<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[15351] CalendarServer/trunk/contrib/performance</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/15351">15351</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2015-12-01 13:38:14 -0800 (Tue, 01 Dec 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fix old sim configs. Add a tool to run the sim against a range of server revisions.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcontribperformanceloadtestclientsoldplist">CalendarServer/trunk/contrib/performance/loadtest/clients-old.plist</a></li>
<li><a href="#CalendarServertrunkcontribperformanceloadtestconfigoldplist">CalendarServer/trunk/contrib/performance/loadtest/config-old.plist</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>CalendarServer/trunk/contrib/performance/simanalysis/</li>
<li><a href="#CalendarServertrunkcontribperformancesimanalysis__init__py">CalendarServer/trunk/contrib/performance/simanalysis/__init__.py</a></li>
<li><a href="#CalendarServertrunkcontribperformancesimanalysissim_regresspy">CalendarServer/trunk/contrib/performance/simanalysis/sim_regress.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcontribperformanceloadtestclientsoldplist"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/contrib/performance/loadtest/clients-old.plist (15350 => 15351)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/contrib/performance/loadtest/clients-old.plist        2015-12-01 16:53:48 UTC (rev 15350)
+++ CalendarServer/trunk/contrib/performance/loadtest/clients-old.plist        2015-12-01 21:38:14 UTC (rev 15351)
</span><span class="lines">@@ -55,8 +55,10 @@
</span><span class="cx"> 
</span><span class="cx">                                         &lt;key&gt;supportAmpPush&lt;/key&gt;
</span><span class="cx">                                         &lt;true/&gt;
</span><del>-                                        &lt;key&gt;ampPushHost&lt;/key&gt;
-                                        &lt;string&gt;localhost&lt;/string&gt;
</del><ins>+                                        &lt;key&gt;ampPushHosts&lt;/key&gt;
+                                        &lt;array&gt;
+                                                &lt;string&gt;localhost&lt;/string&gt;
+                                    &lt;/array&gt;
</ins><span class="cx">                                         &lt;key&gt;ampPushPort&lt;/key&gt;
</span><span class="cx">                                         &lt;integer&gt;62311&lt;/integer&gt;
</span><span class="cx">                                 &lt;/dict&gt;
</span></span></pre></div>
<a id="CalendarServertrunkcontribperformanceloadtestconfigoldplist"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/contrib/performance/loadtest/config-old.plist (15350 => 15351)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/contrib/performance/loadtest/config-old.plist        2015-12-01 16:53:48 UTC (rev 15350)
+++ CalendarServer/trunk/contrib/performance/loadtest/config-old.plist        2015-12-01 21:38:14 UTC (rev 15351)
</span><span class="lines">@@ -20,9 +20,47 @@
</span><span class="cx"> &lt;plist version=&quot;1.0&quot;&gt;
</span><span class="cx">         &lt;dict&gt;
</span><span class="cx">                 &lt;!-- Identify the server to be load tested. --&gt;
</span><del>-                &lt;key&gt;server&lt;/key&gt;
-                &lt;string&gt;https://localhost:8443&lt;/string&gt;
</del><ins>+                &lt;key&gt;servers&lt;/key&gt;
+                &lt;dict&gt;
+                        &lt;key&gt;PodA&lt;/key&gt;
+                        &lt;dict&gt;
+                                &lt;key&gt;enabled&lt;/key&gt;
+                                &lt;true/&gt;
</ins><span class="cx"> 
</span><ins>+                                &lt;!-- Identify the server to be load tested. --&gt;
+                                &lt;key&gt;uri&lt;/key&gt;
+                                &lt;string&gt;https://localhost:8443&lt;/string&gt;
+
+                                &lt;!--  Define whether server supports stats socket. --&gt;
+                                &lt;key&gt;stats&lt;/key&gt;
+                                &lt;dict&gt;
+                                        &lt;key&gt;enabled&lt;/key&gt;
+                                        &lt;true/&gt;
+                                        &lt;key&gt;Port&lt;/key&gt;
+                                        &lt;integer&gt;8100&lt;/integer&gt;
+                                &lt;/dict&gt;
+                        &lt;/dict&gt;
+                        &lt;key&gt;PodB&lt;/key&gt;
+                        &lt;dict&gt;
+                                &lt;key&gt;enabled&lt;/key&gt;
+                                &lt;false/&gt;
+
+                                &lt;!-- Identify the server to be load tested. --&gt;
+                                &lt;key&gt;uri&lt;/key&gt;
+                                &lt;string&gt;https://localhost:8543&lt;/string&gt;
+
+                                &lt;!--  Define whether server supports stats socket. --&gt;
+                                &lt;key&gt;stats&lt;/key&gt;
+                                &lt;dict&gt;
+                                        &lt;key&gt;enabled&lt;/key&gt;
+                                        &lt;true/&gt;
+                                        &lt;key&gt;Port&lt;/key&gt;
+                                        &lt;integer&gt;8101&lt;/integer&gt;
+                                &lt;/dict&gt;
+                        &lt;/dict&gt;
+                &lt;/dict&gt;
+
+
</ins><span class="cx">                 &lt;!-- The template URI for doing initial principal lookup on. --&gt;
</span><span class="cx">                 &lt;key&gt;principalPathTemplate&lt;/key&gt;
</span><span class="cx">                 &lt;string&gt;/principals/users/%s/&lt;/string&gt;
</span><span class="lines">@@ -37,15 +75,6 @@
</span><span class="cx">                         &lt;integer&gt;8080&lt;/integer&gt;
</span><span class="cx">                 &lt;/dict&gt;
</span><span class="cx"> 
</span><del>-                &lt;!--  Define whether server supports stats socket. --&gt;
-                &lt;key&gt;serverStats&lt;/key&gt;
-                &lt;dict&gt;
-                        &lt;key&gt;enabled&lt;/key&gt;
-                        &lt;true/&gt;
-                        &lt;key&gt;Port&lt;/key&gt;
-                        &lt;integer&gt;8100&lt;/integer&gt;
-                &lt;/dict&gt;
-
</del><span class="cx">                 &lt;!--  Define whether client data should be re-used. It will always be saved to the specified path.--&gt;
</span><span class="cx">                 &lt;key&gt;clientDataSerialization&lt;/key&gt;
</span><span class="cx">                 &lt;dict&gt;
</span><span class="lines">@@ -75,6 +104,11 @@
</span><span class="cx">                                         a relative path. This isn't a great solution. --&gt;
</span><span class="cx">                                 &lt;key&gt;path&lt;/key&gt;
</span><span class="cx">                                 &lt;string&gt;contrib/performance/loadtest/accounts.csv&lt;/string&gt;
</span><ins>+
+                                &lt;!-- When there are accounts for multiple pods, interleave the accounts for each
+                                        pod so that the arrival mechanism will cycle clients between each pod. --&gt;
+                                &lt;key&gt;interleavePods&lt;/key&gt;
+                                &lt;true/&gt;
</ins><span class="cx">                         &lt;/dict&gt;
</span><span class="cx">                 &lt;/dict&gt;
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServertrunkcontribperformancesimanalysis__init__py"></a>
<div class="addfile"><h4>Added: CalendarServer/trunk/contrib/performance/simanalysis/__init__.py (0 => 15351)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/contrib/performance/simanalysis/__init__.py                                (rev 0)
+++ CalendarServer/trunk/contrib/performance/simanalysis/__init__.py        2015-12-01 21:38:14 UTC (rev 15351)
</span><span class="lines">@@ -0,0 +1,19 @@
</span><ins>+##
+# Copyright (c) 2015 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+&quot;&quot;&quot;
+Tools to manage sim runs and associated data.
+&quot;&quot;&quot;
</ins></span></pre></div>
<a id="CalendarServertrunkcontribperformancesimanalysissim_regresspy"></a>
<div class="addfile"><h4>Added: CalendarServer/trunk/contrib/performance/simanalysis/sim_regress.py (0 => 15351)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/contrib/performance/simanalysis/sim_regress.py                                (rev 0)
+++ CalendarServer/trunk/contrib/performance/simanalysis/sim_regress.py        2015-12-01 21:38:14 UTC (rev 15351)
</span><span class="lines">@@ -0,0 +1,179 @@
</span><ins>+##
+# Copyright (c) 2015 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+import argparse
+import os
+import plistlib
+import shutil
+import subprocess
+import sys
+import time
+
+
+class SimRegress(object):
+    &quot;&quot;&quot;
+    Class that manages running the sim against a range of SVN revisions.
+    &quot;&quot;&quot;
+
+    TMP_DIR = &quot;/tmp/CalendarServer-SimRegress&quot;
+
+    def __init__(self, startRev, stopRev, stepRev):
+        self.startRev = startRev
+        self.currentRev = startRev
+        self.stopRev = stopRev
+        self.stepRev = stepRev
+        self.cwd = os.getcwd()
+        self.results = []
+
+
+    def run(self):
+
+        # Get the actual SVN revisions we want to use
+        svn_revs = self.getRevisions()
+        print(&quot;SVN Revisions to analyze: {}&quot;.format(svn_revs))
+
+        # Create the tmp dir and do initial checkout
+        for revision in svn_revs:
+            self.currentRev = revision
+            logfile = os.path.join(self.cwd, &quot;Log-rev-{}.txt&quot;.format(self.currentRev))
+            with open(logfile, &quot;w&quot;) as f:
+                self.log = f
+                self.checkRevision()
+                self.buildServer()
+                self.runServer()
+                qos = self.runSim()
+                self.stopServer()
+            with open(logfile) as f:
+                qos = filter(lambda line: line.strip().startswith(&quot;Qos : &quot;), f.read().splitlines())
+                qos = float(qos[0].strip()[len(&quot;Qos : &quot;):]) if qos else None
+                print(&quot;Revision: {}  Qos: {}&quot;.format(self.currentRev, qos))
+                self.results.append((self.currentRev, qos))
+
+        print(&quot;All revisions complete&quot;)
+
+        print(&quot;\n*** Results:&quot;)
+        print(&quot;Rev\tQos&quot;)
+        for result in self.results:
+            print(&quot;{}\t{:.4f}&quot;.format(*result))
+
+
+    def getRevisions(self):
+
+        if self.stopRev is None:
+            print(&quot;Determining HEAD revision&quot;)
+            out = subprocess.check_output(&quot;svn info -r HEAD&quot;.split())
+            rev = filter(lambda line: line.startswith(&quot;Revision: &quot;), out.splitlines())
+            if rev:
+                self.stopRev = int(rev[0][len(&quot;Revision: &quot;):])
+                print(&quot;Using HEAD revision: {}&quot;.format(self.stopRev))
+
+        return range(self.startRev, self.stopRev, self.stepRev) + [self.stopRev]
+
+
+    def checkRevision(self):
+        # Create the tmp dir and do initial checkout
+        if not os.path.exists(SimRegress.TMP_DIR):
+            os.makedirs(SimRegress.TMP_DIR)
+            os.chdir(SimRegress.TMP_DIR)
+            self.checkoutInitialRevision()
+        else:
+            os.chdir(SimRegress.TMP_DIR)
+            actualRevision = self.currentRevision()
+            if actualRevision &gt; self.currentRev:
+                # If actualRevision code is newer than what we want, always wipe it
+                # and start from scratch
+                shutil.rmtree(SimRegress.TMP_DIR)
+                self.checkRevision()
+            elif actualRevision &lt; self.currentRev:
+                # Upgrade from older revision to what we want
+                self.updateRevision()
+
+
+    def checkoutInitialRevision(self):
+        print(&quot;Checking out revision: {}&quot;.format(self.startRev))
+        subprocess.call(
+            &quot;svn checkout http://svn.calendarserver.org/repository/calendarserver/CalendarServer/trunk -r {start} .&quot;.format(start=self.startRev).split(),
+            stdout=self.log, stderr=self.log,
+        )
+
+
+    def currentRevision(self):
+        print(&quot;Checking current revision&quot;)
+        out = subprocess.check_output(&quot;svn info&quot;.split())
+        rev = filter(lambda line: line.startswith(&quot;Revision: &quot;), out.splitlines())
+        return int(rev[0][len(&quot;Revision: &quot;):]) if rev else None
+
+
+    def updateRevision(self):
+        print(&quot;Updating to revision: {}&quot;.format(self.currentRev))
+        subprocess.call(&quot;svn up -r {rev} .&quot;.format(rev=self.currentRev).split())
+
+
+    def patchConfig(self, configPath):
+        &quot;&quot;&quot;
+        Patch the plist config file to use settings that make sense for the sim.
+
+        @param configPath: path to plist file to patch
+        @type configPath: L{str}
+        &quot;&quot;&quot;
+
+        f = plistlib.readPlist(configPath)
+        f['Authentication']['Kerberos']['Enabled'] = False
+        plistlib.writePlist(f, configPath)
+
+
+    def buildServer(self):
+        print(&quot;Building revision: {}&quot;.format(self.currentRev))
+        subprocess.call(&quot;./bin/develop&quot;.split(), stdout=self.log, stderr=self.log)
+
+
+    def runServer(self):
+        print(&quot;Running revision: {}&quot;.format(self.currentRev))
+        shutil.copyfile(&quot;conf/caldavd-test.plist&quot;, &quot;conf/caldavd-dev.plist&quot;)
+        self.patchConfig(&quot;conf/caldavd-dev.plist&quot;)
+        if os.path.exists(&quot;data&quot;):
+            shutil.rmtree(&quot;data&quot;)
+        subprocess.call(&quot;./bin/run -nd&quot;.split(), stdout=self.log, stderr=self.log)
+        time.sleep(10)
+
+
+    def stopServer(self):
+        print(&quot;Stopping revision: {}&quot;.format(self.currentRev))
+        subprocess.call(&quot;./bin/run -k&quot;.split(), stdout=self.log, stderr=self.log)
+
+
+    def runSim(self):
+        print(&quot;Running sim&quot;)
+        if os.path.exists(&quot;/tmp/sim&quot;):
+            shutil.rmtree(&quot;/tmp/sim&quot;)
+        subprocess.call(&quot;{exe} {sim} --config {config} --clients {clients} --runtime 300&quot;.format(
+            exe=sys.executable,
+            sim=os.path.join(self.cwd, &quot;contrib/performance/loadtest/sim.py&quot;),
+            config=os.path.join(self.cwd, &quot;contrib/performance/loadtest/config-old.plist&quot;),
+            clients=os.path.join(self.cwd, &quot;contrib/performance/loadtest/clients-old.plist&quot;),
+        ).split(), stdout=self.log, stderr=self.log)
+
+
+
+if __name__ == '__main__':
+    parser = argparse.ArgumentParser(description=&quot;Run the sim tool against a specific range of server revisions.&quot;)
+    parser.add_argument(&quot;--start&quot;, type=int, required=True, help=&quot;Revision number to start at&quot;)
+    parser.add_argument(&quot;--stop&quot;, type=int, help=&quot;Revision number to stop at&quot;)
+    parser.add_argument(&quot;--step&quot;, default=100, type=int, help=&quot;Revision number steps&quot;)
+
+    args = parser.parse_args()
+
+    SimRegress(args.start, args.stop, args.step).run()
</ins></span></pre>
</div>
</div>

</body>
</html>