Skip to content

Instantly share code, notes, and snippets.

@travislee89
Created January 26, 2018 11:27
Show Gist options
  • Save travislee89/76e57bf013923eb9efe9f5cc6c5f9ce9 to your computer and use it in GitHub Desktop.
Save travislee89/76e57bf013923eb9efe9f5cc6c5f9ce9 to your computer and use it in GitHub Desktop.

测试环境

请先安装nginx和wrk
测试完后无需清理文件,重启后不留痕迹

创建配置文件

mkdir -p /dev/shm/html;

cat > /dev/shm/nginx.conf<<'_EOF_'
user                    nobody;
daemon                  on;
worker_processes        2;

error_log               /dev/shm/error.log;
pid                     /run/nginx-test.pid;

pcre_jit                on;
worker_rlimit_nofile    1048576;
worker_shutdown_timeout	10m;
thread_pool		        default threads=32 max_queue=100000;

events {
    use                  epoll;
    accept_mutex         on;
    worker_connections   10240;         # 512
}

http {
    log_format  default '$remote_addr $host $hostname $remote_user [$time_local] '
                        '"$request" $status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for" "$http_cookie"';
    access_log off;
    types {
        text/html html htm;
    }
    default_type text/html;
    sendfile on;
    open_file_cache max=100 inactive=60s;
    open_file_cache_valid 60s;
    open_file_cache_min_uses 1;
    tcp_nodelay on;
    gzip off;
    server {
        listen 32645;
        server_name _;
        root /dev/shm/html;
        index index.html;
        location = /hello { return 200 "hello world"; }
    }
}
_EOF_

cat > /dev/shm/html/index.html<<'_EOF_'
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
_EOF_

测试

启动nginx并测试访问正常

nginx -c /dev/shm/nginx.conf
curl -D- -o /dev/null -s localhost:32645/index.html
curl -D- -o /dev/null -s localhost:32645/hello

测试

wrk --latency -c 2048 -d 30 -t 2 http://127.0.0.1:32645/index.html

Running 30s test @ http://127.0.0.1:32645/index.html
2 threads and 2048 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 16.54ms 91.31ms 1.97s 96.19%
Req/Sec 35.86k 14.09k 81.79k 66.50%
Latency Distribution
50% 1.55ms
75% 2.86ms
90% 4.47ms
99% 406.41ms
2140722 requests in 30.08s, 1.69GB read
Socket errors: connect 1029, read 98, write 0, timeout 564
Requests/sec: 71172.27
Transfer/sec: 57.69MB

wrk --latency -c 1000 -d 30 -t 2 http://127.0.0.1:32645/hello

Running 30s test @ http://127.0.0.1:32645/hello
2 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 43.54ms 182.36ms 1.83s 94.93%
Req/Sec 83.45k 12.45k 128.69k 74.58%
Latency Distribution
50% 0.99ms
75% 1.75ms
90% 50.98ms
99% 1.12s
4975705 requests in 30.04s, 749.51MB read
Socket errors: connect 0, read 21, write 0, timeout 352
Requests/sec: 165662.55
Transfer/sec: 24.95MB

测试完退出nginx

nginx -c /dev/shm/nginx.conf -s quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment