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

source_changes at macosforge.org source_changes at macosforge.org
Tue Sep 14 09:30:13 PDT 2010


Revision: 6287
          http://trac.macosforge.org/projects/calendarserver/changeset/6287
Author:   exarkun at twistedmatrix.com
Date:     2010-09-14 09:30:11 -0700 (Tue, 14 Sep 2010)
Log Message:
-----------
Add a benchmark for adding attendees to an event


Also clean up the whitespace in benchlib.py
And make the invalid log directory argument exception actually contain the bad value
Plus remove unused imports in date change benchmark
Additionally, refactor _event_change, adding a feature, in support of the new benchmark

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

Added Paths:
-----------
    CalendarServer/trunk/contrib/performance/event_add_attendee.py

Modified: CalendarServer/trunk/contrib/performance/_event_change.py
===================================================================
--- CalendarServer/trunk/contrib/performance/_event_change.py	2010-09-14 16:02:31 UTC (rev 6286)
+++ CalendarServer/trunk/contrib/performance/_event_change.py	2010-09-14 16:30:11 UTC (rev 6287)
@@ -4,6 +4,7 @@
 """
 
 from itertools import count
+
 from urllib2 import HTTPDigestAuthHandler
 
 from twisted.internet import reactor
@@ -18,7 +19,8 @@
 from event import makeEvent
 
 @inlineCallbacks
-def measure(host, port, dtrace, attendeeCount, samples, fieldName, replacer):
+def measure(host, port, dtrace, attendeeCount, samples, fieldName,
+            replacer, eventPerSample=False):
     user = password = "user01"
     root = "/"
     principal = "/"
@@ -35,18 +37,60 @@
     # Set up the calendar first
     yield initialize(agent, host, port, user, password, root, principal, calendar)
 
-    event = makeEvent(0, attendeeCount)
+    if eventPerSample:
+        # Create an event for each sample that will be taken, so that no event
+        # is used for two different samples.
+        f = _selfish_sample
+    else:
+        # Just create one event and re-use it for all samples.
+        f = _generous_sample
+
+    data = yield f(
+        dtrace, replacer, agent, host, port, user, calendar, fieldName,
+        attendeeCount, samples)
+    returnValue(data)
+
+
+
+ at inlineCallbacks
+def _selfish_sample(dtrace, replacer, agent, host, port, user, calendar, fieldName, attendeeCount, samples):
+    url = 'http://%s:%s/calendars/__uids__/%s/%s/%s-change-%%d.ics' % (
+        host, port, user, calendar, fieldName)
+
+    headers = Headers({"content-type": ["text/calendar"]})
+
+    events = [
+        (makeEvent(i, attendeeCount), url % (i,))
+        for i in range(samples)]
+
+    for (event, url) in events:
+        yield agent.request('PUT', url, headers, StringProducer(event))
+
+
+    # Sample changing the event according to the replacer.
+    samples = yield sample(
+        dtrace, samples,
+        agent, (('PUT', url, headers, StringProducer(replacer(event, i)))
+                for i, (event, url)
+                in enumerate(events)).next)
+    returnValue(samples)
+
+
+
+ at inlineCallbacks
+def _generous_sample(dtrace, replacer, agent, host, port, user, calendar, fieldName, attendeeCount, samples):
     url = 'http://%s:%s/calendars/__uids__/%s/%s/%s-change.ics' % (
         host, port, user, calendar, fieldName)
+
     headers = Headers({"content-type": ["text/calendar"]})
 
-    # Create an event to mess around with.
+    event = makeEvent(0, attendeeCount)
+
     yield agent.request('PUT', url, headers, StringProducer(event))
 
-    # Change the summary to a bunch of different things
+    # Sample changing the event according to the replacer.
     samples = yield sample(
         dtrace, samples,
-        agent, (('PUT', url, headers, StringProducer(replacer(event, i)))
-                for i
-                in count()).next)
+        agent, (('PUT', url, headers, StringProducer(replacer(event)))
+                for i in count(1)).next)
     returnValue(samples)

Modified: CalendarServer/trunk/contrib/performance/benchlib.py
===================================================================
--- CalendarServer/trunk/contrib/performance/benchlib.py	2010-09-14 16:02:31 UTC (rev 6286)
+++ CalendarServer/trunk/contrib/performance/benchlib.py	2010-09-14 16:30:11 UTC (rev 6287)
@@ -7,6 +7,7 @@
 from stats import Duration
 from httpclient import StringProducer, readBody
 
+
 class CalDAVAccount(object):
     def __init__(self, agent, netloc, user, password, root, principal):
         self.agent = agent
@@ -27,9 +28,9 @@
 
     def writeData(self, url, data, contentType):
         return self.agent.request(
-            'PUT', 
-            'http://%s%s' % (self.netloc, url), 
-            Headers({'content-type': [contentType]}), 
+            'PUT',
+            'http://%s%s' % (self.netloc, url),
+            Headers({'content-type': [contentType]}),
             StringProducer(data))
 
 

Modified: CalendarServer/trunk/contrib/performance/benchmark.py
===================================================================
--- CalendarServer/trunk/contrib/performance/benchmark.py	2010-09-14 16:02:31 UTC (rev 6286)
+++ CalendarServer/trunk/contrib/performance/benchmark.py	2010-09-14 16:30:11 UTC (rev 6287)
@@ -279,7 +279,7 @@
 def logsCoerce(directory):
     path = FilePath(directory)
     if not path.isdir():
-        raise ValueError("%r is not a directory")
+        raise ValueError("%r is not a directory" % (path.path,))
     return path
 
 

Added: CalendarServer/trunk/contrib/performance/event_add_attendee.py
===================================================================
--- CalendarServer/trunk/contrib/performance/event_add_attendee.py	                        (rev 0)
+++ CalendarServer/trunk/contrib/performance/event_add_attendee.py	2010-09-14 16:30:11 UTC (rev 6287)
@@ -0,0 +1,21 @@
+
+import _event_change
+
+from event import makeAttendees
+
+
+def measure(host, port, dtrace, attendeeCount, samples):
+    attendees = makeAttendees(attendeeCount)
+
+    def addAttendees(event, i):
+        """
+        Add C{i} new attendees to the given event.
+        """
+        # Find the last CREATED line
+        created = event.rfind('CREATED')
+        # Insert the attendees before it.
+        return event[:created] + attendees + event[created:]
+
+    return _event_change.measure(
+        host, port, dtrace, 0, samples, "date", addAttendees,
+        eventPerSample=True)

Modified: CalendarServer/trunk/contrib/performance/event_change_date.py
===================================================================
--- CalendarServer/trunk/contrib/performance/event_change_date.py	2010-09-14 16:02:31 UTC (rev 6286)
+++ CalendarServer/trunk/contrib/performance/event_change_date.py	2010-09-14 16:30:11 UTC (rev 6287)
@@ -1,6 +1,11 @@
 
-import re, datetime
+"""
+Benchmark a change in the date boundaries of an event.
+"""
 
+
+import datetime
+
 import _event_change
 
 TIME_FORMAT = '%Y%m%dT%H%M%S'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100914/230fed01/attachment-0001.html>


More information about the calendarserver-changes mailing list