我有个tornado服务的某个接口,是调用其他服务的返回值处理后,再返回给服务调用方,我发现我单独用curl请求url不慢,但是用yield AsyncHTTPClient().fetch(url)请求,超级慢,二三十秒回不来。
是AsyncHTTPClient本身处理机制的问题吗?
以下是我的代码:
begin=int(time.time()*1000)
url='http://example.com/server'
response = yield AsyncHTTPClient().fetch(url)
cost=int(time.time()*1000)-begin
log.info("cost:"+str(cost)+" code:"+str(response.code)
+" result:"+str(response.error)+" response:"+str(response.body))
cost能打印出30秒来
code:是599
这个要配合异步装饰器使用的,比如
tornado.gen.coroutine
可以参考 异步客户端AsyncHTTPClient