<!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>[15369] CalendarServer/trunk/contrib/performance/loadtest</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/15369">15369</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2015-12-04 12:03:08 -0800 (Fri, 04 Dec 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Sim attachment downloader avoids unnecessary downloading (i.e. previously downloaded or uploaded)</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcontribperformanceloadtesticalpy">CalendarServer/trunk/contrib/performance/loadtest/ical.py</a></li>
<li><a href="#CalendarServertrunkcontribperformanceloadtestprofilespy">CalendarServer/trunk/contrib/performance/loadtest/profiles.py</a></li>
<li><a href="#CalendarServertrunkcontribperformanceloadtesttest_icalpy">CalendarServer/trunk/contrib/performance/loadtest/test_ical.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcontribperformanceloadtesticalpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/contrib/performance/loadtest/ical.py (15368 => 15369)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -302,15 +302,17 @@
</span><span class="cx">
</span><span class="cx"> coll = NotificationCollection(None, None)
</span><span class="cx"> for attr in ("url", "changeToken"):
</span><del>- setattr(coll, attr, u2str(data[attr]))
</del><ins>+ if attr in data:
+ setattr(coll, attr, u2str(data[attr]))
</ins><span class="cx">
</span><del>- 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 = ""
</del><ins>+ 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 = ""
</ins><span class="cx"> return coll
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -574,7 +576,10 @@
</span><span class="cx"> "eventChanged": Periodical(),
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ # Keep track of previously downloaded attachments
+ self._attachments = {}
</ins><span class="cx">
</span><ins>+
</ins><span class="cx"> def _addDefaultHeaders(self, headers):
</span><span class="cx"> """
</span><span class="cx"> Add the clients default set of headers to ones being used in a request.
</span><span class="lines">@@ -1590,6 +1595,7 @@
</span><span class="cx"> "calendars": [calendar.serialize() for calendar in sorted(self._calendars.values(), key=lambda x:x.name)],
</span><span class="cx"> "events": [event.serialize() for event in sorted(self._events.values(), key=lambda x:x.url)],
</span><span class="cx"> "notificationCollection" : self._notificationCollection.serialize() if self._notificationCollection else {},
</span><ins>+ "attachments": self._attachments
</ins><span class="cx"> }
</span><span class="cx"> # Write JSON data
</span><span class="cx"> with open(os.path.join(path, "index.json"), "w") as f:
</span><span class="lines">@@ -1603,6 +1609,7 @@
</span><span class="cx">
</span><span class="cx"> self._calendars = {}
</span><span class="cx"> self._events = {}
</span><ins>+ self._attachments = {}
</ins><span class="cx">
</span><span class="cx"> path = self.serializeLocation()
</span><span class="cx"> if path is None:
</span><span class="lines">@@ -1626,8 +1633,10 @@
</span><span class="cx"> self._calendars[calendar.url] = calendar
</span><span class="cx"> if data.get("notificationCollection"):
</span><span class="cx"> self._notificationCollection = NotificationCollection.deserialize(data, {})
</span><ins>+ self._attachments = data.get("attachments", {})
</ins><span class="cx">
</span><span class="cx">
</span><ins>+
</ins><span class="cx"> @inlineCallbacks
</span><span class="cx"> def reset(self):
</span><span class="cx"> path = self.serializeLocation()
</span><span class="lines">@@ -2003,11 +2012,27 @@
</span><span class="cx"> method_label="POST{attach}"
</span><span class="cx"> )
</span><span class="cx"> body = yield readBody(response)
</span><ins>+
+ # 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
+
</ins><span class="cx"> yield self.updateEvent(href)
</span><span class="cx"> returnValue(body)
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><ins>+ 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
</ins><span class="cx"> def postXML(self, href, content, label):
</span><span class="cx"> headers = Headers({
</span><span class="cx"> 'content-type': ['text/xml']
</span></span></pre></div>
<a id="CalendarServertrunkcontribperformanceloadtestprofilespy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/contrib/performance/loadtest/profiles.py (15368 => 15369)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -558,15 +558,13 @@
</span><span class="cx"> if attachments:
</span><span class="cx"> for attachment in attachments:
</span><span class="cx"> attachmentHref = attachment.value()
</span><ins>+ managedId = attachment.parameterValue('MANAGED-ID')
</ins><span class="cx"> self._reactor.callLater(
</span><del>- 0, self._downloadAttachment, attachmentHref
</del><ins>+ 0, self._client.getAttachment, attachmentHref, managedId
</ins><span class="cx"> )
</span><span class="cx">
</span><del>- def _downloadAttachment(self, href):
- return self._client._get(href, 200)
</del><span class="cx">
</span><span class="cx">
</span><del>-
</del><span class="cx"> class Eventer(ProfileBase):
</span><span class="cx"> """
</span><span class="cx"> A Calendar user who creates new events.
</span></span></pre></div>
<a id="CalendarServertrunkcontribperformanceloadtesttest_icalpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/contrib/performance/loadtest/test_ical.py (15368 => 15369)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1626,7 +1626,8 @@
</span><span class="cx"> "etag": "123.123",
</span><span class="cx"> "uid": "00a79cad-857b-418e-a54a-340b5686d747"
</span><span class="cx"> }
</span><del>- ]
</del><ins>+ ],
+ "attachments": {}
</ins><span class="cx"> }""")))
</span><span class="cx">
</span><span class="cx"> event1Path = os.path.join(clientPath, "calendar", "1.ics")
</span></span></pre>
</div>
</div>
</body>
</html>