Commits

Maciej Fijalkowski committed b27b48b

add a warmup

Comments (0)

Files changed (1)

asynchammer/asynchammer.py

             self.factory.next()
 
 class HammerFactory(Factory):
-    def __init__(self, endpoint, max):
+    def __init__(self, endpoint, max, warmup):
         self.endpoint = endpoint
         self.max = max
         self.counter = 0
         self.done = 0
         self.errors = 0
-        self.t0 = time.time()
+        self.warmup = warmup
     
     def buildProtocol(self, addr):
         return Hammer(self)
         self.counter += 1
         if self.counter % 1000 == 0:
             print self.counter
+        if self.counter == self.warmup:
+            self.t0 = time.time()
         if self.counter == self.max:
             self.done = 1
 
     def print_stats(self):
-        reqs = int(self.counter / (time.time() - self.t0))
+        reqs = int((self.counter - self.warmup) / (time.time() - self.t0))
         print "Req/s %d" % reqs
         print "Errors: %d" % self.errors
             
                       default=10, type=int)
     parser.add_option('-m', '--max', dest='max', default=1000, type=int)
     parser.add_option('--host', dest='host', default='localhost:80')
+    parser.add_option('--warmup', dest='warmup', default=5000, type=int)
     (options, args) = parser.parse_args()
     hostname, port = options.host.split(':')
     if hostname == 'localhost':
         hostname == '127.0.0.1'
     point = TCP4ClientEndpoint(reactor, hostname, int(port))
-    factory = HammerFactory(point, options.max)
+    factory = HammerFactory(point, options.max + options.warmup, options.warmup)
     for i in xrange(options.concurrency):
         factory.next()
     reactor.run()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.