[英]Tornado multiple processes: create multiple MySQL connections
I'm running a Tornado HTTPS server across multiple processes using the first method described here http://www.tornadoweb.org/en/stable/guide/running.html (server.start(n)) 我正在使用此处所述的第一种方法跨多个进程运行Tornado HTTPS服务器http://www.tornadoweb.org/en/stable/guide/running.html(server.start(n ))
The server is connected to a local MySQL instance and I would like to have a independent MySQL connection per Tornado process. 服务器已连接到本地MySQL实例,我希望每个Tornado进程都具有独立的MySQL连接。
However, right now I only have one MySQL connection according to the output of SHOW PROCESSLIST. 但是,根据SHOW PROCESSLIST的输出,现在我只有一个MySQL连接。 I guess this happens because I establish the connection before calling server.start(n) and IOLoop.current().start() right?
我猜是因为我在调用server.start(n)和IOLoop.current()。start()之前建立了连接,对吗?
What I don't really understand is whether the processes created after calling server.start(n) share some data (for instance, global variables within the same module) or are totally independent. 我真正不了解的是,调用server.start(n)之后创建的进程是共享某些数据(例如,同一模块内的全局变量)还是完全独立的。
Should I establish the connection after calling server.start(n) ? 我应该在调用server.start(n)之后建立连接吗? Or after calling IOLoop.current().start() ?
还是在调用IOLoop.current()。start()之后? If I do so, will I have one MySQL connection per Tornado process?
如果这样做,每个Tornado进程是否会有一个MySQL连接?
Thanks 谢谢
Each child process gets a copy of the variables that existed in the parent process when start(n)
was called. 当调用
start(n)
时,每个子进程都会获得父进程中存在的变量的副本。 For things like connections, this will usually cause problems. 对于诸如连接之类的事物,通常会引起问题。 When using multi-process mode, it's important to do as little as possible before starting the child processes, so don't create the mysql connections until after
start(n)
(but before IOLoop.start()
; IOLoop.start()
doesn't return until the server is stopped). 当使用多进程模式时,在启动子进程之前尽可能少地做是很重要的,因此在
start(n)
(但在IOLoop.start()
之前; IOLoop.start()
不会创建mysql连接IOLoop.start()
在服务器停止之前不会返回)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.