J
J
Jekson2019-02-25 12:25:07
Nginx
Jekson, 2019-02-25 12:25:07

How to avoid 502 server error when executing a heavy script?

Small flask webserver with two endpoints. The image is loaded and processed, on the local script is executed for 8-10 seconds. Hosted the whole thing on digitalocean on a compute-optimized VPS for $40/mo. Used nginx and uwsgi. Now the script starts and issues 502 after 10 seconds. The image is saved on the server.
nginx log

2019/02/25 08:59:19 [error] 2947#2947: *1 upstream prematurely closed connection while reading response header from upstream, client: xxx.17.x6.62, server: 1xx.62.203.2xx, request: "POST / HTTP/1.1", upstream: "uwsgi://unix:/home/jekson/bee/app/bee.sock:", host: "x8.x2.203.227", , referrer: "http://xx8.x2.203.227/"

uwsgi log
[pid: 3083|app: 0|req: 1/1] xx4.17.26.x2 () {40 vars in 718 bytes} [Mon Feb 25 09:15:01 2019] GET / => generated 863 bytes in 16 msecs (HTTP/1.1 200) 2 headers in 80 bytes (1 switches on core 0)
Using cpu

DAMN ! worker 2 (pid: 3086) died, killed by signal 9 :( trying respawn ...
Respawned uWSGI worker 2 (new pid: 3279)

nginx server
server {
    listen 80;
    server_name xx8.62.203.xx7 www.xx8.62.203.xx7;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/home/jekson/bee/app/bee.sock;
        proxy_connect_timeout 300s;
        proxy_read_timeout 300s;
    }
}

nginx.conf
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;

}

http {

        ##
        # Basic Settings
        ##
        client_max_body_size 8M;
        uwsgi_read_timeout 86400;
        uwsgi_send_timeout 86400;
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
       

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

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_comp_level 6;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

Broke my head, need help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2019-02-25
@Lepilov

Long tasks should be shifted to Celery or similar.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question