-
-
Save rainly/08e6798f9e89bb5d385392eb9e54a8cf to your computer and use it in GitHub Desktop.
test long-poll server, test hight concurrency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ===========================================httperf=========================== | |
| apache bench常碰到"apr_poll: The timeout specified has expired (70007) ", | |
| 测试行业里常用httperf+autobench(有bench2graph生成性能图表): | |
| (共10000连接,每秒10000个连接,每连接1个请求(就没必要分bursts来发了,即connection-oriented或request-oriented workload下--burst-length是在connection之内pipeline)): | |
| httperf --hog --num-conns 10000 --rate 10000 --num-calls=1 --timeout 20 --server 127.0.0.1 --port 8888 --uri / | |
| 等同(共1次会话,每秒1次会话,每次会话10000请求,分若干bursts,每bursts含10000个请求,每bursts间隔1秒,每连接最多1请求,最大连接数10000, | |
| max-connections大于4需要修改httperf/src/gen/session.c为#define MAX_CONN 65536,即session-oriented workload下--burst-length肯能是一个connection内pipeline也可能跨connection): | |
| httperf --hog --wsess=1,10000,1 --rate 1 --burst-length=10000 --max-piped-calls 1 --max-connections=10000 --timeout 20 --server 127.0.0.1 --port 8888 --uri / | |
| #发出超过3000个并行连接PC还是会报"*** buffer overflow detected ***: httperf terminated",不知怎么解决 | |
| #"--hog" means to use all available ports to create connection | |
| (需要修改/usr/include/i386-linux-gnu/bits/typesizes.h和/usr/include/linux/posix_types.h里的#define __FD_SETSIZE 1024为65536 后编译httperf: | |
| sudo apt-get install build-essential | |
| sudo apt-get install libevent-dev | |
| wget http://httperf.googlecode.com/files/httperf-0.9.0.tar.gz ###(1)### | |
| tar -xzf httperf-0.9.0.tar.gz | |
| cd httperf | |
| autoreconf -i #add "ACLOCAL_AMFLAGS = -I m4" into Makefile.am, add "AC_CONFIG_MACRO_DIR([m4])" into configure.ac | |
| mkdir build | |
| cd build | |
| ../configure | |
| make | |
| sudo make install | |
| #verify max open files: | |
| httperf -v | grep open | |
| ) | |
| 发出连接数超过1024的话要改配置:echo -ne " | |
| * soft nofile 65536 | |
| * hard nofile 65536 | |
| " >>/etc/security/limits.conf | |
| And add something like this to /etc/profile and it should apply system wide to all accounts: | |
| ulimit -n 65536 ###(2)### | |
| However in order for tools such as ssh and su to obey the limits.conf file you need to add the following to the corresponding pam.d files if it's not yet there, | |
| i.e. for su add to /etc/pam.d/su and for ssh add to /etc/pam.d/sshd: | |
| session required /lib/security/pam_limits.so | |
| 并重启系统或用sudo -i -u malcolm立即生效 | |
| 另外超时连接关闭会积累大量TIME_WAIT状态(需等/proc/sys/net/ipv4/tcp_fin_timeout一般60秒才会自动清理),导致无法发起新的连接, | |
| 可以sudo echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse 解决 ###(3)### | |
| 持久化配置sudo echo 'net.ipv4.tcp_tw_reuse = 1' >> /etc/sysctl.conf 立即生效:sudo /sbin/sysctl -p #参考:http://pesen.blog.51cto.com/4575807/1137946 | |
| 而服务器端: sudo echo 'net.core.netdev_max_backlog = 262144' >> /etc/sysctl.conf | |
| 因为端口数有限,从单个客户端ip测试连接服务器确定ip和端口最多28232个并发连接: | |
| 客户端向同一个TCP端点(ip:port)发起主动连接, 每一条连接都必须使用不同的本地TCP端点, | |
| 如果客户端只有一个IP则是使用不同的本地端口,该端口的范围在*nix系统上的一个例子是32768到61000, | |
| 可以通过如下命令查看: | |
| # cat /proc/sys/net/ipv4/ip_local_port_range | |
| 32768 61000 | |
| 也就是说, 一个客户端连接同一个服务器的同一个ip:port(比如进行压力测试), 最多可以发起28232个左右的连接. | |
| TCP客户端(TCP的主动发起者)可以在同一ip:port上向不同的服务器发起主动连接, 只需在bind之前对socket设置SO_REUSEADDR选项. | |
| 系统支持的最大打开文件描述符数(包括socket连接): | |
| # cat /proc/sys/fs/file-max | |
| 203758 | |
| 单个进程所能打开的最大文件描述符数(上段修改/etc/security/limits.conf): | |
| # ulimit -Hn | |
| 4096 | |
| # ulimit -Sn | |
| 1024 | |
| 每个连接占用内存,修改: | |
| /proc/sys/net/ipv4/tcp_wmem | |
| /proc/sys/net/ipv4/tcp_rmem | |
| ===========================================weighttp=========================== | |
| 安装: | |
| sudo apt-get install libev4 libev-dev | |
| wget http://cgit.lighttpd.net/weighttp.git/snapshot/weighttp-master.tar.gz | |
| tar -xzf weighttp-master.tar.gz | |
| cd weighttp-master | |
| ./waf configure | |
| ./waf build | |
| sudo ./waf install | |
| 使用: | |
| weighttp -n 10000 -c 10000 http://127.0.0.1:8888/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment