[CalendarServer-changes] [6304] CalendarServer/trunk/contrib/performance

source_changes at macosforge.org source_changes at macosforge.org
Thu Sep 16 10:22:22 PDT 2010


Revision: 6304
          http://trac.macosforge.org/projects/calendarserver/changeset/6304
Author:   exarkun at twistedmatrix.com
Date:     2010-09-16 10:22:21 -0700 (Thu, 16 Sep 2010)
Log Message:
-----------
Fix the default for the datafile prefix; also add concurrent request support to the sample() function

Modified Paths:
--------------
    CalendarServer/trunk/contrib/performance/benchlib.py
    CalendarServer/trunk/contrib/performance/benchmark.py

Modified: CalendarServer/trunk/contrib/performance/benchlib.py
===================================================================
--- CalendarServer/trunk/contrib/performance/benchlib.py	2010-09-16 01:55:15 UTC (rev 6303)
+++ CalendarServer/trunk/contrib/performance/benchlib.py	2010-09-16 17:22:21 UTC (rev 6304)
@@ -1,7 +1,7 @@
 import pickle
 from time import time
 
-from twisted.internet.defer import inlineCallbacks, returnValue
+from twisted.internet.defer import DeferredSemaphore, inlineCallbacks, returnValue, gatherResults
 from twisted.web.http_headers import Headers
 
 from stats import Duration
@@ -61,19 +61,38 @@
 
 
 @inlineCallbacks
-def sample(dtrace, samples, agent, paramgen):
+def sample(dtrace, samples, agent, paramgen, concurrency=1):
+    sem = DeferredSemaphore(concurrency)
+
     urlopen = Duration('HTTP')
     data = {urlopen: []}
+
+    def once():
+        before = time()
+        d = agent.request(*paramgen())
+        def cbResponse(response):
+            print response.code
+            d = readBody(response)
+            def cbBody(ignored):
+                after = time()
+                d = dtrace.mark()
+                def cbStats(stats):
+                    for k, v in stats.iteritems():
+                        data.setdefault(k, []).append(v)
+                    data[urlopen].append(after - before)
+                d.addCallback(cbStats)
+                return d
+            d.addCallback(cbBody)
+            return d
+        d.addCallback(cbResponse)
+        return d
+
     yield dtrace.start()
+    l = []
     for i in range(samples):
-        before = time()
-        response = yield agent.request(*paramgen())
-        yield readBody(response)
-        after = time()
-        stats = yield dtrace.mark()
-        for k, v in stats.iteritems():
-            data.setdefault(k, []).append(v)
-        data[urlopen].append(after - before)
+        l.append(sem.run(once))
+    yield gatherResults(l)
+
     leftOver = yield dtrace.stop()
     for (k, v) in leftOver.items():
         if v:

Modified: CalendarServer/trunk/contrib/performance/benchmark.py
===================================================================
--- CalendarServer/trunk/contrib/performance/benchmark.py	2010-09-16 01:55:15 UTC (rev 6303)
+++ CalendarServer/trunk/contrib/performance/benchmark.py	2010-09-16 17:22:21 UTC (rev 6304)
@@ -293,7 +293,7 @@
          'Logs directory of the CalendarServer being benchmarked (if and only '
          'if the CalendarServer is on the same host as this benchmark process)',
          logsCoerce),
-        ('label', 'l', 'A descriptive string to attach to the output filename.'),
+        ('label', 'l', 'data', 'A descriptive string to attach to the output filename.'),
         ]
 
     optFlags = [
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100916/b16f0bcb/attachment.html>


More information about the calendarserver-changes mailing list