flypen
flypen

Reputation: 2585

What's the best way of communication between tornado and Python based daemon?

I use Tornado as the web server. I write some daemons with Python, which run in the server hardware. Sometimes the web server needs to send some data to the daemon and receives some computed results. There are two working: 1. Asynchronous mode: the server sends some data to the daemons, and it doesn't need the results soon. Can I use message queue to do it perfectly? 2. Synchronous mode: the server sends data to the daemons, and it will wait until it get the results. Should Iuse sockets?

So what's the best way of communication between tornado and Python based daemon?

Upvotes: 1

Views: 769

Answers (2)

zubinmehta
zubinmehta

Reputation: 4533

ZeroMQ can be used for this purpose. It has various sockets for different purposes and it's fast enough to never be your bottleneck. For asynchronous you can use DEALER/ROUTER sockets and for strict synchronous mode you can use REQ/REP sockets.

You can use the python binding for this --> http://www.zeromq.org/bindings:python.

For the async mode you can try something like this from the zguide chapter 3 Router-to-dealer async routing :

In your case, the "client" in the diagram will be your web server and your daemon will be the "worker".

zguide router-dealer-async-routing


For synchronous you can try a simple request-reply broker or some variant to suit your need.

a simple request-reply-broker

The diagram above shows a strictly synchronous cycle of send/recv at the REQ/REP sockets. Read through the zguide link to understand how it works. They also have a python code snippet on the page.

Upvotes: 1

koblas
koblas

Reputation: 27118

Depending on the scale - the simple thing is to just use HTTP and the AsyncHTTPClient in Tornado. For the request<->response case in our application we're going 300 connections/second with such an approach.

For the first case Fire and forget, you could also use AsyncHTTP and just have the server close out the connection and continue working...

Upvotes: 0

Related Questions