@bergus
2017-01-05T10:31:27.000000Z
字数 4238
阅读 1971
优化
并发4个线程:
uwsgi -s :9090 -w myapp -p 4
主控制线程+4个线程:
uwsgi -s :9090 -w myapp -M -p 4
执行超过30秒的client直接放弃:
uwsgi -s :9090 -w myapp -M -p 4 -t 30
限制内存空间128M:
uwsgi -s :9090 -w myapp -M -p 4 -t 30 --limit-as 128
服务超过10000个req自动respawn:
uwsgi -s :9090 -w myapp -M -p 4 -t 30 --limit-as 128 -R 10000
后台运行等:
uwsgi -s :9090 -w myapp -M -p 4 -t 30 --limit-as 128 -R 10000 -d uwsgi.log
命令行参数 uwsgi将gevent做为模块uwsgi -s 127.0.0.1:8080 --processes 4 --loop gevent --enable-threads --async 128 --disable-logging --wsgi-file test.pyuwsgi将gevent内置uwsgi --http :8080 --file test.py --gevent 2000 -l 1000 -p 1 -L 参数解释
uwsgi将gevent做为模块
uwsgi -s 127.0.0.1:8080 --processes 4 --loop gevent --enable-threads --async 128 --disable-logging --wsgi-file test.py
如题谁有 uwsgi 的配置文件让我参考一下,我的配置老是出现 upstream prematurely closed connection while reading response header from upstream, client 这样的错误。 以下是我自己的配置: [uwsgi] #coding:utf-8
uwsgi 启动时所使用的地址与端口
socket = 127.0.0.1:8001
master = true
指向网站目录
chdir = /obj1/wechat/
profiler = true
enable-threads = true
logdate = true
memory-report=true
limit-as = 6048
daemnize = /obj1/wechat.log
python 启动程序文件
wsgi-file = manage.py
python 程序内用以启动的 application 变量名
callable = app
处理器数
processes = 4
线程数
threads = 2
#状态检测地址 stats = 127.0.0.1:9191
uwsgi_read_timeout = 600
harakiri = 1200
gevent = 100
./uwsgi -w tests.cpubound_green -s :3031 --async 30 --ugreen
./uwsgi -s :3031 -w simple_app --daemonize /tmp/mylog.log
./uwsgi -s :3031 -w simple_app --logto /tmp/mylog.log
# logto2 only opens the log file after privileges have been dropped to the specified uid/gid.
./uwsgi -s :3031 -w simple_app --uid 1001 --gid 1002 --logto2 /tmp/mylog.log
uwsgi --gevent 100 --gevent-monkey-patch --http :9090 -M --processes 4 --wsgi-file wsgi.py
%(uri) -> REQUEST_URI
%(method) -> REQUEST_METHOD
%(user) -> REMOTE_USER
%(addr) -> REMOTE_ADDR
%(host) -> HTTP_HOST
%(proto) -> SERVER_PROTOCOL
%(uagent) -> HTTP_USER_AGENT (starting from 1.4.5)
%(referer) -> HTTP_REFERER (starting from 1.4.5)
# report uwsgi配置
[uwsgi]
base = /opt/report/dimension_report
app = api.api_listener
module = %(app)
home = /opt/report/venv
pythonpath = %(base)
# processes = 16
workers=16
# lazy=True
socket = /opt/report/dimension_report/%n.sock
#socket = 127.0.0.1:1234
chmod-socket = 644
callable = app
logto = /var/log/uwsgi/%n.log
# report nginx 配置
user centos;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_disable "msie6";
server {
listen 80;
server_name localhost;
charset utf-8;
client_max_body_size 75M;
location / { try_files $uri @api_listener; }
location @api_listener {
include uwsgi_params;
uwsgi_pass unix:/opt/report/dimension_report/app_uwsgi.sock;
# uwsgi_pass 127.0.0.1:1234;
}
}
}
# report service uwsgi
[uwsgi]
base = /opt/services/services
app = api.service_rest_api
module = %(app)
home = /opt/services/venv
pythonpath = %(base)
# processes = 16
workers=12
enable-threads=true
# lazy=True
# socket = /opt/services/services/%n.sock
uwsgi-socket = 127.0.0.1:1122
uwsgi-socket = 127.0.0.1:1123
uwsgi-socket = 127.0.0.1:1124
uwsgi-socket = 127.0.0.1:1125
uwsgi-socket = 127.0.0.1:1126
uwsgi-socket = 127.0.0.1:1127
uwsgi-socket = 127.0.0.1:1128
uwsgi-socket = 127.0.0.1:1129
chmod-socket = 644
callable = app
logto = /var/log/uwsgi/%n.log
# report service nginx
user centos;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_disable "msie6";
upstream uwsgicluster {
server 127.0.0.1:1122;
server 127.0.0.1:1123;
server 127.0.0.1:1124;
server 127.0.0.1:1125;
server 127.0.0.1:1126;
server 127.0.0.1:1127;
server 127.0.0.1:1128;
server 127.0.0.1:1129;
}
server {
listen 80;
server_name localhost;
charset utf-8;
client_max_body_size 75M;
location / { try_files $uri @api_listener; }
location @api_listener {
include uwsgi_params;
# uwsgi_pass unix:/opt/services/services/app_uwsgi.sock;
uwsgi_pass uwsgicluster;
}
}
}
快速部署Python应用:Nginx+uWSGI配置详解
nginx+uwsgi+flask配置记录
Managing the uWSGI server
在 Linux 下生成高强度密码的四种方法