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

source_changes at macosforge.org source_changes at macosforge.org
Mon Feb 21 12:18:55 PST 2011


Revision: 7062
          http://trac.macosforge.org/projects/calendarserver/changeset/7062
Author:   exarkun at twistedmatrix.com
Date:     2011-02-21 12:18:52 -0800 (Mon, 21 Feb 2011)
Log Message:
-----------
Load population parameters and client profiles from the config.

Modified Paths:
--------------
    CalendarServer/trunk/contrib/performance/loadtest/config.plist
    CalendarServer/trunk/contrib/performance/loadtest/population.py
    CalendarServer/trunk/contrib/performance/loadtest/sim.py
    CalendarServer/trunk/contrib/performance/loadtest/test_sim.py

Modified: CalendarServer/trunk/contrib/performance/loadtest/config.plist
===================================================================
--- CalendarServer/trunk/contrib/performance/loadtest/config.plist	2011-02-21 02:20:59 UTC (rev 7061)
+++ CalendarServer/trunk/contrib/performance/loadtest/config.plist	2011-02-21 20:18:52 UTC (rev 7062)
@@ -35,14 +35,33 @@
       <string>loadtest.population.SmoothRampUp</string>
 
       <key>groups</key>
-      <integer>10</integer>
+      <integer>60</integer>
 
       <key>groupSize</key>
       <integer>1</integer>
 
       <key>interval</key>
-      <integer>5</integer>
+      <integer>13</integer>
 
     </dict>
+
+    <key>clients</key>
+    <array>
+      <dict>
+	<key>software</key>
+	<string>loadtest.ical.SnowLeopard</string>
+
+	<key>profiles</key>
+	<array>
+	  <string>loadtest.profiles.Eventer</string>
+	  <string>loadtest.profiles.Inviter</string>
+	  <string>loadtest.profiles.Accepter</string>
+	</array>
+
+	<key>weight</key>
+	<integer>1</integer>
+      </dict>
+    </array>
+
   </dict>
 </plist>

Modified: CalendarServer/trunk/contrib/performance/loadtest/population.py
===================================================================
--- CalendarServer/trunk/contrib/performance/loadtest/population.py	2011-02-21 02:20:59 UTC (rev 7061)
+++ CalendarServer/trunk/contrib/performance/loadtest/population.py	2011-02-21 20:18:52 UTC (rev 7062)
@@ -22,34 +22,58 @@
 
 from itertools import izip
 
+from twisted.python.util import FancyEqMixin
+from twisted.python.log import msg
+
 from stats import mean, median, stddev, mad
 from loadtest.ical import SnowLeopard, RequestLogger
 from loadtest.profiles import Eventer, Inviter, Accepter
 
 
-class ClientType(object):
+class ClientType(object, FancyEqMixin):
     """
     @ivar clientType: An L{ICalendarClient} implementation
     @ivar profileTypes: A list of L{ICalendarUserProfile} implementations
     """
+    compareAttributes = ("clientType", "profileTypes")
+
     def __init__(self, clientType, profileTypes):
         self.clientType = clientType
         self.profileTypes = profileTypes
 
 
 
-class PopulationParameters(object):
+class PopulationParameters(object, FancyEqMixin):
     """
     Descriptive statistics about a population of Calendar Server users.
     """
+    compareAttributes = ("clients",)
+
+    def __init__(self):
+        self.clients = []
+
+
+    def addClient(self, weight, clientType):
+        """
+        Add another type of client to these parameters.
+
+        @param weight: A C{int} giving the weight of this client type.
+            The higher the weight, the more frequently a client of
+            this type will show up in the population described by
+            these parameters.
+
+        @param clientType: A L{ClientType} instance describing the
+            type of client to add.
+        """
+        self.clients.append((weight, clientType))
+
+
     def clientTypes(self):
         """
         Return a list of two-tuples giving the weights and types of
         clients in the population.
         """
-        return [
-            (1, ClientType(SnowLeopard, [Eventer, Inviter, Accepter])),
-            ]
+        return self.clients
 
 
 
@@ -242,6 +266,8 @@
     r.seed(100)
     populator = Populator(r)
     parameters = PopulationParameters()
+    parameters.addClient(
+        1, ClientType(SnowLeopard, [Eventer, Inviter, Accepter]))
     simulator = CalendarClientSimulator(
         populator, parameters, reactor, '127.0.0.1', 8008)
 

Modified: CalendarServer/trunk/contrib/performance/loadtest/sim.py
===================================================================
--- CalendarServer/trunk/contrib/performance/loadtest/sim.py	2011-02-21 02:20:59 UTC (rev 7061)
+++ CalendarServer/trunk/contrib/performance/loadtest/sim.py	2011-02-21 20:18:52 UTC (rev 7062)
@@ -24,8 +24,10 @@
 from twisted.python.usage import UsageError, Options
 from twisted.python.reflect import namedAny
 
+from loadtest.ical import SnowLeopard
+from loadtest.profiles import Eventer, Inviter, Accepter
 from loadtest.population import (
-    Populator, PopulationParameters, SmoothRampUp,
+    Populator, ClientType, PopulationParameters, SmoothRampUp,
     CalendarClientSimulator)
 
 
@@ -90,12 +92,15 @@
     clients.
 
     @type server: L{Server}
