如何优化NGINX以处理每分钟100K+请求(10万/min)

几天就回来我得到了一个任务来配置它可以处理每分钟10万的请求Ngnix Web服务器。要完成这个任务,我采取了Ubuntu系统有4个CPU和8GB内存,并开始配置如下所示。

1. 安装Nginx Web服务器

这是,如果在您的系统上没有安装Nginx,执行以下命令来安装nginx,可选步骤。 在Ubuntu / Debian/ Linuxmint 中安装
$ sudo apt-get install nginx
在CentOS / RHEL / Fedora 中安装
# yum install nginx

2. 调整Nginx的配置文件

现在编辑Nginx的配置 /etc/nginx/nginx.conf并改变以下值。在下面的配置仅改变参数显示。
worker_processes 8;  # no of cpu * 2
worker_rlimit_nofile 50000;

events {
        worker_connections 20000;
}
http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_requests 100;
        #keepalive_timeout 65;
        open_file_cache max=100;
        gzip   off;
        access_log off;
       types_hash_max_size 2048;
}

3. 重新启动的Nginx和测试负载

上述更改后,使用下面的命令重启Nginx服务。
# service nginx restart
现在,使用 Apache的基准测试负载工具。我已经上传了50kb服务器的文件,并通过10万次模拟点击它。
# ab -n 100000 -c 500 http://11.22.33.44/mypage.html
This is ApacheBench, Version 2.3 
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 11.22.33.44 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:        nginx/1.4.6
Server Hostname:        11.22.33.44
Server Port:            80

Document Path:          /mypage.html
Document Length:        53339 bytes

Concurrency Level:      500
Time taken for tests:   43.570 seconds
Complete requests:      100000
Failed requests:        0
Total transferred:      5358300000 bytes
HTML transferred:       5333900000 bytes
Requests per second:    2295.18 [#/sec] (mean)
Time per request:       217.848 [ms] (mean)
Time per request:       0.436 [ms] (mean, across all concurrent requests)
Transfer rate:          120100.12 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        4   84 275.9     18    7027
Processing:    39  132 124.1     90    3738
Waiting:        7   21  22.5     18    1598
Total:         50  216 308.0    109    7208

Percentage of the requests served within a certain time (ms)
  50%    109
  66%    127
  75%    158
  80%    180
  90%    373
  95%   1088
  98%   1140
  99%   1333
 100%   7208 (longest request)

按照上面的输出,你可以看到,100K点击量需要43.570秒由Nginx的服务完成。
赞(52) 打赏
未经允许不得转载:优客志 » 系统运维
分享到:

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