<!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>[15091] CalendarServer/trunk</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/15091">15091</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2015-09-02 13:34:57 -0700 (Wed, 02 Sep 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add a tool to look at the processing rate of TestWork items. Make it easy to use the loadtest tool with other server accounts.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarserverdashboard_servicepy">CalendarServer/trunk/calendarserver/dashboard_service.py</a></li>
<li><a href="#CalendarServertrunkcontribperformancejobqueueloadtestpy">CalendarServer/trunk/contrib/performance/jobqueue/loadtest.py</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcontribperformancejobqueueworkratepy">CalendarServer/trunk/contrib/performance/jobqueue/workrate.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcalendarserverdashboard_servicepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/dashboard_service.py (15090 => 15091)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/dashboard_service.py        2015-09-02 19:54:05 UTC (rev 15090)
+++ CalendarServer/trunk/calendarserver/dashboard_service.py        2015-09-02 20:34:57 UTC (rev 15091)
</span><span class="lines">@@ -24,9 +24,12 @@
</span><span class="cx">
</span><span class="cx"> from twistedcaldav.config import config
</span><span class="cx">
</span><ins>+from txdav.common.datastore.work.load_work import TestWork
</ins><span class="cx"> from txdav.dps.client import DirectoryService as DirectoryProxyClientService
</span><span class="cx"> from txdav.who.cache import CachingDirectoryService
</span><span class="cx">
</span><ins>+from twext.enterprise.jobs.queue import WorkerConnectionPool
+
</ins><span class="cx"> import json
</span><span class="cx">
</span><span class="cx"> """
</span><span class="lines">@@ -161,6 +164,28 @@
</span><span class="cx"> return succeed({"workers": loads, "level": level})
</span><span class="cx">
</span><span class="cx">
</span><ins>+ @inlineCallbacks
+ def data_test_work(self):
+ """
+ Return the number of TEST_WORK items in the job queue.
+
+ @return: a string containing the JSON result.
+ @rtype: L{str}
+ """
+
+ results = {}
+ if self.factory.store:
+ txn = self.factory.store.newTransaction()
+ results["queued"] = yield TestWork.count(txn)
+ results["completed"] = WorkerConnectionPool.completed.get(TestWork.workType(), 0)
+ yield txn.commit()
+ else:
+ results["queued"] = 0
+ results["completed"] = 0
+
+ returnValue(results)
+
+
</ins><span class="cx"> def data_directory(self):
</span><span class="cx"> """
</span><span class="cx"> Return a summary of directory service calls.
</span></span></pre></div>
<a id="CalendarServertrunkcontribperformancejobqueueloadtestpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/contrib/performance/jobqueue/loadtest.py (15090 => 15091)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/contrib/performance/jobqueue/loadtest.py        2015-09-02 19:54:05 UTC (rev 15090)
+++ CalendarServer/trunk/contrib/performance/jobqueue/loadtest.py        2015-09-02 20:34:57 UTC (rev 15091)
</span><span class="lines">@@ -23,6 +23,7 @@
</span><span class="cx"> import random
</span><span class="cx"> import sys
</span><span class="cx"> import time
</span><ins>+from urlparse import urlparse
</ins><span class="cx">
</span><span class="cx"> PRIORITY = {
</span><span class="cx"> "low": 0,
</span><span class="lines">@@ -35,14 +36,23 @@
</span><span class="cx"> # Random time delay
</span><span class="cx"> time.sleep(random.randint(0, config["interval"]) / 1000.0)
</span><span class="cx">
</span><ins>+ url = urlparse(config["server"])
+ use_ssl = url[0] == "https"
+ if "@" in url[1]:
+ auth, net_loc = url[1].split("@")
+ else:
+ auth = "admin:admin"
+ net_loc = url[1]
+ host, port = net_loc.split(":")
+ port = int(port)
+ user, pswd = auth.split(":")
+
</ins><span class="cx"> headers = {}
</span><span class="cx"> headers["User-Agent"] = "httploop/1"
</span><span class="cx"> headers["Depth"] = "1"
</span><del>- headers["Authorization"] = "Basic " + "admin:admin".encode("base64")[:-1]
</del><ins>+ headers["Authorization"] = "Basic " + "{}:{}".format(user, pswd).encode("base64")[:-1]
</ins><span class="cx"> headers["Content-Type"] = "application/json"
</span><span class="cx">
</span><del>- host, port = config["server"].split(":")
- port = int(port)
</del><span class="cx"> interval = config["interval"] / 1000.0
</span><span class="cx"> total = config["limit"] / config["numProcesses"]
</span><span class="cx">
</span><span class="lines">@@ -59,7 +69,7 @@
</span><span class="cx">
</span><span class="cx"> base_time = time.time()
</span><span class="cx"> while not complete.value:
</span><del>- http = SmartHTTPConnection(host, port, True, False)
</del><ins>+ http = SmartHTTPConnection(host, port, use_ssl, False)
</ins><span class="cx">
</span><span class="cx"> try:
</span><span class="cx"> count += 1
</span><span class="lines">@@ -101,7 +111,7 @@
</span><span class="cx"> -i MSEC Millisecond delay between each request [1000]
</span><span class="cx"> -r RATE Requests/second rate [10]
</span><span class="cx"> -j JOBS Number of jobs per HTTP request [1]
</span><del>- -s HOST:PORT Host/port to connect to [localhost:8443]
</del><ins>+ -s URL URL to connect to [https://localhost:8443]
</ins><span class="cx"> -b SEC Number of seconds for notBefore [0]
</span><span class="cx"> -d MSEC Number of milliseconds for the work [10]
</span><span class="cx"> -l NUM Total number of requests from all processes
</span><span class="lines">@@ -139,7 +149,7 @@
</span><span class="cx"> "numProcesses": 10,
</span><span class="cx"> "interval": 1000,
</span><span class="cx"> "jobs": 1,
</span><del>- "server": "localhost:8443",
</del><ins>+ "server": "https://localhost:8443",
</ins><span class="cx"> "when": 0,
</span><span class="cx"> "delay": 10,
</span><span class="cx"> "priority": "high",
</span></span></pre></div>
<a id="CalendarServertrunkcontribperformancejobqueueworkratepy"></a>
<div class="addfile"><h4>Added: CalendarServer/trunk/contrib/performance/jobqueue/workrate.py (0 => 15091)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/contrib/performance/jobqueue/workrate.py         (rev 0)
+++ CalendarServer/trunk/contrib/performance/jobqueue/workrate.py        2015-09-02 20:34:57 UTC (rev 15091)
</span><span class="lines">@@ -0,0 +1,224 @@
</span><ins>+#!/usr/bin/env python
+##
+# Copyright (c) 2012-2015 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+from __future__ import print_function
+
+from getopt import getopt, GetoptError
+import errno
+import json
+import os
+import sched
+import socket
+import sys
+import time
+
+
+def usage(e=None):
+ name = os.path.basename(sys.argv[0])
+ print("usage: %s [options]" % (name,))
+ print("")
+ print("options:")
+ print(" -h --help: print this help and exit")
+ print(" -s: server host (and optional port) [localhost:8100]")
+ print(" or unix socket path prefixed by 'unix:'")
+ print("")
+ print("This tool monitors the server's job assignment rate.")
+
+ if e:
+ sys.exit(64)
+ else:
+ sys.exit(0)
+
+
+
+def main():
+ try:
+ (optargs, _ignore_args) = getopt(
+ sys.argv[1:], "hs:", [
+ "help",
+ ],
+ )
+ except GetoptError, e:
+ usage(e)
+
+ #
+ # Get configuration
+ #
+ server = ("localhost", 8100)
+
+ for opt, arg in optargs:
+ if opt in ("-h", "--help"):
+ usage()
+
+ elif opt in ("-s"):
+ if not arg.startswith("unix:"):
+ server = arg.split(":")
+ if len(server) == 1:
+ server.append(8100)
+ else:
+ server[1] = int(server[1])
+ server = tuple(server)
+ else:
+ server = arg
+
+ else:
+ raise NotImplementedError(opt)
+
+ d = Monitor(server)
+ d.run()
+
+
+
+class Monitor(object):
+ """
+ Main monitor controller. Use Python's L{sched} feature to schedule
+ updates.
+ """
+
+ screen = None
+ registered_windows = {}
+ registered_order = []
+
+ def __init__(self, server):
+ self.paused = False
+ self.seconds = 1.0
+ self.sched = sched.scheduler(time.time, time.sleep)
+ self.client = MonitorClient(server)
+ self.client.addItem("test_work")
+ self.last_queued = None
+ self.last_completed = None
+ self.last_time = None
+
+
+ def run(self):
+ """
+ Create the initial window and run the L{scheduler}.
+ """
+ self.sched.enter(self.seconds, 0, self.updateResults, ())
+ self.sched.run()
+
+
+ def updateResults(self):
+ """
+ Periodic update of the current window and check for a key press.
+ """
+
+ t = time.time()
+ self.client.update()
+ if len(self.client.currentData) == 0:
+ print("Failed to read any valid data from the server - exiting")
+ sys.exit(1)
+
+ queued = self.client.currentData["test_work"]["queued"]
+ completed = self.client.currentData["test_work"]["completed"]
+ if self.last_queued is not None:
+ diff_queued = (self.last_queued - queued) / (t - self.last_time)
+ diff_completed = (completed - self.last_completed) / (t - self.last_time)
+ else:
+ diff_queued = 0
+ diff_completed = 0
+ self.last_queued = queued
+ self.last_completed = completed
+ self.last_time = t
+ print("{}\t{:.1f}\t{:.1f}".format(queued, diff_queued, diff_completed,))
+
+ self.sched.enter(max(self.seconds - (time.time() - t), 0), 0, self.updateResults, ())
+
+
+
+class MonitorClient(object):
+ """
+ Client that connects to a server and fetches information.
+ """
+
+ def __init__(self, sockname):
+ self.socket = None
+ if isinstance(sockname, str):
+ self.sockname = sockname[5:]
+ self.useTCP = False
+ else:
+ self.sockname = sockname
+ self.useTCP = True
+ self.currentData = {}
+ self.items = []
+
+
+ def readSock(self, items):
+ """
+ Open a socket, send the specified request, and retrieve the response. Keep the socket open.
+ """
+ try:
+ if self.socket is None:
+ self.socket = socket.socket(socket.AF_INET if self.useTCP else socket.AF_UNIX, socket.SOCK_STREAM)
+ self.socket.connect(self.sockname)
+ self.socket.setblocking(0)
+ self.socket.sendall(json.dumps(items) + "\r\n")
+ data = ""
+ t = time.time()
+ while not data.endswith("\n"):
+ try:
+ d = self.socket.recv(1024)
+ except socket.error as se:
+ if se.args[0] != errno.EWOULDBLOCK:
+ raise
+ if time.time() - t > 5:
+ raise socket.error
+ continue
+ if d:
+ data += d
+ else:
+ break
+ data = json.loads(data)
+ except socket.error:
+ data = {}
+ self.socket = None
+ except ValueError:
+ data = {}
+ return data
+
+
+ def update(self):
+ """
+ Update the current data from the server.
+ """
+
+ # Only read each item once
+ self.currentData = self.readSock(list(set(self.items)))
+
+
+ def getOneItem(self, item):
+ """
+ Update the current data from the server.
+ """
+ data = self.readSock([item])
+ return data[item] if data else None
+
+
+ def addItem(self, item):
+ """
+ Add a server data item to monitor.
+ """
+ self.items.append(item)
+
+
+ def removeItem(self, item):
+ """
+ No need to monitor this item.
+ """
+ self.items.remove(item)
+
+if __name__ == "__main__":
+ main()
</ins></span></pre>
</div>
</div>
</body>
</html>