+    @type arrival: L{Arrival}
+    @type parameters: L{PopulationParameters}
     """
-    def __init__(self, server, arrival, reactor=None):
+    def __init__(self, server, arrival, parameters, reactor=None):
         if reactor is None:
             from twisted.internet import reactor
         self.server = server
         self.arrival = arrival
+        self.parameters = parameters
         self.reactor = reactor
 
 
@@ -125,26 +130,35 @@
             arrival = Arrival(
                 SmoothRampUp, dict(groups=10, groupSize=1, interval=3))
 
-        return cls(server, arrival)
 
+        parameters = PopulationParameters()
+        if 'clients' in options.config:
+            for clientConfig in options.config['clients']:
+                parameters.addClient(
+                    clientConfig["weight"],
+                    ClientType(
+                        namedAny(clientConfig["software"]),
+                        [namedAny(profile)
+                         for profile in clientConfig["profiles"]]))
+        if not parameters.clients:
+            parameters.addClient(
+                1, ClientType(SnowLeopard, [Eventer, Inviter, Accepter]))
 
+        return cls(server, arrival, parameters)
+
+
     @classmethod
     def main(cls, args=None):
         simulator = cls.fromCommandLine(args)
         raise SystemExit(simulator.run())
 
 
-    def createPopulationParameters(self):
-        return PopulationParameters()
-
-
     def createSimulator(self):
         host = self.server.host
         port = self.server.port
         populator = Populator(Random())
-        parameters = self.createPopulationParameters()
         return CalendarClientSimulator(
-            populator, parameters, self.reactor, host, port)
+            populator, self.parameters, self.reactor, host, port)
 
 
     def createArrivalPolicy(self):

Modified: CalendarServer/trunk/contrib/performance/loadtest/test_sim.py
===================================================================
--- CalendarServer/trunk/contrib/performance/loadtest/test_sim.py	2011-02-21 02:20:59 UTC (rev 7061)
+++ CalendarServer/trunk/contrib/performance/loadtest/test_sim.py	2011-02-21 20:18:52 UTC (rev 7062)
@@ -23,8 +23,11 @@
 from twisted.internet.defer import succeed
 from twisted.internet.task import Clock
 
+from loadtest.ical import SnowLeopard
+from loadtest.profiles import Eventer, Inviter, Accepter
+from loadtest.population import (
+    SmoothRampUp, ClientType, PopulationParameters, CalendarClientSimulator)
 from loadtest.sim import Server, Arrival, SimOptions, LoadSimulator, main
-from loadtest.population import SmoothRampUp, CalendarClientSimulator
 
 VALID_CONFIG = {
     'server': {
@@ -104,7 +107,7 @@
 
         exc = self.assertRaises(
             SystemExit, StubSimulator.main, ['--config', config.path])
-        self.assertEquals(exc.args, (StubSimulator(None, None).run(),))
+        self.assertEquals(exc.args, (StubSimulator(None, None, None).run(),))
 
 
     def test_createSimulator(self):
@@ -116,7 +119,7 @@
         host = '127.0.0.7'
         port = 1243
         reactor = object()
-        sim = LoadSimulator(Server(host, port), None, reactor)
+        sim = LoadSimulator(Server(host, port), None, None, reactor)
         calsim = sim.createSimulator()
         self.assertIsInstance(calsim, CalendarClientSimulator)
         self.assertIdentical(calsim.reactor, reactor)
@@ -173,9 +176,42 @@
 
         reactor = object()
         sim = LoadSimulator(
-            None, Arrival(FakeArrival, {'x': 3, 'y': 2}), reactor)
+            None, Arrival(FakeArrival, {'x': 3, 'y': 2}), None, reactor)
         arrival = sim.createArrivalPolicy()
         self.assertIsInstance(arrival, FakeArrival)
         self.assertIdentical(arrival.reactor, reactor)
         self.assertEquals(arrival.x, 3)
         self.assertEquals(arrival.y, 2)
+
+
+    def test_loadPopulationParameters(self):
+        """
+        Client weights and profiles are loaded from the [clients]
+        section of the configuration file specified.
+        """
+        config = FilePath(self.mktemp())
+        config.setContent(writePlistToString({
+                    "clients": [{
+                            "software": "loadtest.ical.SnowLeopard",
+                            "profiles": ["loadtest.profiles.Eventer"],
+                            "weight": 3,
+                            }]}))
+        sim = LoadSimulator.fromCommandLine(['--config', config.path])
+        expectedParameters = PopulationParameters()
+        expectedParameters.addClient(3, ClientType(SnowLeopard, [Eventer]))
+        self.assertEquals(sim.parameters, expectedParameters)
+
+        
+    def test_requireClient(self):
+        """
+        At least one client is required, so if a configuration with an
+        empty clients array is specified, a single default client type
+        is used.
+        """
+        config = FilePath(self.mktemp())
+        config.setContent(writePlistToString({"clients": []}))
+        sim = LoadSimulator.fromCommandLine(['--config', config.path])
+        expectedParameters = PopulationParameters()
+        expectedParameters.addClient(
+            1, ClientType(SnowLeopard, [Eventer, Inviter, Accepter]))
+        self.assertEquals(sim.parameters, expectedParameters)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110221/b8432088/attachment-0001.html>


More information about the calendarserver-changes mailing list