[CalendarServer-changes] [6271] CalendarServer/trunk/contrib/performance
source_changes at macosforge.org
source_changes at macosforge.org
Fri Sep 10 11:59:23 PDT 2010
Revision: 6271
http://trac.macosforge.org/projects/calendarserver/changeset/6271
Author: exarkun at twistedmatrix.com
Date: 2010-09-10 11:59:20 -0700 (Fri, 10 Sep 2010)
Log Message:
-----------
Add an event date change benchmark
Modified Paths:
--------------
CalendarServer/trunk/contrib/performance/event_change_summary.py
Added Paths:
-----------
CalendarServer/trunk/contrib/performance/_event_change.py
CalendarServer/trunk/contrib/performance/event_change_date.py
CalendarServer/trunk/contrib/performance/test_event_change_date.py
Added: CalendarServer/trunk/contrib/performance/_event_change.py
===================================================================
--- CalendarServer/trunk/contrib/performance/_event_change.py (rev 0)
+++ CalendarServer/trunk/contrib/performance/_event_change.py 2010-09-10 18:59:20 UTC (rev 6271)
@@ -0,0 +1,52 @@
+
+"""
+Benchmark a server's handling of event summary changes.
+"""
+
+from itertools import count
+from urllib2 import HTTPDigestAuthHandler
+
+from twisted.internet import reactor
+from twisted.internet.defer import inlineCallbacks, returnValue
+from twisted.web.client import Agent
+from twisted.web.http_headers import Headers
+
+from httpauth import AuthHandlerAgent
+from httpclient import StringProducer
+
+from benchlib import initialize, sample
+from event import makeEvent
+
+ at inlineCallbacks
+def measure(host, port, dtrace, attendeeCount, samples, fieldName, replacer):
+ user = password = "user01"
+ root = "/"
+ principal = "/"
+ calendar = "event-change-%s-benchmark" % (fieldName,)
+
+ authinfo = HTTPDigestAuthHandler()
+ authinfo.add_password(
+ realm="Test Realm",
+ uri="http://%s:%d/" % (host, port),
+ user=user,
+ passwd=password)
+ agent = AuthHandlerAgent(Agent(reactor), authinfo)
+
+ # Set up the calendar first
+ yield initialize(agent, host, port, user, password, root, principal, calendar)
+
+ event = makeEvent(0, attendeeCount)
+ 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.
+ yield agent.request('PUT', url, headers, StringProducer(event))
+
+ # Change the summary to a bunch of different things
+ samples = yield sample(
+ dtrace, samples,
+ agent, (('PUT', url, headers, StringProducer(replacer(event, i)))
+ for i
+ in count()).next)
+ returnValue(samples)
Added: CalendarServer/trunk/contrib/performance/event_change_date.py
===================================================================
--- CalendarServer/trunk/contrib/performance/event_change_date.py (rev 0)
+++ CalendarServer/trunk/contrib/performance/event_change_date.py 2010-09-10 18:59:20 UTC (rev 6271)
@@ -0,0 +1,30 @@
+
+import re, datetime
+
+import _event_change
+
+TIME_FORMAT = '%Y%m%dT%H%M%S'
+
+def _increment(event, marker, amount):
+ # Find the last occurrence of the marker
+ dtstart = event.rfind(marker)
+ # Find the end of that line
+ eol = event.find('\n', dtstart)
+ # Find the : preceding the date on that line
+ colon = event.find(':', dtstart)
+ # Replace the text between the colon and the eol with the new timestamp
+ old = datetime.datetime.strptime(event[colon + 1:eol], TIME_FORMAT)
+ new = old + amount
+ return event[:colon + 1] + new.strftime(TIME_FORMAT) + event[eol:]
+
+
+def replaceTimestamp(event, i):
+ offset = datetime.timedelta(hours=i)
+ return _increment(
+ _increment(event, 'DTSTART', offset),
+ 'DTEND', offset)
+
+
+def measure(host, port, dtrace, attendeeCount, samples):
+ return _event_change.measure(
+ host, port, dtrace, attendeeCount, samples, "date", replaceTimestamp)
Modified: CalendarServer/trunk/contrib/performance/event_change_summary.py
===================================================================
--- CalendarServer/trunk/contrib/performance/event_change_summary.py 2010-09-10 18:12:02 UTC (rev 6270)
+++ CalendarServer/trunk/contrib/performance/event_change_summary.py 2010-09-10 18:59:20 UTC (rev 6271)
@@ -1,53 +1,12 @@
-"""
-Benchmark a server's handling of event summary changes.
-"""
+from event import SUMMARY
-from itertools import count
-from urllib2 import HTTPDigestAuthHandler
+import _event_change
-from twisted.internet import reactor
-from twisted.internet.defer import inlineCallbacks, returnValue
-from twisted.web.client import Agent
-from twisted.web.http_headers import Headers
+def replaceSummary(event, i):
+ return event.replace(SUMMARY, 'Replacement summary %d' % (i,))
-from httpauth import AuthHandlerAgent
-from httpclient import StringProducer
-from benchlib import initialize, sample
-from event import SUMMARY, makeEvent
-
- at inlineCallbacks
def measure(host, port, dtrace, attendeeCount, samples):
- user = password = "user01"
- root = "/"
- principal = "/"
- calendar = "event-change-summary-benchmark"
-
- authinfo = HTTPDigestAuthHandler()
- authinfo.add_password(
- realm="Test Realm",
- uri="http://%s:%d/" % (host, port),
- user=user,
- passwd=password)
- agent = AuthHandlerAgent(Agent(reactor), authinfo)
-
- # Set up the calendar first
- yield initialize(agent, host, port, user, password, root, principal, calendar)
-
- event = makeEvent(0, attendeeCount)
- url = 'http://%s:%s/calendars/__uids__/%s/%s/summary-change.ics' % (
- host, port, user, calendar)
- headers = Headers({"content-type": ["text/calendar"]})
-
- # Create an event to mess around with.
- yield agent.request('PUT', url, headers, StringProducer(event))
-
- # Change the summary to a bunch of different things
- samples = yield sample(
- dtrace, samples,
- agent, (('PUT', url, headers, StringProducer(
- event.replace(SUMMARY, 'Replacement summary %d' % (i,))))
- for i
- in count()).next)
- returnValue(samples)
+ return _event_change.measure(
+ host, port, dtrace, attendeeCount, samples, "summary", replaceSummary)
Added: CalendarServer/trunk/contrib/performance/test_event_change_date.py
===================================================================
--- CalendarServer/trunk/contrib/performance/test_event_change_date.py (rev 0)
+++ CalendarServer/trunk/contrib/performance/test_event_change_date.py 2010-09-10 18:59:20 UTC (rev 6271)
@@ -0,0 +1,68 @@
+
+import datetime
+
+from twisted.trial.unittest import TestCase
+
+from event_change_date import replaceTimestamp
+
+calendarHead = """\
+BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//Apple Inc.//iCal 4.0.3//EN
+BEGIN:VTIMEZONE
+TZID:America/Los_Angeles
+BEGIN:STANDARD
+DTSTART:20071104T020000
+RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
+TZNAME:PST
+TZOFFSETFROM:-0700
+TZOFFSETTO:-0800
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:20070311T020000
+RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
+TZNAME:PDT
+TZOFFSETFROM:-0800
+TZOFFSETTO:-0700
+END:DAYLIGHT
+END:VTIMEZONE
+BEGIN:VEVENT
+UID:f0b54c7b-c8ae-4dca-807f-5909da771964
+"""
+
+calendarDates = """\
+DTSTART;TZID=America/Los_Angeles:20100730T111505
+DTEND;TZID=America/Los_Angeles:20100730T111508
+"""
+
+calendarTail = """\
+ATTENDEE;CN=User 02;CUTYPE=INDIVIDUAL;EMAIL=user02 at example.com;PARTSTAT=NE
+ EDS-ACTION;ROLE=REQ-PARTICIPANT;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:use
+ r02
+CREATED:20100729T193912Z
+DTSTAMP:20100729T195557Z
+ORGANIZER;CN=User 03;EMAIL=user03 at example.com:urn:uuid:user03
+SEQUENCE:1
+SUMMARY:STUFF IS THINGS
+TRANSP:OPAQUE
+END:VEVENT
+END:VCALENDAR
+"""
+
+class TimestampReplaceTests(TestCase):
+ def test_replaceTimestamp(self):
+ """
+ replaceTimestamp adjusts the DTSTART and DTEND timestamp
+ values by one hour times the counter parameter.
+ """
+ oldCalendar = calendarHead + calendarDates + calendarTail
+ start = datetime.datetime(2010, 7, 30, 11, 15, 5) + datetime.timedelta(hours=1)
+ end = datetime.datetime(2010, 7, 30, 11, 15, 8) + datetime.timedelta(hours=1)
+ newCalendar = replaceTimestamp(oldCalendar, 3)
+ self.assertEquals(
+ calendarHead +
+ "DTSTART;TZID=America/Los_Angeles:20100730T141505\n"
+ "DTEND;TZID=America/Los_Angeles:20100730T141508\n" +
+ calendarTail,
+ newCalendar)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100910/f169fa8e/attachment.html>
More information about the calendarserver-changes
mailing list