1

All examples in the Tornado documents show how we can make further HTTP requests asynchronously using Tornado.

http_client = httpclient.AsyncHTTPClient()
http_client.fetch("http://www.google.com/", handle_request)

While I want to ensure that my tornado doesn't wait for response from database (get command of couchbase) to send next.

Check my other bug to understand why I want async call to couchbase.

Community
  • 1
  • 1
codersofthedark
  • 9,183
  • 8
  • 45
  • 70
  • Aren't "asynchronous" and "doesn't wait for a response" the same thing? So the examples should show you exactly what you want, yes? – Kevin Feb 26 '13 at 15:55
  • The are the same thing, problem is Torndao starts waiting for response from Couchbase. – codersofthedark Mar 04 '13 at 20:36

3 Answers3

3

As far as I know Couchbase driver is not an async driver so this wont work. Make the db call synchronous and optimize it to be as fast as possible.

The (scary) alternative is to take couchbase's driver and patch it with something like gevent to create your own async driver. I do not recommend doing this. If you really want to go down this route look at what this guy did with Motor - He made the mongo driver async.

Community
  • 1
  • 1
andy boot
  • 11,355
  • 3
  • 53
  • 66
  • Why you dont recommend this? – codersofthedark Mar 01 '13 at 11:41
  • because its easy to make mistakes and because you would have to do everything again every time couchbase produced a new version of their driver. – andy boot Mar 01 '13 at 11:50
  • Problem is serially on the given machine I am only able to make 500 calls per sec synchronously to the db while asynchronously this scales to 5000+ asynchronously. Couchbase driver is not efficient and my plan to aysnc was to overcome its inefficiency indirectly. What shall you suggest for the stated scenario? – codersofthedark Mar 01 '13 at 12:03
  • we can use something like twisted also, cant we? – codersofthedark Mar 01 '13 at 12:03
  • If you really need that many calls per second and there is no other way of optimizing the calls or running multiple machines then I would look at making your own async library - but you are going beyond my knowledge area there. – andy boot Mar 01 '13 at 12:23
  • you could use twisted instead of tornado but this would make no difference to your current problem – andy boot Mar 03 '13 at 12:52
  • can i use twisted within tornado for making calls to couchbase? – codersofthedark Mar 03 '13 at 22:57
  • 1
    short answer no. Long answer you can use cyclone but this will make your life harder not easier – andy boot Mar 04 '13 at 11:04
  • because you would still have to find a couchbase twisted driver. There isn't one at the minute. So you'd be adding another framework and not getting any benefit – andy boot Mar 05 '13 at 16:27
1

See the Tornado wiki on github and this similar question on StackOverflow. Just do your database calls sync. If your database or your calls to the database/the database driver is your bottleneck your website will not be faster even if tornado is not blocked. Doing asynchronous calls may be more senseful when requesting ressources not under your control as other webservers or ressources which are not vital to most parts of your website like file I/Os.

Community
  • 1
  • 1
Georg Jung
  • 949
  • 10
  • 27
1

Old thread, but I should probably mention that couchbase has support for twisted. See Twisted API for Couchbase not working with Python Tornado and http://pythonhosted.org/couchbase/api/txcouchbase.html

Community
  • 1
  • 1
Mark Nunberg
  • 3,551
  • 15
  • 18