Last active
November 23, 2015 21:44
-
-
Save fluential/4964617f5e28103b5298 to your computer and use it in GitHub Desktop.
async test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys, time | |
import pickle | |
import tornado | |
from tornado import gen | |
from tornado.httpclient import AsyncHTTPClient | |
from tornado.ioloop import IOLoop | |
import itertools | |
from tornado.platform.caresresolver import CaresResolver | |
from tornado.httpclient import HTTPRequest | |
import logging | |
@gen.coroutine | |
def main(): | |
logger = logging.getLogger('prober') | |
logging.basicConfig(format='%(asctime)s [%(levelname)s]: %(message)s', level=logging.INFO) | |
http_client = AsyncHTTPClient() | |
AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient") | |
request = HTTPRequest(url='http://127.0.0.1', method='HEAD', connect_timeout=100, request_timeout=100) | |
url_list = [] | |
reqs = 1000 | |
i=0 | |
while i < reqs: | |
yield http_client.fetch( request ) | |
i+=1 | |
# while len(url_list) < reqs: | |
# yield http_client.fetch( request ) | |
# url_list.append('http://localhost') | |
if __name__ == '__main__': | |
now = time.time() | |
ioloop = IOLoop.current().run_sync(lambda: main()) | |
reqs = 1000 | |
delta = time.time() - now | |
req_per_sec = reqs / delta | |
print("request count:{}, {}req/s".format(reqs, req_per_sec)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment