nginx通用优化以及ab测试

通用优化

修改/etc/nginx/nginx.conf

user  nginx;
worker_processes  16;  // 调至CPU核心数

worker_cpu_affinity auto;  //一个work分配一个CPU,需要配合上面worker_processes


error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

work_rlimit_nofile 35535;  //nginx进程文件句柄,建议调整到1万以上

events {
    use epoll;    // 采用epoll 方式
    worker_connections  10240;   //每个worker能处理的最大连接数
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    charset utf-8;    // 设置字符集

    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;

    keepalive_timeout  65;

    gzip  on;   //打开压缩
    gzip_disable "MSIE [1-6]\.";    //IE有些不支持
    gzip_http_version 1.1;
    

    include /etc/nginx/conf.d/*.conf;
}

ab 测试

docker run -d -P nginx
$ yum install httpd-tools
$ ab -n 2000 -c 2 http://172.17.0.2:80/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.17.0.2 (be patient)
Completed 200 requests
Completed 400 requests
Completed 600 requests
Completed 800 requests
Completed 1000 requests
Completed 1200 requests
Completed 1400 requests
Completed 1600 requests
Completed 1800 requests
Completed 2000 requests
Finished 2000 requests


Server Software:        nginx/1.17.2
Server Hostname:        172.17.0.2
Server Port:            80

Document Path:          /
Document Length:        612 bytes

Concurrency Level:      2
Time taken for tests:   0.261 seconds
Complete requests:      2000
Failed requests:        0
Write errors:           0
Total transferred:      1690000 bytes
HTML transferred:       1224000 bytes
Requests per second:    7652.51 [#/sec] (mean)
Time per request:       0.261 [ms] (mean)                                     // 一个请求的平均时间,包括网络传输
Time per request:       0.131 [ms] (mean, across all concurrent requests)     //一个请求的服务起响应时间
Transfer rate:          6314.82 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     0    0   0.1      0       3
Waiting:        0    0   0.1      0       2
Total:          0    0   0.2      0       3

Percentage of the requests served within a certain time (ms)
  50%      0
  66%      0
  75%      0
  80%      0
  90%      0
  95%      0
  98%      1
  99%      1
 100%      3 (longest request)   //解释:100%的请求在3ms内返回

参数解释
ab -n 2000 -c 2 http://172.17.0.2:80/

  • -n 总的请求数
  • -c 并发数
  • -k 是否开启长连接
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值