mbi*_*ras 5 nginx haproxy ab apache-2.2
我正在尝试使用ab4 个运行的 ubuntu 机器集群进行基准测试nginx,这些机器由另一个正在运行的 ubuntu 机器负载平衡haproxy。对于那些感兴趣的人,我正在关注sysadmincasts教程系列。我无法从运行 osx 的笔记本电脑上成功地对集群进行基准测试:
? ~ uname -a
Darwin mbp 15.6.0 Darwin Kernel Version 15.6.0: Mon Aug 29 20:21:34 PDT 2016; root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64
? ~ system_profiler SPSoftwareDataType
Software:
System Software Overview:
System Version: OS X 10.11.6 (15G1004)
Kernel Version: Darwin 15.6.0
Boot Volume: Untitled
Boot Mode: Normal
Computer Name: Max’s MacBook Pro
User Name: Max Bigras (max)
Secure Virtual Memory: Enabled
System Integrity Protection: Disabled
Time since boot: 4 days 6:27
? ~ ab -n 10000 -c 25 http://127.0.0.1:8080/
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
apr_socket_recv: Connection reset by peer (54)
Run Code Online (Sandbox Code Playgroud)
我发现另一篇文章提到了osx 中套接字限制问题的可能性。但是,当我尝试提到的解决方案时,它仍然不起作用:
? ~ sysctl kern.maxfiles
kern.maxfiles: 1048600
? ~ ulimit -S -n
1048576
? ~ ab -n 10000 -c 25 http://127.0.0.1:8080/
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
apr_socket_recv: Connection reset by peer (54)
Total of 25 requests completed
Run Code Online (Sandbox Code Playgroud)
我知道我至少会访问我的服务器,因为我检查了正在运行的 Web 节点之一的日志文件 nginx
SSH 到 web1(运行 nginx 的 ubuntu 机器):
vagrant@web1:~$ echo $USER
vagrant
vagrant@web1:~$ sudo tail -f /var/log/nginx/access.log
10.0.15.11 - - [02/Oct/2016:06:53:25 +0000] "GET / HTTP/1.0" 200 632 "-" "ApacheBench/2.3"
10.0.15.11 - - [02/Oct/2016:06:53:25 +0000] "GET / HTTP/1.0" 200 632 "-" "ApacheBench/2.3"
10.0.15.11 - - [02/Oct/2016:06:53:25 +0000] "GET / HTTP/1.0" 200 632 "-" "ApacheBench/2.3"
10.0.15.11 - - [02/Oct/2016:06:53:25 +0000] "GET / HTTP/1.0" 200 632 "-" "ApacheBench/2.3"
10.0.15.11 - - [02/Oct/2016:06:53:25 +0000] "GET / HTTP/1.0" 200 632 "-" "ApacheBench/2.3"
10.0.15.11 - - [02/Oct/2016:06:53:25 +0000] "GET / HTTP/1.0" 200 632 "-" "ApacheBench/2.3"
10.0.15.11 - - [02/Oct/2016:06:53:25 +0000] "GET / HTTP/1.0" 200 632 "-" "ApacheBench/2.3"
10.0.15.11 - - [02/Oct/2016:06:53:25 +0000] "GET / HTTP/1.0" 200 632 "-" "ApacheBench/2.3"
10.0.15.11 - - [02/Oct/2016:06:53:25 +0000] "GET / HTTP/1.0" 200 632 "-" "ApacheBench/2.3"
10.0.15.11 - - [02/Oct/2016:06:53:25 +0000] "GET / HTTP/1.0" 200 632 "-" "ApacheBench/2.3"
10.0.15.11 - - [02/Oct/2016:06:54:59 +0000] "GET / HTTP/1.0" 200 632 "-" "ApacheBench/2.3"
10.0.15.11 - - [02/Oct/2016:06:54:59 +0000] "GET / HTTP/1.0" 200 632 "-" "ApacheBench/2.3"
10.0.15.11 - - [02/Oct/2016:06:54:59 +0000] "GET / HTTP/1.0" 200 632 "-" "ApacheBench/2.3"
10.0.15.11 - - [02/Oct/2016:06:54:59 +0000] "GET / HTTP/1.0" 200 632 "-" "ApacheBench/2.3"
10.0.15.11 - - [02/Oct/2016:06:54:59 +0000] "GET / HTTP/1.0" 200 632 "-" "ApacheBench/2.3"
10.0.15.11 - - [02/Oct/2016:06:54:59 +0000] "GET / HTTP/1.0" 200 632 "-" "ApacheBench/2.3"
10.0.15.11 - - [02/Oct/2016:06:54:59 +0000] "GET / HTTP/1.0" 200 632 "-" "ApacheBench/2.3"
10.0.15.11 - - [02/Oct/2016:06:54:59 +0000] "GET / HTTP/1.0" 200 632 "-" "ApacheBench/2.3"
10.0.15.11 - - [02/Oct/2016:06:55:09 +0000] "GET / HTTP/1.1" 200 632 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36"
Run Code Online (Sandbox Code Playgroud)
ab在 osx 上重试:
? ~ echo $USER
max
? ~ date
Sat Oct 1 23:54:54 PDT 2016
? ~ ab -n 10000 -c 25 http://127.0.0.1:8080/
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
apr_socket_recv: Connection reset by peer (54)
Total of 41 requests completed
? ~ date
Sat Oct 1 23:55:02 PDT 2016
? ~
Run Code Online (Sandbox Code Playgroud)
在上面你可以看到,除了尝试对集群进行基准测试之外,我还用我的浏览器点击了它,如/var/log/nginx/access.log. 看起来问题肯定是我可以提出的请求数量有限制。如果我降低请求数量和并发值,那么它可以工作:
? ~ ab -n 100 -c 1 http://127.0.0.1:8080/
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient).....done
Server Software: nginx
Server Hostname: 127.0.0.1
Server Port: 8080
Document Path: /
Document Length: 632 bytes
Concurrency Level: 1
Time taken for tests: 0.218 seconds
Complete requests: 100
Failed requests: 0
Total transferred: 83800 bytes
HTML transferred: 63200 bytes
Requests per second: 458.17 [#/sec] (mean)
Time per request: 2.183 [ms] (mean)
Time per request: 2.183 [ms] (mean, across all concurrent requests)
Transfer rate: 374.95 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.3 0 2
Processing: 1 2 0.8 2 5
Waiting: 1 2 0.7 1 5
Total: 1 2 0.9 2 6
WARNING: The median and mean for the waiting time are not within a normal deviation
These results are probably not that reliable.
Percentage of the requests served within a certain time (ms)
50% 2
66% 2
75% 2
80% 2
90% 3
95% 4
98% 6
99% 6
100% 6 (longest request)
Run Code Online (Sandbox Code Playgroud)
那么如何配置 osx 以便我可以使用 25 个并发测试 10000 个请求ab?
编辑:添加 nginx.conf
vagrant@web1:~$ cat /etc/nginx/nginx.conf
# Ansible managed: /home/vagrant/templates/nginx.conf.j2 modified on 2016-09-11 14:17:19 by vagrant on mgmt
user www-data;
worker_processes 1;
pid /var/run/nginx.pid;
worker_rlimit_nofile 1024;
events {
worker_connections 512;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
tcp_nopush "on";
tcp_nodelay "on";
#keepalive_timeout "65";
access_log "/var/log/nginx/access.log";
error_log "/var/log/nginx/error.log";
server_tokens off;
types_hash_max_size 2048;
# https://philio.me/backend-server-host-name-as-a-custom-header-with-nginx/
add_header X-Backend-Server $hostname;
# disable cache used for testing
add_header Cache-Control private;
add_header Last-Modified "";
sendfile off;
expires off;
etag off;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Run Code Online (Sandbox Code Playgroud)
该Connection reset by peer错误意味着您的网络服务器在响应您的请求之前关闭了连接。因此,负载对于您的服务器来说太大,并且开始断开连接。
您需要研究您的服务器设置以了解为什么会发生这种情况。研究你的日志文件。
由于您的客户端,不会发生此错误。
| 归档时间: |
|
| 查看次数: |
12657 次 |
| 最近记录: |