Why does multiprocessing work on a Django server and not on ngnix uwsgi?

I have Django 1.6 using a python3.3 application that receives an HTTP request, performs a short run, starts a new process and returns within 2 seconds. Usually the process takes 50-60 seconds, and at this time he writes that the data is free in the database, where a temporary ajax call can retrieve the data and refresh the wedge web page.

This works fine on the Django development server.

When I deploy the application to ngnix uwsgi, the quick response is delayed for 50-60 seconds and appears in tandem with the completion of the process.

I recorded the time between entering the view and immediately before sending the response, and this was 1-2 seconds.

I checked the packages using wirehark, and all communication stops during the whole process within 50-60 seconds.

in uwsgi.ini I used processes = 3

I would be grateful for the decision or line of investigation.

.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

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()

corresponding generated 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()
+4
source share
2 answers

This is explained on the (possibly) most important uWSGI docs page: http://uwsgi-docs.readthedocs.org/en/latest/ThingsToKnow.html

fork(), . -close-on-exec, .

+4

djcelery . , , ..

+1

Source: https://habr.com/ru/post/1542439/


All Articles