为什么多进程在Django runserver上工作,而不是在ngnix uwsgi上运行? [英] Why does multiprocessing work on Django runserver and not on ngnix uwsgi?
问题描述
当我在ngnix uwsgi中部署应用程序时,快速响应延迟了50-60秒,并且与完成该过程。
我记录了进入视图之前的时间,然后才发送响应,而且是1-2秒。
我使用wireshark检查数据包,所有通信在进程持续时间内停止,即50-60秒。
在uwsgi .ini文件我使用进程= 3
我会感谢一个解决方案或一行调查。
.ini文件:
[uwsgi],chdir = / nnnhn /,module = wsgi,#master = True,pidfile = / tmp / project-master.pid,vacuum = True,max-r equests = 5000,daemonize = / var / log / uwsgi.log,socket = / tmp / uwsgi.sock,uid = hhm,processes = 3,pythonpath = / csghgfh / doo
过程产生代码:
process = multiprocessing.Process(target = Util。 processImage1,args =(processUtil,img_full_path,snapshot.pk,process_pk,db_name,process_table_name)
process.start()
相关的生成代码:
def processImage1(self,img_full_path,snapshot_pk,process_pk,db_name,
connection.close()
print('')
print('我想我只是关闭db连接连接')
print('')
print('processImage1:',datetime.now())
print('process_pk:',process_pk)
sys.stdout.flush()
try:
con = psycopg2.connect(host ='a',database = db_name,user ='a')
cur = con.cursor()
这在uWSGI文档的(可能)最重要的页面中有所解释: http://uwsgi-docs.readthedocs.org/en/latest/ThingsToKnow.html
当fork()进程时,新的进程将继承连接描述符。您必须在新的分叉进程中关闭它,或者您可以添加--close-on-exec选项来强制自动执行
I have a Django 1.6 using python3.3 application which receives an http request, does short term work, starts a new process and returns in a matter of 2 seconds. The process typically takes 50-60 seconds at which time it writes that the data is free on the data base where a timed ajax call can retrieve the data and update the clint web page.
This works perfectly on the Django development runserver.
When I deploy the application on ngnix uwsgi the quick response is delayed for 50-60 seconds and appears in tandem with the completion of the process.
I logged the time between entering the view and just before sending the response and it was 1-2 seconds.
I checked the packets with wireshark and all communication ceases for the duration of the process i.e 50-60 seconds.
in the uwsgi .ini file I used processes=3
I would be grateful for a solution or a line of investigation.
the .ini file:
[uwsgi], chdir=/nnnhn/, module=wsgi, #master=True, pidfile=/tmp/project-master.pid, vacuum=True, max-requests=5000, daemonize=/var/log/uwsgi.log, socket=/tmp/uwsgi.sock, uid=hhm, processes=3, pythonpath=/csghgfh/doo
the process spawning code:
process=multiprocessing.Process(target=Util.processImage1, args=(processUtil, img_full_path, snapshot.pk, process_pk, db_name, process_table_name))
process.start()
the relevant spawned code:
def processImage1(self, img_full_path, snapshot_pk, process_pk, db_name, process_table_name):
connection.close()
print('')
print('I think I just closed th db connection connection')
print('')
print('processImage1:', datetime.now())
print('process_pk: ', process_pk)
sys.stdout.flush()
try:
con = psycopg2.connect(host = 'a', database=db_name, user='a')
cur = con.cursor()
This is explained in the (probably) most important page of the uWSGI docs: http://uwsgi-docs.readthedocs.org/en/latest/ThingsToKnow.html
When you fork() the process, the new one will inherit the connection descriptor. You have to close it in the new forked process, or you can add the --close-on-exec option to force it automatically
这篇关于为什么多进程在Django runserver上工作,而不是在ngnix uwsgi上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!