Stephen
Stephen

Reputation: 309

Python Flask time out? FLASK + NGINX + uWSGI

As usual, i have another very weird issue. I have a NGINX webserver that is accessible from anywhere.It is serving my python file with the help of uWSGI. Within the python file i make use of the mysql-connector library to get information from a mysql database that is running on the same machine. (The machine is a raspberry pi running raspbian). I have an index page that just returns a string and a /resources page that connects with the database and returns some information in json.

After give or take 15 minutes everything breaks down. The server becomes unesponsive and shows the 'Bad gateway' error or the 'a time out occured' error. I restarted just the uWSGI to narrow down the cause and doing so brings my app back online again. This means it's either that or my flask server somehow.

I used the following link: I used the following link: http://vladikk.com/2013/09/12/serving-flask-with-nginx-on-ubuntu/

I find it VERY difficult to find information about this. What could it be? How could i troubleshoot this? What are possible fixes?

UWSGI Logfiles

clock source: unix detected number of CPU cores: 4 current working directory: /home/pi detected binary path: /usr/local/bin/uwsgi !!! no internal routing support, rebuild with pcre support !!! * WARNING: you are running uWSGI without its master process manager your processes number limit is 7336 your memory page size is 4096 bytes detected max file descriptor number: 65536 lock engine: pthread robust mutexes thunder lock: disabled (you can enable it with --thunder-lock) uwsgi socket 0 bound to UNIX address /var/www/demoapp/demoapp_uwsgi.sock fd 3 Python version: 2.7.9 (default, Sep 17 2016, 20:55:23) [GCC 4.9.2] Set PythonHome to /var/www/demoapp/venv Python threads support is disabled. You can enable it with --enable-threads Python main interpreter initialized at 0x67b490 your server socket listen backlog is limited to 100 connections your mercy for graceful operations on workers is 60 seconds mapped 64256 bytes (62 KB) for 1 cores Operational MODE: single process added /var/www/demoapp/ to pythonpath. WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x67b490 pid: 32459 (default app) uWSGI is running in multiple interpreter mode * spawned uWSGI worker 1 (and the only) (pid: 32459, cores: 1)

Upvotes: 1

Views: 1528

Answers (1)

Keenan Lawrence
Keenan Lawrence

Reputation: 1464

This is a worker blocking issue.

One worker will block because usually, you'll have a worker accepting requests and one performing I/O operations, viz reading from a database in your case. Because you only have one worker, this becomes problematic.

See the docs for some tips (you may search for processes on this page). You can increase the number of workers by using the -p num option from the command line, or processes = num from a configuration file (num is the integer number of processes you want).

Upvotes: 2

Related Questions