[root@hadoop1 httpd]# httpd -v
Server version: Apache/2.2.15 (Unix)
Server built: Feb 22 2013 11:17:44
[root@hadoop1 httpd]# which httpd
/usr/sbin/httpd
#apache主目录:/etc/httpd 确认JDK 及tomcat服务
[hadoop@hadoop1 tomcat-sets]$ ls /u01/tomcat-sets
apache-tomcat-node1
[hadoop@hadoop1 apache-tomcat-node1]$ cat /proc/meminfo
MemTotal: 1937148 kB
...
[hadoop@hadoop1 /]$ /u01/tomcat-sets/apache-tomcat-node1/bin/version.sh
Using CATALINA_BASE: /u01/tomcat-sets/apache-tomcat-node1
Using CATALINA_HOME: /u01/tomcat-sets/apache-tomcat-node1
Using CATALINA_TMPDIR: /u01/tomcat-sets/apache-tomcat-node1/temp
Using JRE_HOME: /usr/local/java/jdk1.6.0_45
...
Server version: Apache Tomcat/7.0.33
Server built: Nov 18 2012 04:15:21
Server number: 7.0.33.0
OS Name: Linux
OS Version: 2.6.32-358.el6.i686
Architecture: i386
JVM Version: 1.6.0_45-b06
JVM Vendor: Sun Microsystems Inc. 1.测试单台tomcat的吞吐率
1.1准备一个静态测试资源(staticProtocal.html,大小50K)
资源可以通过http://192.168.163.146:8080/examples/staticProtocal.html访问
[hadoop@hadoop1 examples]$ ll /u01/tomcat-sets/apache-tomcat-node1/webapps/examples
total 72
-rw-r--r--. 1 hadoop hadoop 1179 Nov 19 2012 index.html
drwxr-xr-x. 22 hadoop hadoop 4096 Aug 10 18:48 jsp
drwxr-xr-x. 3 hadoop hadoop 4096 Aug 10 18:48 servlets
-rw-rw-r--. 1 hadoop hadoop 50663 Aug 12 21:09 staticProtocal.html
drwxr-xr-x. 7 hadoop hadoop 4096 Aug 10 18:48 WEB-INF
drwxr-xr-x. 2 hadoop hadoop 4096 Aug 10 18:48 websocket 1.2启动apache-tomcat-node1,端口为默认的8080
1.3 在另外一台主机使用apache ab命令测试
C:\Apache24\bin>ab -n 10000 -c 4 http://192.168.163.146:8080/examples/staticProtocal.html
This is ApacheBench, Version 2.3
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.163.146 (be patient)
Completed 1000 requests
...
Completed 10000 requests
Finished 10000 requests
Server Software: Apache-Coyote/1.1
Server Hostname: 192.168.163.146
Server Port: 8080
Document Path: /examples/staticProtocal.html
Document Length: 50663 bytes
Concurrency Level: 4
Time taken for tests: 12.065 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 509120000 bytes
HTML transferred: 506630000 bytes
Requests per second: 828.81 [#/sec] (mean)
Time per request: 4.826 [ms] (mean)
Time per request: 1.207 [ms] (mean, across all concurrent requests)
Transfer rate: 41207.63 [Kbytes/sec] received
... 经过测试,单台tomcat的结果是:QPS:828.81
都有这样一个共识,apache处理静态文件的能力,比tomcat强大。是骡子是马,比比看。
1.4 简单编辑apache配置文件httpd.conf。(最好修改之前备份下)
$ cat /etc/httpd/conf/httpd.conf
...
ServerName localhost:80
DocumentRoot "/var/www/html"
... 1.5 将刚才的staticProtocal.html文件,复制到DocumentRoot“/var/www/html”目录下。
$ ls /var/www/html/
staticProtocal.html 1.6 启动httpd
$ service httpd start
Starting httpd: [ OK ] 这时候可以通过链接访问资源:http://192.168.163.146/staticProtocal.html
1.7 测试apache吞吐量
C:\Apache24\bin>ab -n 10000 -c 4 http://192.168.163.146/staticProtocal.html
This is ApacheBench, Version 2.3
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.163.146 (be patient)
Completed 1000 requests
...
Finished 10000 requests
Server Software: Apache/2.2.15
Server Hostname: 192.168.163.146
Server Port: 80
Document Path: /staticProtocal.html
Document Length: 50663 bytes
Concurrency Level: 4
Time taken for tests: 11.902 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 509350000 bytes
HTML transferred: 506630000 bytes
Requests per second: 840.17 [#/sec] (mean)
Time per request: 4.761 [ms] (mean)
Time per request: 1.190 [ms] (mean, across all concurrent requests)
Transfer rate: 41790.94 [Kbytes/sec] received 经过测试,单台apache的结果是:QPS:840.17
显而易见,apache处理静态文件能力略高于tomcat.
接下来,那就利用apache搭建一个双节点tomcat集群,顺带验证下QPS能达到多少。这是下一小节内容。
2.搭建apache+mod_jk+2个tomcat集群环境
2.1下载mod_jk并安装
要安装httpd-devel,否则会configure: error: Cannot find the WebServer
# yum install httpd-devel
## 安装完httpd-devel之后,新添加目录/usr/sbin/apxs
##下载
# wget
##解压
# tar zxvf tomcat-connectors-1.2.41-src.tar.gz
# cd tomcat-connectors-1.2.41-src/native
# ./buildconf.sh --with-apxs=/usr/sbin/apxs
# make 到这里mod_jk.so已经生成了,最后将mod_jk.so放到apache的modules 目录下
为了排除浏览器缓存干扰,最好使用强制刷新。(CTRL+F5),这时候可以验证下权重。
3.6 测试下双节点集群的吞吐量。
C:\Apache24\bin>ab -n 10000 -c 4 http://192.168.163.146/examples/staticProtocal.html
This is ApacheBench, Version 2.3
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.163.146 (be patient)
Completed 1000 requests
...
Finished 10000 requests
Server Software: Apache/2.2.15
Server Hostname: 192.168.163.146
Server Port: 80
Document Path: /examples/staticProtocal.html
Document Length: 49598 bytes
Concurrency Level: 4
Time taken for tests: 13.996 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 498670000 bytes
HTML transferred: 495980000 bytes
Requests per second: 714.51 [#/sec] (mean)
Time per request: 5.598 [ms] (mean)
Time per request: 1.400 [ms] (mean, across all concurrent requests)
Transfer rate: 34795.47 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.4 1 5
Processing: 0 5 9.1 3 162
Waiting: 0 3 4.9 2 125
Total: 0 6 9.1 3 162
ERROR: The median and mean for the initial connection time are more than twice the standard
deviation apart. These results are NOT reliable.
吞吐量最差:714.51
为什么?
到了这里,还没有讲到session和memcached的影子。