设为首页 收藏本站
查看: 2331|回复: 0

[经验分享] memcached演练(4) 使用apache+memcached-session-manager+tomcat集群

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-8-15 10:53:38 | 显示全部楼层 |阅读模式
继续《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
<distributable/>



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效果
wKiom1eunGfjNwphAACuvAaKpso074.jpg
经过验证,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 测试结果
wKioL1eun2TgAYJ0AADGV-YiNjQ330.jpg
经过验证,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下
1
2
3
4
5
6
7
8
wget -P /u01/tomcat-sets/apache-tomcat-node1/lib  http://repo1.maven.org/maven2/de ... n-manager-1.9.7.jar
wget -P /u01/tomcat-sets/apache-tomcat-node1/lib http://repo1.maven.org/maven2/de ... nager-tc7-1.9.7.jar
wget -P /u01/tomcat-sets/apache-tomcat-node1/lib  http://repo1.maven.org/maven2/ne ... emcached-2.11.1.jar


wget -P /u01/tomcat-sets/apache-tomcat-node2/lib  http://repo1.maven.org/maven2/de ... n-manager-1.9.7.jar
wget -P /u01/tomcat-sets/apache-tomcat-node2/lib http://repo1.maven.org/maven2/de ... nager-tc7-1.9.7.jar
wget -P /u01/tomcat-sets/apache-tomcat-node2/lib  http://repo1.maven.org/maven2/ne ... emcached-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
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效果一样。
wKioL1eun2TgAYJ0AADGV-YiNjQ330.jpg 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.66Failed 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。
接下来,我将把环境分散到多个虚拟机节点上。在测试下。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-258081-1-1.html 上篇帖子: memcached演练(3) 使用apache+搭建双节点tomcat集群 下篇帖子: memcached演练(4) 使用apache+memcached-session-manager+tomcat集群(续)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表