Re: [tornado] tornado AsyncHTTPClient only can process one request on the same time

165 views
Skip to first unread message

Ben Darnell

unread,
Oct 8, 2012, 1:08:59 PM10/8/12
to python-...@googlegroups.com
In general AsyncHTTPClient should be able to handle multiple requests
concurrently, but there is one part of it that does block the IOLoop:
DNS resolution. If your DNS calls are slow then you will see problems
like what you're describing. The best way to deal with slow DNS in
tornado 2.4 is to compile libcurl with c-ares support (which is not
the default, so you'll probably have to build it yourself instead of
getting it from your distribution's package manager) and use
CurlAsyncHTTPClient. In 3.0 you'll be able to use a thread pool with
SimpleAsyncHTTPClient.

-Ben

On Mon, Oct 8, 2012 at 12:34 AM, Jet Vster <jetv...@gmail.com> wrote:
>
>
>> import logging
>>
>> import tornado.httpserver
>> import tornado.ioloop
>> import tornado.web
>> from tornado import gen
>> from tornado.web import asynchronous
>>
>> from tornado.httpclient import AsyncHTTPClient
>>
>> class MainHandler(tornado.web.RequestHandler):
>>
>> @asynchronous
>> @gen.engine
>> def get(self):
>> http_client = AsyncHTTPClient()
>> self.write("finish")
>> response = yield gen.Task(http_client.fetch,
>> "http://examplay.com",request_timeout=4)
>> if response.error:
>> self.write('except')
>> else :
>> self.write(response.body)
>>
>> self.flush()
>> self.finish()
>>
>> settings = {
>> #"debug": True,
>> }
>>
>> application = tornado.web.Application([
>> (r"/", MainHandler),
>> ], **settings)
>>
>> if __name__ == "__main__":
>>
>> http_server = tornado.httpserver.HTTPServer(application)
>> http_server.listen(8083)
>> tornado.ioloop.IOLoop.instance().start()
>
>
>
>
> when url is wrong,it alows throw the exception 'timeout'
>
> then i send Multi requests in the same time, tornado will process request
> one by one.
>
> How to process multi AsyncHTTPClient on the same time?
>
>

Jetvster

unread,
Oct 9, 2012, 6:08:35 AM10/9/12
to python-...@googlegroups.com, b...@bendarnell.com
hi Ben

thanks
 i replace the domain with ip '10.167.8.3','10.167.8.3' is down.
it's block too.  and use SimpleAsyncHTTPClient  also have same problem.

the code is the same with tornado document,the document say it's non-blocking

but  in my code  it's block all other request when one request is processing

any problem in my code?
Reply all
Reply to author
Forward
0 new messages