[CalendarServer-changes] [15626] CalendarServer/trunk/contrib/performance/loadtest
source_changes at macosforge.org
source_changes at macosforge.org
Fri May 20 12:45:30 PDT 2016
Revision: 15626
http://trac.calendarserver.org//changeset/15626
Author: sagen at apple.com
Date: 2016-05-20 12:45:30 -0700 (Fri, 20 May 2016)
Log Message:
-----------
Client sim enhancement: log request/response whenever the duration exceeds a threshold or an incorrect response code is received.
Modified Paths:
--------------
CalendarServer/trunk/contrib/performance/loadtest/config.plist
CalendarServer/trunk/contrib/performance/loadtest/ical.py
Modified: CalendarServer/trunk/contrib/performance/loadtest/config.plist
===================================================================
--- CalendarServer/trunk/contrib/performance/loadtest/config.plist 2016-05-20 19:01:26 UTC (rev 15625)
+++ CalendarServer/trunk/contrib/performance/loadtest/config.plist 2016-05-20 19:45:30 UTC (rev 15626)
@@ -197,6 +197,20 @@
</dict>
</dict>
+ <!-- ErrorLogger logs the request/response bodies whenever an incorrect
+ response code is received, or if the duration exceeds threshold. -->
+ <dict>
+ <key>type</key>
+ <string>contrib.performance.loadtest.ical.ErrorLogger</string>
+ <key>params</key>
+ <dict>
+ <key>directory</key>
+ <string>/tmp/sim_errors</string>
+ <key>durationThreshold</key>
+ <real>10.0</real>
+ </dict>
+ </dict>
+
<!-- OperationLogger generates an end-of-run summary of the gross operations
performed (logical operations which may span more than one HTTP request,
such as inviting an attendee to an event). -->
Modified: CalendarServer/trunk/contrib/performance/loadtest/ical.py
===================================================================
--- CalendarServer/trunk/contrib/performance/loadtest/ical.py 2016-05-20 19:01:26 UTC (rev 15625)
+++ CalendarServer/trunk/contrib/performance/loadtest/ical.py 2016-05-20 19:45:30 UTC (rev 15626)
@@ -2601,7 +2601,74 @@
return []
+class ErrorLogger(object):
+ """
+ Requests which get an incorrect response code or take too long are logged
+ """
+ def __init__(self, directory, durationThreshold):
+ self.directory = directory
+ self.durationThreshold = durationThreshold
+ if os.path.isdir(directory):
+ shutil.rmtree(directory)
+ os.mkdir(directory)
+ self.errorCounter = 0
+ self.durationCounter = 0
+
+
+ def _getBodies(self, event):
+ body = event['body']
+ if isinstance(body, StringProducer):
+ body = body._body
+ if body:
+ body = body[:5000]
+ responseBody = event['responseBody']
+ return body, responseBody
+
+
+ def observe(self, event):
+ if event.get("type") == "response":
+ if not event['success']:
+ body, responseBody = self._getBodies(event)
+ self.errorCounter += 1
+ filename = "error-{:08d}.txt".format(self.errorCounter)
+ fullname = os.path.join(self.directory, filename)
+ with open(fullname, "w") as f:
+ f.write("RESPONSE CODE: {}\n".format(event['code']))
+ f.write("URL: {}\n".format(event['url']))
+ f.write("METHOD: {}\n".format(event['method']))
+ f.write("USER: {}\n".format(event['user']))
+ f.write("REQUEST BODY:\n{}\n".format(body))
+ f.write("RESPONSE BODY:\n{}\n".format(responseBody))
+
+ print("Incorrect Response Code logged to {}".format(fullname))
+
+ elif event["duration"] > self.durationThreshold:
+ body, responseBody = self._getBodies(event)
+ self.durationCounter += 1
+
+ filename = "duration-{:08d}.txt".format(self.durationCounter)
+ fullname = os.path.join(self.directory, filename)
+ with open(fullname, "w") as f:
+ f.write("LONG RESPONSE: {:.1f} sec\n".format(event['duration']))
+ f.write("RESPONSE CODE: {}\n".format(event['code']))
+ f.write("URL: {}\n".format(event['url']))
+ f.write("METHOD: {}\n".format(event['method']))
+ f.write("USER: {}\n".format(event['user']))
+ f.write("REQUEST BODY:\n{}\n".format(body))
+ f.write("RESPONSE BODY:\n{}\n".format(responseBody))
+
+ print("Long Duration logged to {}".format(fullname))
+
+
+ def report(self, output):
+ pass
+
+
+ def failures(self):
+ return []
+
+
def main():
from urllib2 import HTTPDigestAuthHandler
from twisted.internet import reactor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20160520/e955a90d/attachment.html>
More information about the calendarserver-changes
mailing list