memcached演练(4) 使用apache+memcached
继续《memcached演练(3) 使用apache+搭建双节点tomcat集群 》,已经简单完成了双节点tomcat集群的搭建。本章在原来集群的基础上,测试session相关内容。主要内容
[*] 测试apache+mod_jk+2个tomcat集群环境,session管理情况
[*] 搭建apache+mod_jk+2个tomcat+memcached-session-manager集群环境
[*] 测试2个环境的吞吐量
1.测试apache+mod_jk+2个tomcat集群环境,session管理情况
1.1 准备测试JSP(testSession.jsp)
Tomcat集群测试
服务器信息:
session分发: 1.2 将两个节点的对应测试应用examples,web.xml添加以下配置
1.3 将jsp文件复制应用中
cp testSession.jsp /u01/tomcat-sets/apache-tomcat-node1/webapps/examples
cp testSession.jsp /u01/tomcat-sets/apache-tomcat-node2/webapps/examples 1.4 回顾下/etc/httpd/workers.properties
worker.list=tomcat1
worker.tomcat1.port=8009
worker.tomcat1.host=127.0.0.1
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1
worker.tomcat2.port=8019
worker.tomcat2.host=127.0.0.1
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=tomcat1,tomcat2
worker.loadbalancer.sticky_session=true sticky_session=false 表明需求会话复制。
sticky_session=true表明为会话粘性,不进行会话复制,当某用户的请求第一次分发到哪台Tomcat后,后继的请求会一直分发到此Tomcat服务器上处理。
1.5 先设置sticky_session=false
# cat /etc/httpd/conf/workers.properties
worker.list=loadbalancer
worker.tomcat1.port=8009
worker.tomcat1.host=127.0.0.1
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1
worker.tomcat2.port=8019
worker.tomcat2.host=127.0.0.1
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=tomcat1,tomcat2
worker.loadbalancer.sticky_session=false 1.6测试sticky_session=false效果
经过验证,sticky_session=false时,同一个浏览器多次访问,实现了负载均衡,服务可以切换。
1.7 测试下吞吐量(sticky_session=false)
本次测试是独立的,和memcached演练(3)中的数据没有可比性,两者响应报文大小和特点都不同。
C:\Apache24\bin>ab-n 10000 -c 4http://192.168.163.146/examples/testSession.jsp
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/2.2.15
Server Hostname: 192.168.163.146
Server Port: 80
Document Path: /examples/testSession.jsp
Document Length: 328 bytes
Concurrency Level: 4
Time taken for tests: 15.796 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 5870000 bytes
HTML transferred: 3280000 bytes
Requests per second: 633.06 [#/sec] (mean)
Time per request: 6.319 (mean)
Time per request: 1.580 (mean, across all concurrent requests)
Transfer rate: 362.90 received 吞吐量:633.06.
1.8 先设置sticky_session=true
# cat /etc/httpd/conf/workers.properties
worker.list=loadbalancer
worker.tomcat1.port=8009
worker.tomcat1.host=127.0.0.1
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1
worker.tomcat2.port=8019
worker.tomcat2.host=127.0.0.1
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=tomcat1,tomcat2
worker.loadbalancer.sticky_session=true 1.9 重启httpd
service httpd stop
service httpd start 1.10 测试结果
经过验证,sticky_session=false时,同一个浏览器多次访问,将请求都发到同一个服务上,实现了session粘滞效果。
2.11 测试下吞吐量(sticky_session=true)
c:\Apache24\bin>ab-n 10000 -c 4http://192.168.163.146/examples/testSession.jsp
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/testSession.jsp
Document Length: 328 bytes
Concurrency Level: 4
Time taken for tests: 11.719 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 5870000 bytes
HTML transferred: 3280000 bytes
Requests per second: 853.29 [#/sec] (mean)
Time per request: 4.688 (mean)
Time per request: 1.172 (mean, across all concurrent requests)
Transfer rate: 489.14 received
Connection Times (ms)
minmean[+/-sd] median max
Connect: 0 0 0.6 1 8
Processing: 0 4 7.5 3 115
Waiting: 0 4 7.0 2 115
Total: 0 5 7.5 3 115
WARNING: The median and mean for the initial connection time are not within a normal deviation
These results are probably not that reliable. 吞吐量:853.29.
通过对比,设置了session粘滞,吞吐量提升很大的空间。
2.搭建apache+mod_jk+2个tomcat+memcached-session-manager集群环境
确认memcached环境。(具体见)
$ ps -ef |grep memcached
nobody 2028 10 10:07 ? 00:00:03 /usr/local/memcached/bin/memcached -d -p 11211 -u nobody -m 64 -c 1024 -P /var/run/memcached/memcached.pid 本节主要内容就是使用memcached-session-manager组件,管理节点间的session信息。
2.1 复制需要的jar到节点lib下
wget -P /u01/tomcat-sets/apache-tomcat-node1/libhttp://repo1.maven.org/maven2/de/javakaffee/msm/memcached-session-manager/1.9.7/memcached-session-manager-1.9.7.jar
wget -P /u01/tomcat-sets/apache-tomcat-node1/lib http://repo1.maven.org/maven2/de/javakaffee/msm/memcached-session-manager-tc7/1.9.7/memcached-session-manager-tc7-1.9.7.jar
wget -P /u01/tomcat-sets/apache-tomcat-node1/libhttp://repo1.maven.org/maven2/net/spy/spymemcached/2.11.1/spymemcached-2.11.1.jar
wget -P /u01/tomcat-sets/apache-tomcat-node2/libhttp://repo1.maven.org/maven2/de/javakaffee/msm/memcached-session-manager/1.9.7/memcached-session-manager-1.9.7.jar
wget -P /u01/tomcat-sets/apache-tomcat-node2/lib http://repo1.maven.org/maven2/de/javakaffee/msm/memcached-session-manager-tc7/1.9.7/memcached-session-manager-tc7-1.9.7.jar
wget -P /u01/tomcat-sets/apache-tomcat-node2/libhttp://repo1.maven.org/maven2/net/spy/spymemcached/2.11.1/spymemcached-2.11.1.jar 2.2 配置msm
编辑两节点
/u01/tomcat-sets/apache-tomcat-node1/conf/context.xml
/u01/tomcat-sets/apache-tomcat-node2/conf/context.xml
WEB-INF/web.xml
并没有用一些效率高的序列化框架。
有这么一个参数确认下
sticky (since 1.4.0, optional, default true)
定义session方式为黏性或非黏性,默认为true。
也就是说,我们开启了黏性。通过前面的使用,理解也很简单。
2.3测试
经过测试,效果和步骤1.10效果一样。
2.4 测试下MSM环境sticky_session=true吞吐量
c:\Apache24\bin>ab-n 10000 -c 4http://192.168.163.146/examples/testSession.jsp
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/2.2.15
Server Hostname: 192.168.163.146
Server Port: 80
Document Path: /examples/testSession.jsp
Document Length: 331 bytes
Concurrency Level: 4
Time taken for tests: 13.745 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 5930000 bytes
HTML transferred: 3310000 bytes
Requests per second: 727.55 [#/sec] (mean)
Time per request: 5.498 (mean)
Time per request: 1.374 (mean, across all concurrent requests)
Transfer rate: 421.32 received
Connection Times (ms)
minmean[+/-sd] median max
Connect: 0 1 0.5 1 5
Processing: 0 515.3 2 545
Waiting: 0 515.2 2 545
Total: 0 515.3 3 545 测试吞吐量效果:727.55。
2.5修改msm参数,关闭sticky_session。
修改两节点参数
/u01/tomcat-sets/apache-tomcat-node1/conf/context.xml
/u01/tomcat-sets/apache-tomcat-node2/conf/context.xml
WEB-INF/web.xml
2.6 经过测试。
并没有达到想要的切换效果。不知什么原因。有清楚原因的朋友,告知下。
以后有机会深入研究下MSM的工作机理。
2.7 测试下吞吐量
c:\Apache24\bin>ab-n 10000 -c 4http://192.168.163.146/examples/testSession.jsp
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 10000 requests
Finished 10000 requests
Server Software: Apache/2.2.15
Server Hostname: 192.168.163.146
Server Port: 80
Document Path: /examples/testSession.jsp
Document Length: 331 bytes
Concurrency Level: 4
Time taken for tests: 13.743 seconds
Complete requests: 10000
Failed requests: 635
(Connect: 0, Receive: 0, Length: 635, Exceptions: 0)
Total transferred: 5926190 bytes
HTML transferred: 3308095 bytes
Requests per second: 727.66 [#/sec] (mean)
Time per request: 5.497 (mean)
Time per request: 1.374 (mean, across all concurrent requests)
Transfer rate: 421.12 received
Connection Times (ms)
minmean[+/-sd] median max
Connect: 0 1 0.9 1 17
Processing: 0 512.9 2 527
Waiting: 0 512.8 2 527
Total: 0 512.9 3 527 Requests per second: 727.66 [#/sec] (mean)
Failed requests: 635
结论
环境
吞吐量
apache+双节点+MSM(sticky="false")
727.66Failed requests: 635apache+双节点+MSM(sticky="true")727.55
apache+双节点(Cluster)
sticky_session=true
853.29
apache+双节点(Cluster)
sticky_session=false
633.06
由于memchached与节点+apache环境均安装在同一个机器上,而且是单CPU。
接下来,我将把环境分散到多个虚拟机节点上。在测试下。
参考资源:
http://www.cnblogs.com/dennisit/p/3370220.html
页:
[1]