ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

docker nginx 和宿主机原生 nginx 服务的性能压测对比

docker nginx 和宿主机原生 nginx 服务的性能压测对比

1、通过 yum install -y nginx 安装的原生 nginx 1.20.1

➜  ~ service nginx restart
Redirecting to /bin/systemctl restart nginx.service
➜  ~ curl localhost
<!DOCTYPE html>
<html>
<head>
<title>HTTP Server Test Page</title>
<style>body {width: 35em;margin: 0 auto;font-family: Tahoma, Verdana, Arial, sans-serif;}
</style>
</head>
<body>
<h1>Welcome to HTTP Server Test Page!</h1>
<p>If you see this page, the httpd web server is successfully installed and
working. Further configuration is required.</p><p><em>Thank you for using apache httpd.</em></p>
</body>
</html>~ ab -n 50000 -c 1000 http://localhost/
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 5000 requests
Completed 10000 requests
Completed 15000 requests
Completed 20000 requests
Completed 25000 requests
Completed 30000 requests
Completed 35000 requests
Completed 40000 requests
Completed 45000 requests
Completed 50000 requests
Finished 50000 requestsServer Software:        nginx/1.20.1
Server Hostname:        localhost
Server Port:            80Document Path:          /
Document Length:        452 bytesConcurrency Level:      1000
Time taken for tests:   5.816 seconds
Complete requests:      50000
Failed requests:        0
Total transferred:      34250000 bytes
HTML transferred:       22600000 bytes
Requests per second:    8596.25 [#/sec] (mean)
Time per request:       116.330 [ms] (mean)
Time per request:       0.116 [ms] (mean, across all concurrent requests)
Transfer rate:          5750.42 [Kbytes/sec] receivedConnection Times (ms)min  mean[+/-sd] median   max
Connect:        0   46   7.2     46      71
Processing:    23   69  13.9     69     140
Waiting:        1   51  13.1     48     122
Total:         45  115  12.7    115     173Percentage of the requests served within a certain time (ms)50%    11566%    12075%    12380%    12590%    13395%    13898%    14399%    148100%    173 (longest request)

平均耗时 115ms

 

2、通过 docker pull nginx:1.20.1 安装的 docker run -d -p 80:80 nginx:1.20.1

➜  ~ docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED       STATUS       PORTS                               NAMES
3c91d5b22774   nginx:1.20.1   "/docker-entrypoint.…"   2 hours ago   Up 2 hours   0.0.0.0:80->80/tcp, :::80->80/tcp   upbeat_roentgen
➜  ~ curl localhost
<!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>~ ab -n 50000 -c 1000 http://localhost/
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 5000 requests
Completed 10000 requests
Completed 15000 requests
Completed 20000 requests
Completed 25000 requests
Completed 30000 requests
Completed 35000 requests
Completed 40000 requests
Completed 45000 requests
Completed 50000 requests
Finished 50000 requestsServer Software:        nginx/1.20.1
Server Hostname:        localhost
Server Port:            80Document Path:          /
Document Length:        612 bytesConcurrency Level:      1000
Time taken for tests:   15.255 seconds
Complete requests:      50000
Failed requests:        0
Total transferred:      42250000 bytes
HTML transferred:       30600000 bytes
Requests per second:    3277.64 [#/sec] (mean)
Time per request:       305.098 [ms] (mean)
Time per request:       0.305 [ms] (mean, across all concurrent requests)
Transfer rate:          2704.69 [Kbytes/sec] receivedConnection Times (ms)min  mean[+/-sd] median   max
Connect:        0   13  14.5      8      88
Processing:    57  290  59.9    285     565
Waiting:        1  281  59.8    277     562
Total:         57  303  56.9    297     582Percentage of the requests served within a certain time (ms)50%    29766%    32075%    33680%    34990%    37795%    40398%    44199%    468100%    582 (longest request)

平均耗时 303ms

 

返回列表