[CalendarServer-changes] [15573] CalendarServer/trunk/contrib/performance/loadtest
source_changes at macosforge.org
source_changes at macosforge.org
Thu May 5 10:12:41 PDT 2016
Revision: 15573
http://trac.calendarserver.org//changeset/15573
Author: sagen at apple.com
Date: 2016-05-05 10:12:41 -0700 (Thu, 05 May 2016)
Log Message:
-----------
Simulator clients now use a single AMP connection per server rather than each client connecting to each server
Modified Paths:
--------------
CalendarServer/trunk/contrib/performance/loadtest/ical.py
CalendarServer/trunk/contrib/performance/loadtest/sim.py
Added Paths:
-----------
CalendarServer/trunk/contrib/performance/loadtest/amphub.py
CalendarServer/trunk/contrib/performance/loadtest/test_amphub.py
Added: CalendarServer/trunk/contrib/performance/loadtest/amphub.py
===================================================================
--- CalendarServer/trunk/contrib/performance/loadtest/amphub.py (rev 0)
+++ CalendarServer/trunk/contrib/performance/loadtest/amphub.py 2016-05-05 17:12:41 UTC (rev 15573)
@@ -0,0 +1,87 @@
+##
+# Copyright (c) 2016 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 calendarserver.push.amppush import AMPPushClientFactory, SubscribeToID
+from twisted.internet.endpoints import TCP4ClientEndpoint
+from twisted.internet.defer import inlineCallbacks
+from twisted.internet import reactor
+from uuid import uuid4
+
+
+class AMPHub(object):
+
+ _hub = None
+
+ def __init__(self):
+ # self.hostsAndPorts = hostsAndPorts
+ self.protocols = []
+ self.callbacks = {}
+
+
+ @classmethod
+ @inlineCallbacks
+ def start(cls, hostsAndPorts):
+ """
+ Instantiates the AMPHub singleton and connects to the hosts.
+
+ @param hostsAndPorts: The hosts and ports to connect to
+ @type hostsAndPorts: A list of (hostname, port) tuples
+ """
+
+ cls._hub = cls()
+
+ for host, port in hostsAndPorts:
+ endpoint = TCP4ClientEndpoint(reactor, host, port)
+ factory = AMPPushClientFactory(cls._hub._pushReceived)
+ protocol = yield endpoint.connect(factory)
+ cls._hub.protocols.append(protocol)
+
+
+ @classmethod
+ @inlineCallbacks
+ def subscribeToIDs(cls, ids, callback):
+ """
+ Clients can call this method to register a callback which
+ will get called whenever a push notification is fired for any
+ id in the ids list.
+
+ @param ids: The push IDs to subscribe to
+ @type ids: list of strings
+ @param callback: The method to call whenever a notification is
+ received.
+ @type callback: callable which is passed an id (string), a timestamp
+ of the change in data triggering this push (integer), and the
+ priority level (integer)
+
+ """
+ hub = cls._hub
+
+ for id in ids:
+ hub.callbacks.setdefault(id, []).append(callback)
+ for protocol in hub.protocols:
+ yield protocol.callRemote(SubscribeToID, token=str(uuid4()), id=id)
+
+
+ def _pushReceived(self, id, dataChangedTimestamp, priority=5):
+ """
+ Called for every incoming push notification, this method then calls
+ each callback registered for the given ID.
+ """
+
+ for callback in self.callbacks.setdefault(id, []):
+ callback(id, dataChangedTimestamp, priority=priority)
Modified: CalendarServer/trunk/contrib/performance/loadtest/ical.py
===================================================================
--- CalendarServer/trunk/contrib/performance/loadtest/ical.py 2016-05-03 16:46:28 UTC (rev 15572)
+++ CalendarServer/trunk/contrib/performance/loadtest/ical.py 2016-05-05 17:12:41 UTC (rev 15573)
@@ -25,9 +25,9 @@
from caldavclientlibrary.protocol.webdav.definitions import davxml
from caldavclientlibrary.protocol.webdav.propfindparser import PropFindParser
-from calendarserver.push.amppush import subscribeToIDs
from calendarserver.tools.notifications import PubSubClientFactory
+from contrib.performance.loadtest.amphub import AMPHub
from contrib.performance.httpauth import AuthHandlerAgent
from contrib.performance.httpclient import StringProducer, readBody
from contrib.performance.loadtest.subscribe import Periodical
@@ -1510,11 +1510,7 @@
"""
Start monitoring for AMP-based push notifications
"""
- for host in self.ampPushHosts:
- subscribeToIDs(
- host, self.ampPushPort, pushKeys,
- self._receivedPush, self.reactor
- )
+ AMPHub.subscribeToIDs(pushKeys, self._receivedPush)
@inlineCallbacks
Modified: CalendarServer/trunk/contrib/performance/loadtest/sim.py
===================================================================
--- CalendarServer/trunk/contrib/performance/loadtest/sim.py 2016-05-03 16:46:28 UTC (rev 15572)
+++ CalendarServer/trunk/contrib/performance/loadtest/sim.py 2016-05-05 17:12:41 UTC (rev 15573)
@@ -59,6 +59,8 @@
CalendarClientSimulator)
from contrib.performance.loadtest.webadmin import LoadSimAdminResource
+from contrib.performance.loadtest.amphub import AMPHub
+
class _DirectoryRecord(object):
def __init__(self, uid, password, commonName, email, guid, podID="PodA"):
self.uid = uid
@@ -487,12 +489,24 @@
attachService(self.reactor, self, self.ms)
+ def startAmpHub(self):
+ hostsAndPorts = []
+ for serverInfo in self.servers.itervalues():
+ if serverInfo["enabled"]:
+ for host in serverInfo.get("ampPushHosts", []):
+ hostsAndPorts.append((host, serverInfo["ampPushPort"]))
+ if hostsAndPorts:
+ AMPHub.start(hostsAndPorts)
+
+
+
def run(self, output=stdout):
self.attachServices(output)
if self.runtime is not None:
self.reactor.callLater(self.runtime, self.stopAndReport)
if self.webadminPort:
self.reactor.listenTCP(self.webadminPort, Site(LoadSimAdminResource(self)))
+ self.startAmpHub()
self.reactor.run()
# Return code to indicate pass or fail
Added: CalendarServer/trunk/contrib/performance/loadtest/test_amphub.py
===================================================================
--- CalendarServer/trunk/contrib/performance/loadtest/test_amphub.py (rev 0)
+++ CalendarServer/trunk/contrib/performance/loadtest/test_amphub.py 2016-05-05 17:12:41 UTC (rev 15573)
@@ -0,0 +1,56 @@
+##
+# Copyright (c) 2011-2016 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 twisted.internet.defer import inlineCallbacks, succeed
+from twisted.trial.unittest import TestCase
+
+from contrib.performance.loadtest.amphub import AMPHub
+
+class StubProtocol(object):
+
+ def __init__(self, history):
+ self.history = history
+
+ def callRemote(self, *args, **kwds):
+ self.history.append((args, kwds))
+ return succeed(None)
+
+
+class AMPHubTestCase(TestCase):
+
+ def callback(self, id, dataChangedTimestamp, priority=5):
+ self.callbackHistory.append(id)
+
+ @inlineCallbacks
+ def test_amphub(self):
+ amphub = AMPHub()
+ subscribeHistory = []
+ protocol = StubProtocol(subscribeHistory)
+ amphub.protocols.append(protocol)
+ AMPHub._hub = amphub
+ keys = ("a", "b", "c")
+ yield AMPHub.subscribeToIDs(keys, self.callback)
+ self.assertEquals(len(subscribeHistory), 3)
+ for key in keys:
+ self.assertEquals(len(amphub.callbacks[key]), 1)
+
+ self.callbackHistory = []
+ amphub._pushReceived("a", 0)
+ amphub._pushReceived("b", 0)
+ amphub._pushReceived("a", 0)
+ amphub._pushReceived("c", 0)
+ self.assertEquals(self.callbackHistory, ["a", "b", "a", "c"])
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20160505/241132ca/attachment.html>
More information about the calendarserver-changes
mailing list