在尝试对我的烧瓶应用程序进行基准测试时,我遇到了 Nginx + uWSGI + 烧瓶的一些问题。正如我的测试所显示的那样,这种组合非常缓慢。我在具有 4 个内核和 4 GB RAM 的 Ubuntu 12.04 VM 上全新安装了 Nginx 1.1.19 和 uWSGI 2.0。(下面的 Nginx 和 uWSGI 配置)
我自己做了一个 Nginx 基准测试,它自己提供一个静态的 20 字节文件,我能够获得高达 80k req/sec 的速度。然后我做了一个 Nginx + uWSGI + 一个非常基本的烧瓶应用程序(烧瓶网站上的 Hello world 示例)的基准测试,我最多只能获得 8k 请求/秒(减少 10 倍)
我打开了登录 Nginx 和 uWSGI(加上统计套接字)并格式化日志以打印两者的请求处理时间,这是我能够收集到的:
uWSGI 平均 请求时间 = 0毫秒
Nginx 平均。req time = 125ms(Nginx 日志时间包括在 uWSGI 中花费的时间)
我对我的烧瓶应用程序进行了相同的测试,结果遵循相同的模式
uWSGI 平均 请求时间 = 4 毫秒
Nginx 平均。请求时间 = 815ms
问题: Nginx 和 uWSGI 之间的通信似乎花费了大量时间。有人见过这个问题吗???我已经为 Nginx 和 uWSGI 尝试了各种配置,结果都一样。
请注意,我使用 apachebench (ab) 在 VM 本地和远程机器上进行了测试,结果相同。
Nginx 配置文件
user www-data;
worker_processes 4;
worker_rlimit_nofile 200000;
pid /var/run/nginx.pid;
events {
worker_connections 10240;
#multi_accept on;
#use epoll;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 10;
types_hash_max_size 2048;
client_body_timeout 10;
send_timeout 2;
gzip on;
gzip_disable "msie6";
keepalive_disable "msie6";
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log off;
error_log /var/log/nginx/error.log crit;
log_format ugzip '$remote_addr - "$request" - $status $body_bytes_sent - [$request_time]';
##
# Virtual Host Configs
##
#include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server {
listen 80;
server_name localhost;
access_log /var/log/nginx-access.log ugzip buffer=32k;
error_log /var/log/nginx-error.log;
location /myapplication {
uwsgi_pass unix:/tmp/bdds.sock;
include uwsgi_params;
uwsgi_param UWSGI_SCHEME $scheme;
}
}
}
uWSGI conf(相关部分)
[uwsgi]
master = true
listen = 40000
chmod-socket = 666
socket = /tmp/bdds.sock
workers = 8
harakiri = 60
harakiri-verbose = true
reload-mercy = 8
logto = /var/log/uwsgi-app.log
logformat = %(proto) %(method) %(uri) - %(status) %(rsize) - [%(msecs)]
vacuum = true
no-orphans = true
#cpu-affinity = 1
stats = /tmp/stats.sock
这是 Nginx + uWSGI 的常见行为吗?我的配置有什么明显不正确的地方吗?我在带有 Ubuntu 12.04 的 4 核/4 GB RAM Xen VM 上运行它。
提前致谢。