tornado-压力测试

2017-01-01 10:46
  • 异步压力测试请求客户端,下面代码是post请求
import tornado.ioloop
from tornado.httpclient import AsyncHTTPClient
def handle_request(response):
    if response.error:
        print ("Error:", response.error)
    else:
        print(response.body)
param = {"msg":"111"}
param["img_msg"] = open("t.jpg",'r',encoding='utf-8')
url = 'http://gc.ditu.aliyun.com/geocoding?a=苏州市'
i = 1
print(param)
req = tornado.httpclient.HTTPRequest(url, 'POST', body=str(param))
http_client = AsyncHTTPClient()
while i<10000:
    i += 1
    http_client.fetch(req, handle_request)
tornado.ioloop.IOLoop.instance().start()