From: CaStarCo <cas...@gm...> - 2009-12-09 10:01:51
|
Un mensaje de la lista de tornado :) , en cuanto liberen la nueva versión cambiaré el código y quedará simplificado :D , simplemente detectará el número de procesadores de forma automática y creará un proceso independiente por cada uno de ellos ^^. Además compartirán puertos, así que que nginx no tendrá que perder tiempo balanceando carga y de ello se encargará el kernel. ---------- Forwarded message ---------- From: Bret Taylor <bt...@gm...> Date: 2009/12/9 Subject: Run Tornado servers on all available CPUs with pre-forking To: pyt...@go... I just checked in a (experimental and backwards-compatible) change to enable "pre-forking" Tornado servers, and I would love your feedback: http://github.com/facebook/tornado/commit/6fb90ae694190fcedc48d9fb98b02325826d783e Previously, every Tornado server ran on a single thread within a single process. If your server had 8 cores, you would have to run 8 separate Tornado processes on 8 different ports to utilize all CPUs and put a reverse proxy like nginx in front to balance requests between all those processes (see http://www.tornadoweb.org/documentation#running-tornado-in-production). With this change, you can easily run a single Tornado server listening to a single port on all available CPUs of a server. To try out this change, change your call from listen(port) to bind(port) followed by start(), e.g., http_server = tornado.httpserver.HTTPServer(application) http_server.bind(options.port) http_server.start() # Pre-forks multiple child processes tornado.ioloop.IOLoop.instance().start() start() detects the number of CPUs on the current machine and "pre-forks" that number of child processes so that we have one Tornado process per CPU, all with their own IOLoop. You can also pass in the specific number of child processes you want to run with if you want to override this auto-detection. listen(port) is simply a shortcut for bind(port); start(1). Background The "pre-forking" phrase is used to mean a couple of different things, so it is worth clarifying what it means for Tornado. Essentially, we bind a single server socket to a port, and we fork() one process per CPU. Each of those CPUs calls accept() on the shared server socket, and the Linux kernel gives new requests to one of the child processes on a first-come-first-serve basis. Each of the child processes has their own epoll-based IO loop, and a single request is handled entirely within one of the child processes. There is no shared memory or shared state between the forked child processes, only a shared port. This technique is used by a number of high performance servers, including Unicorn (see http://tomayko.com/writings/unicorn-is-unix). Apache pre-forking means something entirely different (forking a process for each request), so please don't get confused if you Google "pre-forking" and see people talking about the performance characteristics of Apache. Bret -- - Per la llibertat del coneixement - - Per la llibertat de la ment... - |