继续《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)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@ page import="java.text.SimpleDateFormat"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
<head>
<title>Tomcat集群测试</title>
</head>
<body>
服务器信息: <%
String dtm = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date());
System.out.println("["+request.getLocalAddr()+":"+ request.getLocalPort()+"]" + dtm);
out.println("<br>["+request.getLocalAddr()+":" +request.getLocalPort()+"]" + dtm+"<br>");
%>
session分发: <%
session.setAttribute("name","dennisit");
System.out.println("[session分发] session id:"+session.getId());
out.println("<br>[session分发] session id: " + session.getId()+"<br>");
%> </body></html>
|
1.2 将两个节点的对应测试应用examples,web.xml添加以下配置
1.3 将jsp文件复制应用中
1
2
| 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| [iyunv@hadoop1 ~]# 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)中的数据没有可比性,两者响应报文大小和特点都不同。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| C:\Apache24\bin>ab -n 10000 -c 4 http://192.168.163.146/examples/testSession.jsp
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
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 [ms] (mean)
Time per request: 1.580 [ms] (mean, across all concurrent requests)
Transfer rate: 362.90 [Kbytes/sec] received
|
吞吐量:633.06.
1.8 先设置sticky_session=true
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| [iyunv@hadoop1 ~]# 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
1
2
| service httpd stop
service httpd start
|
1.10 测试结果
经过验证,sticky_session=false时,同一个浏览器多次访问,将请求都发到同一个服务上,实现了session粘滞效果。
2.11 测试下吞吐量(sticky_session=true)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| c:\Apache24\bin>ab -n 10000 -c 4 http://192.168.163.146/examples/testSession.jsp
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
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 [ms] (mean)
Time per request: 1.172 [ms] (mean, across all concurrent requests)
Transfer rate: 489.14 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-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环境。(具体见<memcached演练(1) 搭建memcached服务>)
1
2
| [hadoop@hadoop1 tomcat-sets]$ ps -ef |grep memcached
nobody 2028 1 0 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下
2.2 配置msm
编辑两节点
/u01/tomcat-sets/apache-tomcat-node1/conf/context.xml
/u01/tomcat-sets/apache-tomcat-node2/conf/context.xml
1
2
3
4
5
6
7
8
| <Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:localhost:11211"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$" />
</Context>
|
并没有用一些效率高的序列化框架。
有这么一个参数确认下
sticky (since 1.4.0, optional, default true) 定义session方式为黏性或非黏性,默认为true。 也就是说,我们开启了黏性。通过前面的使用,理解也很简单。 2.3测试 经过测试,效果和步骤1.10效果一样。
2.4 测试下MSM环境sticky_session=true吞吐量
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
| c:\Apache24\bin>ab -n 10000 -c 4 http://192.168.163.146/examples/testSession.jsp
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
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 [ms] (mean)
Time per request: 1.374 [ms] (mean, across all concurrent requests)
Transfer rate: 421.32 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 0.5 1 5
Processing: 0 5 15.3 2 545
Waiting: 0 5 15.2 2 545
Total: 0 5 15.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
1
2
3
4
5
6
7
8
9
| <Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:localhost:11211"
sticky="false"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$" />
</Context>
|
2.6 经过测试。
并没有达到想要的切换效果。不知什么原因。有清楚原因的朋友,告知下。
以后有机会深入研究下MSM的工作机理。
2.7 测试下吞吐量
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
| c:\Apache24\bin>ab -n 10000 -c 4 http://192.168.163.146/examples/testSession.jsp
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
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 [ms] (mean)
Time per request: 1.374 [ms] (mean, across all concurrent requests)
Transfer rate: 421.12 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 0.9 1 17
Processing: 0 5 12.9 2 527
Waiting: 0 5 12.8 2 527
Total: 0 5 12.9 3 527
|
Requests per second: 727.66 [#/sec] (mean)
Failed requests: 635
结论
环境
| 吞吐量
|
| apache+双节点+MSM(sticky="false")
| 727.66 | Failed requests: 635 | apache+双节点+MSM(sticky="true") | 727.55
|
| apache+双节点(Cluster)
sticky_session=true
| 853.29 |
| apache+双节点(Cluster)
sticky_session=false
| 633.06 |
|
|
|
|
|
|
| 由于memchached与节点+apache环境均安装在同一个机器上,而且是单CPU。
接下来,我将把环境分散到多个虚拟机节点上。在测试下。
|