[CalendarServer-changes] [15369] CalendarServer/trunk/contrib/performance/loadtest

source_changes at macosforge.org source_changes at macosforge.org
Fri Dec 4 12:03:08 PST 2015


Revision: 15369
          http://trac.calendarserver.org//changeset/15369
Author:   sagen at apple.com
Date:     2015-12-04 12:03:08 -0800 (Fri, 04 Dec 2015)
Log Message:
-----------
Sim attachment downloader avoids unnecessary downloading (i.e. previously downloaded or uploaded)

Modified Paths:
--------------
    CalendarServer/trunk/contrib/performance/loadtest/ical.py
    CalendarServer/trunk/contrib/performance/loadtest/profiles.py
    CalendarServer/trunk/contrib/performance/loadtest/test_ical.py

Modified: CalendarServer/trunk/contrib/performance/loadtest/ical.py
===================================================================
--- CalendarServer/trunk/contrib/performance/loadtest/ical.py	2015-12-04 17:15:02 UTC (rev 15368)
+++ CalendarServer/trunk/contrib/performance/loadtest/ical.py	2015-12-04 20:03:08 UTC (rev 15369)
@@ -302,15 +302,17 @@
 
         coll = NotificationCollection(None, None)
         for attr in ("url", "changeToken"):
-            setattr(coll, attr, u2str(data[attr]))
+            if attr in data:
+                setattr(coll, attr, u2str(data[attr]))
 
-        for notification in data["notifications"]:
-            url = urljoin(coll.url, notification)
-            if url in notifications:
-                coll.notifications[notification] = notifications[url]
-            else:
-                # Ughh - a notification is missing - force changeToken to empty to trigger full resync
-                coll.changeToken = ""
+        if "notifications" in data:
+            for notification in data["notifications"]:
+                url = urljoin(coll.url, notification)
+                if url in notifications:
+                    coll.notifications[notification] = notifications[url]
+                else:
+                    # Ughh - a notification is missing - force changeToken to empty to trigger full resync
+                    coll.changeToken = ""
         return coll
 
 
@@ -574,7 +576,10 @@
             "eventChanged": Periodical(),
         }
 
+        # Keep track of previously downloaded attachments
+        self._attachments = {}
 
+
     def _addDefaultHeaders(self, headers):
         """
         Add the clients default set of headers to ones being used in a request.
@@ -1590,6 +1595,7 @@
             "calendars": [calendar.serialize() for calendar in sorted(self._calendars.values(), key=lambda x:x.name)],
             "events": [event.serialize() for event in sorted(self._events.values(), key=lambda x:x.url)],
             "notificationCollection" : self._notificationCollection.serialize() if self._notificationCollection else {},
+            "attachments": self._attachments
         }
         # Write JSON data
         with open(os.path.join(path, "index.json"), "w") as f:
@@ -1603,6 +1609,7 @@
 
         self._calendars = {}
         self._events = {}
+        self._attachments = {}
 
         path = self.serializeLocation()
         if path is None:
@@ -1626,8 +1633,10 @@
             self._calendars[calendar.url] = calendar
         if data.get("notificationCollection"):
             self._notificationCollection = NotificationCollection.deserialize(data, {})
+        self._attachments = data.get("attachments", {})
 
 
+
     @inlineCallbacks
     def reset(self):
         path = self.serializeLocation()
@@ -2003,11 +2012,27 @@
             method_label="POST{attach}"
         )
         body = yield readBody(response)
+
+        # We don't want to download an attachment we uploaded, so look for the
+        # Cal-Managed-Id: and Location: headers and remember those
+        managedId = response.headers.getRawHeaders("Cal-Managed-Id")[0]
+        location = response.headers.getRawHeaders("Location")[0]
+        self._attachments[managedId] = location
+
         yield self.updateEvent(href)
         returnValue(body)
 
 
     @inlineCallbacks
+    def getAttachment(self, href, managedId):
+
+        # If we've already downloaded this managedId, skip it.
+        if managedId not in self._attachments:
+            self._attachments[managedId] = href
+            yield self._newOperation("download", self._get(href, 200))
+
+
+    @inlineCallbacks
     def postXML(self, href, content, label):
         headers = Headers({
             'content-type': ['text/xml']

Modified: CalendarServer/trunk/contrib/performance/loadtest/profiles.py
===================================================================
--- CalendarServer/trunk/contrib/performance/loadtest/profiles.py	2015-12-04 17:15:02 UTC (rev 15368)
+++ CalendarServer/trunk/contrib/performance/loadtest/profiles.py	2015-12-04 20:03:08 UTC (rev 15369)
@@ -558,15 +558,13 @@
         if attachments:
             for attachment in attachments:
                 attachmentHref = attachment.value()
+                managedId = attachment.parameterValue('MANAGED-ID')
                 self._reactor.callLater(
-                    0, self._downloadAttachment, attachmentHref
+                    0, self._client.getAttachment, attachmentHref, managedId
                 )
 
-    def _downloadAttachment(self, href):
-        return self._client._get(href, 200)
 
 
-
 class Eventer(ProfileBase):
     """
     A Calendar user who creates new events.

Modified: CalendarServer/trunk/contrib/performance/loadtest/test_ical.py
===================================================================
--- CalendarServer/trunk/contrib/performance/loadtest/test_ical.py	2015-12-04 17:15:02 UTC (rev 15368)
+++ CalendarServer/trunk/contrib/performance/loadtest/test_ical.py	2015-12-04 20:03:08 UTC (rev 15369)
@@ -1626,7 +1626,8 @@
       "etag": "123.123",
       "uid": "00a79cad-857b-418e-a54a-340b5686d747"
     }
-  ]
+  ],
+  "attachments": {}
 }""")))
 
         event1Path = os.path.join(clientPath, "calendar", "1.ics")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20151204/152358bc/attachment.html>


More information about the calendarserver-changes mailing list