0

In my project I have Nginx, Django and JQuery. I'm using JQuery post requests to call Django functions and sometimes it takes awhile to complete.
The problem is it looks like when I'm using async/await function with post, it blocks Nginx entirely until the task is completed. I can't even open a new tab or open my project on another computer

How can I fix that? Or should I use Celery instead?

JS function example:

async function very_long_function(params) {
    // some code
    await $.post(post_params).done(function (data) {
        // some code with data Django returned
    })
    // some code that has to be after
}

nginx.conf file:

user  nginx;
worker_processes 16;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections 1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request"'
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;

    keepalive_timeout  65s;

    include /etc/nginx/conf.d/*.conf;
}

1 Answer 1

0

It turned out the problem was not in Nginx, but in Gunicorn, which I used for Django. It looks like the Nginx configuration is fine, but in the backend I had only one synchronize worker by default. So I added --workers 4 --worker-class gevent in the Gunicorn launch script and now it works

Don't make my mistake.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.