Running Tornado App on Individual Core

312 views
Skip to first unread message

Kandarp Desai

unread,
Mar 22, 2011, 8:56:28 PM3/22/11
to python-tornado
Hi,

I've multicore machine to run my tornado app.  After reading few discussions, I've decided to try Supervisor to monitor multiple tornado instances(on same machine) and nginx to balance across those instances. But, I want to assign each instance to individual core, e.g. On 4 cores machine, I want to assign 3 cores to each individual tornado instance running on different ports(8001,8002,8003) and 1 core to other python process. Is it possible to do with supervisor ? Or I have to use some other linux scheduler utilities ? Have anyone tried this kind scenario for their production environment ? Any other recommendation?
Thanks.

Regards,
Kandarp Desai 

David P. Novakovic

unread,
Mar 22, 2011, 8:58:56 PM3/22/11
to python-...@googlegroups.com
The operating system will assign the affinity of the processes. There is a fair bit of code in the kernel designed to handle this problem. Especially with regards to the various cache layers on a chip.

I'm assuming you are running a modern processor here :)

David

David P. Novakovic

unread,
Mar 22, 2011, 9:00:04 PM3/22/11
to python-...@googlegroups.com
Also further to this, you want to run more than one process per CPU. This will allow greater throughput as there are tiny amounts of time while tornado apps will be waiting for IO from the database.

We have a quad core machine and run 10 instances of tornado, sometimes more.

David

Kandarp Desai

unread,
Mar 22, 2011, 9:34:16 PM3/22/11
to python-...@googlegroups.com, David P. Novakovic
Thanks. got it. Basically, I don't need to worry about it :).  Also, I will have to do some benchmarking to do decide exact number of instances required for my app.  

Regards,
Kandarp Desai

Jeremy Kelley

unread,
Mar 22, 2011, 9:41:45 PM3/22/11
to python-...@googlegroups.com
Conservative rule-of-thumb (with no scientific backing ymmv iamal
blah) is 1.25-1.5 instances per core you want to "dedicate".

So for an 8 core box, let's say you want to give 7 cores to tornado.
I'd do 7*1.25= 8.75 (round up in this instance) 9 instances.

Again, ymmv.

-j

--
The Christian ideal has not been tried and found wanting;
it has been found difficult and left untried – G. K. Chesterton

Didip Kerabat

unread,
Mar 22, 2011, 10:07:42 PM3/22/11
to python-...@googlegroups.com
Pretty much. One thing to note, Nginx proxy_pass doesn't spread the load evenly (It does round robin). If you want to make sure traffic is spread more or less evenly, then you need Nginx fair balancer module:


Or use HAProxy

- Didip -

Phil Plante

unread,
Mar 23, 2011, 12:24:58 AM3/23/11
to python-...@googlegroups.com, Didip Kerabat
We run 16 instances on a Core i7 2.8ghz quad core with 24gb of ram.  Granted this is just our app server.  We came to this limit because most of the time we're waiting on a Sphinx Search query, or MySql to return data.  Very little time is spent in the Tornado app since its just an API.

Kandarp Desai

unread,
Mar 29, 2011, 2:39:52 PM3/29/11
to python-...@googlegroups.com, Phil Plante, Didip Kerabat
Thanks Guys for all suggestions :).
Reply all
Reply to author
Forward
0 new messages