我在uwsgi上运行一个烧瓶应用程序.我使用主管来管理uwsgi进程.我发现日志说的那样
您的服务器套接字侦听backlog限制为100个连接.
如何克服100个连接限制?我的运行脚本如下:
[program:myapp]
command=uwsgi --master -s /tmp/app.sock --module myapp:app --processes 2 -H /srv/sites/mysite chmod-socket 666 --enable-threads
Run Code Online (Sandbox Code Playgroud) 我有Python Django应用程序的Nginx + uWSGI.
我有以下内容nginx.conf
:
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:9001;
uwsgi_read_timeout 1800;
uwsgi_send_timeout 300;
client_header_timeout 300;
proxy_read_timeout 300;
index index.html index.htm;
}
Run Code Online (Sandbox Code Playgroud)
但是对于uWSGI上长时间运行的请求大约需要1分钟才能完成,我在Nginx错误日志中会出现超时错误,如下所示:
2013/04/22 12:35:56 [错误] 2709#0:*1上游超时(110:连接超时)从上游读取响应头,客户端:xx.xx.xx.xx,server :, request :"GET/entity/datasenders/HTTP/1.1",上游:"uwsgi://127.0.0.1:9001",主机:"xxx.xx.xx.x"
我已经设置了标头超时和uWSGI发送/读取超时到5分钟,有人可以告诉我我能做些什么来克服这个问题?
我正在尝试使用uWSGI + Nginx设置应用程序webserver,它使用SQLAlchemy运行Flask应用程序与Postgres数据库进行通信.
当我向Web服务器发出请求时,每个其他响应都将是500错误.
错误是:
Traceback (most recent call last):
File "/var/env/argos/lib/python3.3/site-packages/sqlalchemy/engine/base.py", line 867, in _execute_context
context)
File "/var/env/argos/lib/python3.3/site-packages/sqlalchemy/engine/default.py", line 388, in do_execute
cursor.execute(statement, parameters)
psycopg2.OperationalError: SSL error: decryption failed or bad record mac
The above exception was the direct cause of the following exception:
sqlalchemy.exc.OperationalError: (OperationalError) SSL error: decryption failed or bad record mac
Run Code Online (Sandbox Code Playgroud)
该错误由一个简单的Flask-SQLAlchemy
方法触发:
result = models.Event.query.get(id)
Run Code Online (Sandbox Code Playgroud)
uwsgi
正在管理supervisor
,有一个配置:
[program:my_app]
command=/usr/bin/uwsgi --ini /etc/uwsgi/apps-enabled/myapp.ini --catch-exceptions
directory=/path/to/my/app
stopsignal=QUIT
autostart=true
autorestart=true
Run Code Online (Sandbox Code Playgroud)
和uwsgi
配置看起来像:
[uwsgi]
socket = …
Run Code Online (Sandbox Code Playgroud) 当我尝试在uWSGI下使用python pdb调试器时,执行不会在断点上停止,它只返回trackback.
这是代码:
def application(env, start_response):
import pdb; pdb.set_trace()
start_response('200 OK', [('Content-Type','text/html')])
return "Hello World"
Run Code Online (Sandbox Code Playgroud)
这是我运行它的方式:
uwsgi --http 127.0.0.1:7777 --wsgi-file uwsgi_test.py
Run Code Online (Sandbox Code Playgroud)
这就是我得到的:
/home/andrey/Development/ttt/uwsgi_test.py(3)application()
-> start_response('200 OK', [('Content-Type','text/html')])
(Pdb)
Traceback (most recent call last):
File "uwsgi_test.py", line 3, in application
start_response('200 OK', [('Content-Type','text/html')])
File "uwsgi_test.py", line 3, in application
start_response('200 OK', [('Content-Type','text/html')])
File "/usr/lib/python2.7/bdb.py", line 48, in trace_dispatch
return self.dispatch_line(frame)
File "/usr/lib/python2.7/bdb.py", line 67, in dispatch_line
if self.quitting: raise BdbQuit
bdb.BdbQuit
[pid: 11421|app: 0|req: 1/1] 127.0.0.1 () {32 vars in 366 …
Run Code Online (Sandbox Code Playgroud) 我正在使用:
uWSGI启动参数:
--socket 127.0.0.1:8081 --daemonize --enable-threads --threads 2 --processes 2
Run Code Online (Sandbox Code Playgroud)
我设置我的MongoClient ONE时间:
self.mongo_client = MongoClient('mongodb://user:pw@host.mongolab.com:port/mydb')
self.db = self.mongo_client['mydb']
Run Code Online (Sandbox Code Playgroud)
我尝试将一个JSON字典保存到MongoDB:
result = self.db.jobs.insert_one(job_dict)
Run Code Online (Sandbox Code Playgroud)
它通过单元测试工作,该测试执行与mongodb相同的代码路径.但是当我使用HTTP POST通过CherryPy和uWSGI执行时,我得到了这个:
pymongo.errors.ServerSelectionTimeoutError: No servers found yet
Run Code Online (Sandbox Code Playgroud)
为什么我在通过CherryPy和uWSGI运行时会看到这种行为?这可能是PyMongo 3中的新线程模型吗?
更新:
如果我通过使用CherryPy内置服务器运行没有uWSGI和nginx,那么就insert_one()
可以了.
更新1/25美国东部时间下午4:53:
在PyMongo中添加一些调试后,似乎topology._update_servers()
知道服务器'myserver-a.mongolab.com'的server_type = 2.但是server_description.known_servers()
服务器'myserver.mongolab.com'的server_type = 0
这导致以下堆栈跟踪:
result = self.db.jobs.insert_one(job_dict)
File "/usr/local/lib/python3.4/site-packages/pymongo/collection.py", line 466, in insert_one
with self._socket_for_writes() as sock_info:
File "/usr/local/lib/python3.4/contextlib.py", line 59, in __enter__
return next(self.gen)
File …
Run Code Online (Sandbox Code Playgroud) 我已经使用pip安装了uWSGI并使用XML启动它来加载我的应用程序.XML配置包含<plugin>python</plugin>
.在我的新服务器上,它会导致错误:
open("./python_plugin.so"): No such file or directory [core/utils.c line 3321]
!!! UNABLE to load uWSGI plugin: ./python_plugin.so: cannot open shared object file: No such file or directory !!!
Run Code Online (Sandbox Code Playgroud)
我可以找到.c
和.o
版本:
sudo find / -name 'python_plugin.c'
/srv/www/li/venv/build/uwsgi/build/uwsgi/plugins/python/python_plugin.c
/srv/www/li/venv/build/uwsgi/plugins/python/python_plugin.c
sudo find / -name 'python_plugin.o'
/srv/www/li/venv/build/uwsgi/build/uwsgi/plugins/python/python_plugin.o
/srv/www/li/venv/build/uwsgi/plugins/python/python_plugin.o
sudo find / -name 'python_plugin.so'
Run Code Online (Sandbox Code Playgroud)
但没有发现.我之前的系统通过apt-get进行了uwsgi安装,但这确实很旧(而且我很确定它通常使用pip安装的uwsgi,但是对于共享对象可能不行吗?)
一些背景信息:
pip install uwsgi
(没有sudo
)所以我有点无能为力:(我不能成为世界上唯一拥有此权利的人,对吧?我应该自己编译.so
对象吗?(如果是这样,怎么样?)或者还有另一个很好的解决方案吗?
我正在为Flask 寻找类似uWSGI + django autoreload模式的东西.
是否可以使用像PyCharm这样的ide来调试uwsgi应用程序?我可以通过直接从pycharm运行它们来调试基于flask的应用程序,但是甚至无法在pycharm中运行uwsgi应用程序.
我必须使用远程调试吗?是否可以使用run从pycharm中启动uwsgi应用程序?
我可以看到,如果我像这样启动uwsgi:
sudo /usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals --uid www --gid www
Run Code Online (Sandbox Code Playgroud)
它创造了一个皇帝副本.但是如果我--master
另外启动它(这里推荐),它会创建两个皇帝副本.是否有意义使用--master
与--emperor
?我会说不,但如果我在没有该选项的情况下运行它,我会收到此警告:
*** WARNING: you are running uWSGI without its master process manager ***
我正在努力小心并理解我的nginx配置中的每个设置.我见过一个配置示例,其中包含:
workers = 8
processes = 10
Run Code Online (Sandbox Code Playgroud)
但是uWSGI文档似乎没有区别.他们是同义词吗?如果是这样,这会导致此配置不正确吗?
uwsgi ×10
python ×4
flask ×3
nginx ×2
debugging ×1
mlab ×1
mongodb ×1
postgresql ×1
pycharm ×1
pymongo-3.x ×1
sqlalchemy ×1
supervisord ×1
werkzeug ×1
wsgi ×1