简体   繁体   English

Python Flask超时了吗? FLASK + NGINX + uWSGI

[英]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. 我有一个可以从任何地方访问的NGINX Web服务器,它在uWSGI的帮助下为python文件提供服务。 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. 在python文件中,我利用mysql-connector库从同一台计算机上运行的mysql数据库中获取信息。 (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. 我有一个索引页面,它仅返回一个字符串,和一个/ resources页面,该页面与数据库连接并在json中返回一些信息。

After give or take 15 minutes everything breaks down. 付出或花费15分钟后,一切都会崩溃。 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. 我只是重新启动了uWSGI,以缩小原因范围,然后使我的应用重新恢复在线。 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/ 我使用了以下链接:我使用了以下链接: 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 UWSGI日志文件

clock source: unix detected number of CPU cores: 4 current working directory: /home/pi detected binary path: /usr/local/bin/uwsgi !!! 时钟源:unix检测到的CPU内核数:4当前工作目录:/ home / pi检测到的二进制路径:/ usr / local / bin / uwsgi! no internal routing support, rebuild with pcre support !!! 没有内部路由支持,使用pcre支持进行重建!!! * WARNING: you are running uWSGI without its master process manager *警告:您正在运行没有其主进程管理器的uWSGI 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 您的进程数限制为7336,您的内存页面大小为4096个字节(检测到的最大文件描述符数):65536锁定引擎:pthread健壮的互斥体雷锁:禁用(您可以使用--thunder-lock启用)uwsgi socket 0绑定到UNIX地址/ var / www / demoapp / demoapp_uwsgi.sock fd 3 Python版本:2.7.9(默认值,2016年9月17日,20:55:23)[GCC 4.9.2]将PythonHome设置为/ var / www / demoapp / venv Python threads support is disabled. Python线程支持已禁用。 You can enable it with --enable-threads 您可以使用--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 Python主解释器初始化为0x67b490,您的服务器套接字监听积压被限制为100个连接;对工作者进行正常操作的怜悯是60秒,对应于1个内核的64256字节(62 KB)映射 Operational MODE: single process 操作模式:单过程 added /var/www/demoapp/ to pythonpath. 在pythonpath中添加了/ var / www / demoapp /。 WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x67b490 pid: 32459 (default app) WSGI应用程序0(mountpoint ='')在0秒内在解释器0x67b490 pid上准备就绪:32459(默认应用程序) uWSGI is running in multiple interpreter mode * spawned uWSGI worker 1 (and the only) (pid: 32459, cores: 1) uWSGI在多种解释器模式下运行*产生了uWSGI worker 1(也是唯一的)(pid:32459,核心:1)

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. 一个工作人员会阻塞,因为通常情况下,您将有一个工作人员接受请求并执行一个I / O操作,即从您的案例中读取数据库。 Because you only have one worker, this becomes problematic. 因为您只有一名工人,所以这成为问题。

See the docs for some tips (you may search for processes on this page). 请参阅文档以获取一些提示(您可以在此页面上搜索processes )。 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). 您可以通过在命令行中使用-p num选项来增加工作程序数量,或者通过配置文件中的processes = num来增加工作数量(num是所需的整数)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM