在 4 核机器上,哪种情况可以进行更好的设置:
4 个 uWSGI 进程,具有深度队列来处理请求
8 个带有深队列的 uWSGI 进程
服务器内存允许的进程数量与相对较浅的队列一样多?
我使用本指南进行了设置,它为我的 django 应用程序服务了一段时间,但是在添加新的 django 模块后,没有触及任何 nginx 或 uwsgi 配置,现在服务器导致 502 502 Bad Gateway 错误。nginx error.log 说:
*1 上游在从上游读取响应头时提前关闭连接,客户端:xxxx,服务器:blabla.com,请求:“GET / HTTP/1.1”,上游:“uwsgi://127.0.0.1:4000”,主机:“ xxx"
我很欣赏你的提示来解决这个问题。
我正在通过 uwsgi 使用 nginx 运行 django 站点。问题是当流量变大时,uwsgi 进程会占用大量 CPU 时间。相同的配置在测试服务器上运行良好,并且 siege/ab 模拟大量并发流量。
这是 uwsgi 进程的一份 strace 日志。http://dl.dropbox.com/u/43017476/strace.log
还有一些 sysctl:
fs.file-max = 128000
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
net.core.netdev_max_backlog = 4096
net.ipv4.tcp_max_syn_backlog = 4096
net.core.somaxconn = 250000
net.ipv4.tcp_keepalive_time = 300
Run Code Online (Sandbox Code Playgroud)
nginx conf 与 Google 的其他教程非常相似。我一直在试图弄清楚但没有运气。不过我发现了很多这样的作品:
22:12:02.932276 read(8, "\7\0\0\2\0\0\0\2\0\0\0", 16384) = 11
22:12:02.932504 poll([{fd=8, events=POLLIN|POLLPRI}], 1, 0) = 0 (Timeout)
22:12:02.932547 write(8, "\17\0\0\0\3SET NAMES utf8", 19) = 19
22:12:02.932643 read(8, …Run Code Online (Sandbox Code Playgroud) 我正在运行一个接收很少流量的数据库支持的网站。但是,一天一两次,请求会超时,我会在 Nginx 中看到这个(或类似的)错误error.log:
2013/06/13 18:32:40 [error] 16723#0: *27796 upstream timed out (110: Connection timed out)
while reading response header from upstream, client: 199.71.215.214, server:
app.mypythonwebapp.com, request: "POST /api?submit_staker_response HTTP/1.1", upstream:
"uwsgi://unix:/var/run/uwsgi/app.mypythonwebapp.com-uwsgi.sock", host:
"app.mypythonwebapp.com", referrer:
"https://app.mypythonwebapp.com/survey/5/791/70ea73eb9a489f2dead804a95c400ab2"
Run Code Online (Sandbox Code Playgroud)
我正在运行 uWSGI 并且在它的日志文件中根本没有任何与此相关的内容(我可以说)。我怀疑它可能与 PostgreSQL 相关,但如果我通过检查它的状态,pg_stat_activity我看不到任何异常。
这是我的 uWSGI YAML 配置文件:
uwsgi:
socket: /var/run/uwsgi/%n-uwsgi.sock
workers: 5
buffer-size: 32768
callable: app
wsgi-file: /opt/sites/app.mypythonwebapp.com/run.py
virtualenv: /opt/virtualenv/app.mypythonwebapp.com
pythonpath: /opt/sites/app.mypythonwebapp.com
Run Code Online (Sandbox Code Playgroud)
我所在的服务器有两个(虚拟化)内核,所以我做了 1 + cores*2 来确定工作人员的数量。我还提高了buffer-size参数以尝试解决此问题,但错误仍然发生。
我不确定从哪里开始调试。我几乎没有运行 uWSGI(或任何 Python WSGI 实现)的经验。
我有一个使用基于 nginx、uWSGI 和 Django 构建的 API 的 web 应用程序。最近我在一个特定的 API 调用中看到了很多 harakiris,它执行一些快速处理,然后产生一些线程来处理一些长时间运行的函数。然后主线程返回,工作线程将结果存储在缓存中并退出。线程生成后,它们之间没有交互。
我的 uWSGI 设置为 20 秒的 harakiri。这应该是主线程完成并返回的充足时间(平均约为 2-3 秒)。uWSGI 是否有可能是 harakiri-ing 因为我的工作线程需要太长时间才能返回?如果是这样,我可以通过在 python 中使用多处理而不是多线程来解决这个问题吗?
谢谢!
即使我按照官方说明进行操作,当我使用 uWSGI 启动 Django 测试站点时,也不会加载管理界面的 CSS 文件。例如http://localhost:8443/static/admin/css/base.css,如果我打开 CSS 文件的 URL,则会收到 404 错误。我搜索了本地文件,我猜它的路径是/usr/local/lib/python3.3/dist-packages/django/contrib/admin/static/admin/css/base.css; 所以我也尝试以 root 身份运行 uwsgi,但没有任何改变。
我使用没有问题python3 manage.py runserver。如果我打开http://localhost:8000/static/admin/css/base.css,文件将加载到浏览器中,并将样式应用于管理页面。
这是我在 bash 中执行的命令:
uwsgi --ini ~/.uwsgi/conf/django.ini --set-placeholder project_name=mysite --set-placeholder port=8443
Run Code Online (Sandbox Code Playgroud)
这是 django.ini 的内容:
[uwsgi]
module = %(project_name).wsgi:application
https = :%(port),/usr/local/nginx/conf/server.crt,/usr/local/nginx/conf/server.key,HIGH
strict = true
chdir = /home/marco/django-projects/%(project_name)
env = DJANGO_SETTINGS_MODULE=%(project_name).settings
socket = /home/marco/.uwsgi/%(project_name).socket
pidfile = /home/marco/.uwsgi/%(project_name).pid
daemonize = /home/marco/.uwsgi/%(project_name).log
master = true
enable-threads = true
harakiri = 20
max-requests = 5000
vacuum …Run Code Online (Sandbox Code Playgroud) 我使用 nginx 作为几个 Flask 应用程序的代理,使用 uwsgi 作为中间件。这是我的测试应用程序的 nginx 配置。
server {
listen 80;
server_name test.myapp.com www.test.myapp.com;
charset utf-8;
client_max_body_size 250M;
location / { try_files $uri @testapp; }
location @testapp {
include uwsgi_params;
uwsgi_pass unix:/tmp/testapp_uwsgi.sock;
}
location /forecaster/components/ {
alias /opt/test/client/app/components/;
}
Run Code Online (Sandbox Code Playgroud)
}
Run Code Online (Sandbox Code Playgroud)
我很确定 nginx 实际上并没有为静态文件提供服务,即使我注释掉了该location块,文件也是从某些东西中获取的。我在 nginx 日志中看到了 200 个,在 uWsgi 日志中也看到了 200 个。你怎么知道哪个是服务静态文件的?我想烧瓶应用程序也可以为他们服务?
/opt/test/client/app/components/ 肯定存在,并且对其他人可读。有什么方法可以强制 uwsgi 不处理这些请求?
我在新的 DigitalOcean Droplet 上运行我的应用程序时遇到问题。本机运行 CentOS 6.5
我的 /etc/nginx/nginx.conf
user nginx www-data;
worker_processes 1;
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
(continues)
Run Code Online (Sandbox Code Playgroud)
我的 myapp_nginx.conf
server {
server_name 104.xxx.x.xxx;
listen 8080;
charset utf-8;
client_max_body_size 30M;
location / {
index index.html index.htm;
root /home/webdev/mydevelopment/git/ers_portal;
try_files $uri @app;
}
location /static {
alias /home/webdev/mydevelopment/git/ers_portal/app/static;
}
location @app {
include uwsgi_params;
uwsgi_pass unix:/home/webdev/mydevelopment/git/ers_portal_uwsgi.sock;
}
}
Run Code Online (Sandbox Code Playgroud)
我的 myapp_uwsgi.ini
[uwsgi]
master = true
#user info
uid = webdev
gid = www-data
#application's base folder …Run Code Online (Sandbox Code Playgroud) 我将从我的用例开始,因为我很可能没有使用正确的工具来完成这项工作。如果我以错误的方式处理这件事,请告诉我
用例:我有一个 CentOS 服务器托管多个 Web 应用程序。我希望能够相信我的 Web 服务器和应用程序服务器将运行。我的堆栈看起来像
我想用supervisord来监控nginx和uWSGI。在我的 /etc/supervisor.conf 中,我有
[program:nginxgo]
command = /usr/sbin/nginx
autostart=true
autorestart=unexpected
exitcodes=0
stdout_logfile=/home/webdev/nginxgo.log
stderr_logfile=/home/webdev/nginxgoerr.log
[program:uwsgi_emperor_go]
command = uwsgi --emperor /etc/uwsgi/emperor.ini
autostart=true
autorestart=unexpected
stopsignal=INT
stdout_logfile=/home/webdev/emp.log
stderr_logfile=/home/webdev/emperr.log
directory=/home/webdev/
user=webdev
Run Code Online (Sandbox Code Playgroud)
我启动了 uWSGI 进程。当我进入[root@mymachine]# /usr/local/bin/supervisord -n -c /etc/supervisord.conf
输出是
2014-11-26 14:07:56,917 CRIT Supervisor running as root (no user in config file)
2014-11-26 14:07:56,951 CRIT Server 'inet_http_server' running without any HTTP authentication checking
2014-11-26 14:07:56,952 INFO supervisord started with pid 31068
2014-11-26 14:07:57,957 …Run Code Online (Sandbox Code Playgroud) 我收到一个错误:ImportError: No module named site根据我的 uWSGI 日志。
test_proj.ini:
[uwsgi]
chdir = /home/%n/app
module = %n.wsgi
home = /home/%n/app/venv
master = true
processes = 10
chmod-socket = 664
socket = /home/%n/uwsgi/socket
daemonize = /home/%n/uwsgi/log
pidfile = /home/%n/uwsgi/pid
Run Code Online (Sandbox Code Playgroud)
nginx:
server {
listen 8888;
server_name 192.168.88.187;
# Set up django static file serving
location /static {
alias /home/test_proj/app/static/;
}
# pass all non-static request to uWSGI
location / {
uwsgi_pass unix:///home/test_proj/uwsgi/socket;
include uwsgi_params;
}
}
Run Code Online (Sandbox Code Playgroud)
点冻结:
Django==1.7.1
django-braces==1.4.0
django-cors-headers==0.13
django-dynamic-settings==1.1.0
django-oauth-toolkit==0.7.2 …Run Code Online (Sandbox Code Playgroud)