Skip to content
Browse files

add a mode to use the simple http client

  • Loading branch information...
1 parent e6b230e commit 936952f4216534a004a45d03fec5ab94830028c8 @eklitzke eklitzke committed Apr 7, 2011
Showing with 21 additions and 3 deletions.
  1. +8 −0 .gitignore
  2. +13 −3 client.py
View
8 .gitignore
@@ -1,2 +1,10 @@
*.py[co]
*~
+*.sw[nop]
+*.egg-info/
+build
+dist
+lib
+lib64
+bin
+include
View
16 client.py
@@ -1,6 +1,8 @@
import optparse
import time
import tornado.httpclient
+import tornado.httputil
+import tornado.simple_httpclient
class ClientBenchmark(object):
@@ -11,8 +13,10 @@ def __init__(self, client, io_loop, url='http://localhost:8888/'):
self.response_times = []
self.requests = 0
self.io_loop = io_loop
+ self.headers = tornado.httputil.HTTPHeaders({'Connection': 'close'})
def handle_response(self, response):
+ #print 'handle_response'
self.count += 1
self.response_times.append(1000 * (time.time() - self.time_start))
if self.count < self.requests:
@@ -26,8 +30,10 @@ def handle_response(self, response):
print '95th percentile time was %f' % (self.response_times[int(len(self.response_times) * 0.95)],)
def run_once(self):
+ #print 'run once'
self.time_start = time.time()
- self.client.fetch(self.url, self.handle_response)
+ request = tornado.httpclient.HTTPRequest(self.url, headers=self.headers)
+ self.client.fetch(request, self.handle_response)
def run(self, requests):
self.count = 0
@@ -36,11 +42,15 @@ def run(self, requests):
if __name__ == '__main__':
parser = optparse.OptionParser()
- parser.add_option('-r', '--requests', default=10000, type='int')
+ parser.add_option('-r', '--requests', default=10000, type='int', help='how many requests to make')
+ parser.add_option('-s', '--simple', action='store_true', default=False, help='use simple_httpclient')
opts, args = parser.parse_args()
io_loop = tornado.ioloop.IOLoop.instance()
- async_client = tornado.httpclient.AsyncHTTPClient2(io_loop=io_loop)
+ if opts.simple:
+ async_client = tornado.simple_httpclient.SimpleAsyncHTTPClient(io_loop=io_loop, max_clients=1)
+ else:
+ async_client = tornado.httpclient.AsyncHTTPClient2(io_loop=io_loop)
bench = ClientBenchmark(async_client, io_loop)
io_loop.add_callback(lambda: bench.run(opts.requests))
io_loop.start()

0 comments on commit 936952f

Please sign in to comment.
Something went wrong with that request. Please try again.