如何在我的networking服务器上实现每秒500K的请求?

我最近给自己一个新的专用服务器,我试图挤出最大的性能,为了好玩和学习。

我正在尝试实现这个服务器每秒钟可能处理的最大请求数,并且在这里提到500K请求/秒 – http://lowlatencyweb.wordpress.com/2012/03/20/500000-requestssec-modern-http-servers -are快速/

服务器细节

英特尔®至强®E3-1270 4核(8 HT)x 3.4 GHz

内存24 GB DDR3 ECC

硬盘空间2,000 GB(2 x 2,000 SATA)RAID软件RAID 1

蓝100mbps

OS Centos 6.3 64位

Nginx的

我能够达到只有35K请求/秒的静态TXT文件。 我正在同一台机器上运行基准testing。 我知道网卡的限制和networking开销

ab -n100000 -c200 http://localhost/test.txt 

更新 – 165K请求/秒

我尝试了另一个称为wrk的基准testing工具,它给了我165K个请求/秒。 非常酷!

更新2 – 250K请求/秒

nginx.conf

 ####################################################################### # # This is the main Nginx configuration file. # # More information about the configuration options is available on # * the English wiki - http://wiki.nginx.org/Main # * the Russian documentation - http://sysoev.ru/nginx/ # ####################################################################### #---------------------------------------------------------------------- # Main Module - directives that cover basic functionality # # http://wiki.nginx.org/NginxHttpMainModule # #---------------------------------------------------------------------- user nginx; worker_processes 8; worker_rlimit_nofile 262144; 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; #---------------------------------------------------------------------- # Events Module # # http://wiki.nginx.org/NginxHttpEventsModule # #---------------------------------------------------------------------- events { worker_connections 16384; multi_accept on; use epoll; } #---------------------------------------------------------------------- # HTTP Core Module # # http://wiki.nginx.org/NginxHttpCoreModule # #---------------------------------------------------------------------- http { include /etc/nginx/mime.types; index index.php index.html index.htm; 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 /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; server_tokens off; client_max_body_size 24m; client_body_buffer_size 128k; #keepalive_timeout 0; keepalive_timeout 65; open_file_cache max=1000; open_file_cache_min_uses 10; open_file_cache_errors on; gzip on; gzip_static on; gzip_comp_level 3; gzip_disable "MSIE [1-6]\."; gzip_http_version 1.1; gzip_vary on; gzip_proxied any; gzip_types text/plain text/css text/xml text/javascript text/x-component text/cache-manifest application/json application/javascript application/x-javascript application/xml application/rss+xml application/xml+rss application/xhtml+xml application/atom+xml application/wlwmanifest+xml application/x-font-ttf image/svg+xml image/x-icon font/opentype app/vnd.ms-fontobject; gzip_min_length 1000; fastcgi_cache_path /tmp levels=1:2 keys_zone=NAME:10m inactive=5m; fastcgi_cache_key "$scheme$request_method$host$request_uri"; server { listen 80; server_name _; root /var/www/html; #charset koi8-r; #access_log logs/host.access.log main; location / { try_files $uri $uri/ /index.php?$args; } error_page 404 /404.html; location = /404.html { root /var/www/error; } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/error; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; # checks to see if the visitor is logged in, a commenter, # or some other user who should bypass cache set $nocache ""; if ($http_cookie ~ (comment_author_.*|wordpress_logged_in.*|wp-postpass_.*)) { set $nocache "Y"; } # bypass cache if logged in. # Be sure that this is above all other fastcgi_cache directives fastcgi_no_cache $nocache; fastcgi_cache_bypass $nocache; fastcgi_cache NAME; fastcgi_cache_valid 200 302 10m; fastcgi_cache_valid 301 1h; fastcgi_cache_valid any 1m; fastcgi_cache_min_uses 10; fastcgi_cache_use_stale error timeout invalid_header http_500; fastcgi_buffers 256 16k; } location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). location ~ /\. { deny all; access_log off; log_not_found off; } # Deny access to any files with a .php extension in the uploads directory location ~* ^/wp-content/uploads/.*.php$ { deny all; access_log off; log_not_found off; } location ~* \.(jpg|jpeg|gif|png|flv|mp3|mpg|mpeg|js|css|ico)$ { expires max; log_not_found off; } } } 

首先,你应该写一个新的基准testing工具。 你实际上是基准不是nginx

Arpit,如果你认为即使是一个静态的文本文件是一个以太网数据包(〜1,500字节),那么其中的50万个可以在7.5亿个字节左右,或者大约7.5亿个字节的范围内工作。 所以除非你的服务器有非常容易卸载的10Gb网卡(它不是那么容易,你得到的是一百倍慢),并且设置了驱动程序和内核,让你几乎完全淹没其中一个链接,再加上负载平衡器,防火墙,路由器以及速率的延迟,那么您将永远无法达到这种性能 – 即使是单个数据包响应,这也不太可能。 所以最终35K听起来不是很远。

让我们找出瓶颈。 既然你在同一台机器上,我们可以假设它是CPU或磁盘活动。 对于一个文本文件,它不应该是磁盘活动,但在35k连接,你可能会产生每秒35MB的logging。

您显示的示例不运行访问日志logging,只有错误。 然而,你的configuration有更多的事情,特别是日志logging:

 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 /var/log/nginx/access.log main; 

从禁用该日志logging开始,然后找出下一个挂起的位置。 还要考虑在同一台机器上运行testing客户端可能会对服务器守护进程产生显着的影响。 Hypertheading也可能会使你变得有害,所以在开启或closures的时候,探索一下你的负载能否更好地工作。

如果你只是在数字之后(例如,这个testing没有真正的用例),请使用http的保持活动特性 – 通过已经打开的TCP连接执行请求数。