??xml version="1.0" encoding="utf-8" standalone="yes"?>欧美日韩在线综合,色佬视频在线观看,中文字幕一区二区三中文字幕http://www.aygfsteel.com/gdufo/category/32717.htmlzh-cnSat, 02 Jun 2012 03:50:06 GMTSat, 02 Jun 2012 03:50:06 GMT60TOMCAT6配置负蝲均衡和集?_2http://www.aygfsteel.com/gdufo/archive/2012/06/02/379786.htmlgdufogdufoSat, 02 Jun 2012 00:55:00 GMThttp://www.aygfsteel.com/gdufo/archive/2012/06/02/379786.html

http://blog.csdn.net/dangerous_fire/article/details/6278435

最q要配置tomcat集群Q在|上搜了很多文章Q但照着步骤一步一步做到最后却无法成功Q着使我费了两天的劲查看了apache ? tomcat的大量文档,才将问题一一解决。ؓ方便自己和新手配|tomcat集群Q我整理好的过E晒一晒,希望可以帮到后来人少C些弯路?/p>

==================

目标:
使用 apache ?tomcat 配置一个可以应用的 web |站Q要辑ֈ以下要求Q?
1?Apache 做ؓ HttpServer Q后面连接多?tomcat 应用实例Qƈq行负蝲均衡?
2?为系l设?Session 时旉Q包?Apache ?tomcat
3?为系l屏蔽文件列表,包括 Apache ?tomcat

注:本例E以一台机器ؓ例子Q即同一台机器上装一个apache?个Tomcat?/p>

一、前期准备工作:安装用的E序Q前提保证已安装了JDK1.5以上的版本)
APAHCE 2.2.8下蝲Qapache_2.2.8-win32-x86-no_ssl.msi
TOMCAT6.0.14下蝲Qapache-tomcat-6.0.14.zip直接解压?/p>

二、安装过E?br />APAHCE安装目录QD:/Apache?
两个TOMCAT目录Q自行解压到(D:/TomcatCluster/)下?br />分别?tomcat6-aQtomcat6-b

三、配|?
1、Apache配置
1.1 httpd.conf配置
修改APACHE的配|文件D:/Apache/conf/httpd.conf

q里q没有用mod_jk.soq行apache和tomcat的链接,?.X以后apache自n已集成了mod_jk.so的功能。只需单的把下面几行去掉注释,q当于以前用mod_jk.so比较J琐的配|了?br />q里主要采用了代理的ҎQ就q么单?/p>

以下Module的注释去?br />LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so

再找?br /><IfModule dir_module>
DirectoryIndex index.html
</IfModule>
加上index.jsp修改?

<IfModule dir_module>
DirectoryIndex index.html index.jsp
</IfModule>

此处dindex.jsp 主要Z配置完成以后利用index.jsp输出试信息Q?/p>

?httpd.conf 最后面加入
ProxyRequests Off
<proxy balancer://cluster>
BalancerMember ajp://127.0.0.1:8009 loadfactor=1 route=jvm1
BalancerMember ajp://127.0.0.1:9009 loadfactor=1 route=jvm2
</proxy>

上面的两个BalancerMember成员是我们配|的tomcat集群?/p>


1.2 httpd-vhosts.conf讄
接下来进行虚拟主机的讄?br />APACHE的虚拟主|如下:
首先要修?conf/httpd.conf
扑ֈ

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

把Include语句注释L。改?

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

在文Ӟextra/httpd-vhosts.confQ最下面加入

<VirtualHost *:80>
 ServerAdmin adminname
 ServerName localhost
 ServerAlias localhost
 ProxyPass / balancer://cluster/ stickysession=jsessionid nofailover=On lbmethod=bytraffic
 ProxyPassReverse / balancer://cluster/
</VirtualHost>

其中的域名和路径Ҏ你自己情况设|?

负蝲均衡有三U方式,可以通过讄 lbmethod 选择自己需要的方式Q详l可查看apache文档

proxy是位于客L与实际的服务器之间的服务器,一般称为facade serverQ负责将外部的请求分,也负责对内部的响应做一些必要的处理?br />如果l合mod_cacheQ则可提高访问速度Q适当的减ȝl流量压力?br />闲话说Q直接拿个例子来Q?br />    设本站地址?www.test.com
    ProxyPass /images/ !
    ProxyPass /js/ !
    ProxyPass /css/ !
    ProxyPass /example http://www.example.com/
    ProxyPassReverse /example http://www.example.com/
    ProxyPass / ajp://127.0.0.1:8009/
    ProxyPassReverse / ajp://127.0.0.1:8009/
q是上一的例子QProxyPass易理解,是转发url上的hQ而其中的配置序也是需要遵守?br />要禁止{发的url需要放在一般的h之前?br />对于
http://www.test.com/images/ 
http://www.test.com/js/
http://www.test.com/css/
的请求是不予转发的,对于http://www.test.com/example/的请求,会{发到http://www.example.com?br />值得注意的就是ProxyPassReverse的配|了Q这是反向代理?br />Z么要在这里加上这L配置Q我们来看个例子Q?br /> 在没有加q样的反向代理设|的情况下,讉Khttp://www.test.com/example/aQ?br /> 如果www.example.com对请求进行了redirect?a >http://www.example.com/bQ?br /> 那么Q客L׃l过反向代理Q进而访?a >http://www.test.com/example/b?br /> 如果讄了反向代理,则会在{交HTTP重定向应{到客户端之前调整它?a >http://www.test.com/example/a/b
 x在原h之后q加上了redirect的\径?br />更多更详l的关于mod_proxy的描q可以参见手册:
http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/mod_proxy.html


2 配置 tomcat
2.1 配置 server 的关?
我们需要在一台机器上跑两个不同的 tomcat Q需要修改不同的 tomcat 的关闭口Q避免出现端口被占用的情c?br />其中tomcat6-a用默认|不修攏V?br />tomcat6-b修改。在tomcat6-b/conf下的 server.xml 中找?server, :
<Server port="8005" shutdown="SHUTDOWN">
改ؓ
<Server port="9005" shutdown="SHUTDOWN">

2.2 配置 Engine
把原来的配置注释掉,把下面一句去掉注释。ƈ标明jvmRoute="jvm2"
<Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm2">

以下是原来的配置?br /><Engine name="Catalina" defaultHost="localhost">
 
2.3. 配置 Connector
原来的默认配|?

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

tomcal6-b 中的 protocol="HTTP/1.1" ?Connector 端口改ؓ 8081 避免冲突。tomcat6-a 中的保持不变?br />protocol="AJP/1.3" ?Connector 是apache和tomcat链接的关键,前台apache是通过AJP协议与tomcatq行通信的,以完成负载均衡的作用?br />也可以用HTTP协议。大家注意它们是如何q接通信的,Qport="8009"Q就是连接的接口了?

把tomcat6-b?lt;Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> 中的portҎ 9009
<proxy balancer://cluster>
#?tomcat6-a 对应Qroute?lt;Engine jvmRoute="jvm1">对应?
BalancerMember ajp://127.0.0.1:8009 loadfactor=1 route=jvm1
#?tomcat6-b 对应Qroute?lt;Engine jvmRoute="jvm2">对应?
BalancerMember ajp://127.0.0.1:9009 loadfactor=1 route=jvm2
</proxy>

中的端口对应Q?br />tomcat6-a 的ajp端口port:8009
tomcat6-b 的ajp端口port:9009
一定要与上面的一致?/p>

2.5.配置Cluster(两个tomcat中都要修?
原来的配|?
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
修改Z下的代码Q?lt;Receiver port=”XX”/>port也要保证唯一性?

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"? channelSendOptions="6">
 <Manager className="org.apache.catalina.ha.session.BackupManager"
  expireSessionsOnShutdown="false"
  notifyListenersOnReplication="true"
  mapSendOptions="6"/>
 <!--
 <Manager className="org.apache.catalina.ha.session.DeltaManager"
  expireSessionsOnShutdown="false"
  notifyListenersOnReplication="true"/>
 -->
 <Channel className="org.apache.catalina.tribes.group.GroupChannel">
  <Membership className="org.apache.catalina.tribes.membership.McastService"
   address="228.0.0.4"
   port="45564"
   frequency="500"
   dropTime="3000"/>
  <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
   address="auto"
   port="5001"
   selectorTimeout="100"
   maxThreads="6"/>
  <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
   <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
  </Sender>
  <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
  <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
  <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
 </Channel>
 <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
  filter=".*/.gif;.*/.js;.*/.jpg;.*/.png;.*/.htm;.*/.html;.*/.css;.*/.txt;"/>
 <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
  tempDir="/tmp/war-temp/"
  deployDir="/tmp/war-deploy/"
  watchDir="/tmp/war-listen/"
  watchEnabled="false"/>
 <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>

q个讄是主要用以tomcat的集?br />tomcat集群各节炚w过建立tcp链接来完成Session的拷贝,拯有同步和异步两种模式?br />在同步模式下Q对客户端的响应必须在Session拯到其他节点完成后q行Q异步模式无需{待Session拯完成可响应?br />异步模式更高效,但是同步模式可靠性更高。同步异步模式由channelSendOptions参数控制Q默认值是8Qؓ异步模式Q?是同步模式?br />在异步模式下Q可以通过加上拯认QAcknowledgeQ来提高可靠性,此时channelSendOptions设ؓ10?/p>

Manager用来在节炚w拯SessionQ默认用DeltaManagerQDeltaManager采用的一Uall-to-all的工作方式,
即集中的节点会把Session数据向所有其他节Ҏ贝,而不其他节Ҏ否部|了当前应用?br />当集中的节Ҏ量很多ƈ且部|着不同应用Ӟ可以使用BackupManagerQBackManager仅向部v了当前应用的节点拯Session?br />但是到目前ؓ止BackupManagerq未l过大规模测试,可靠性不及DeltaManager?/p>

四、启动服务,试tomcat自带的例?
1、测试apache和tomcat协作?
先在每个tomcat中的/webapps/ROOT下的index.jsp下面加上以下的测试代码部分:
(X代表不同的tomcat的输Z同的信息)Q把index.html删除Q以免媄响测试效果?br />在最后面的加??lt;/table></body>之间?
<%
 System.out.println("tomcat6 A|B deal with request");
%>
然后再通过http://127.0.0.1来访问一下,׃出现大家熟悉的猫猫?
然后再通过分别讉K
http://127.0.0.1:8080
http://127.0.0.1:8081


它们讉K的内容和上面的http:// 127.0.0.1是一L?
q样p明apache和TOMCAT整合成功Q?
2、测试均衡器
如果?extra/httpd-vhosts.conf 中配|?没有讄 lbmethod=bytrafficQ将使用默认?byrequests Q控制分配的一共有三种方式Q还有一U是 bybusyness ?br />通过http://127.0.0.1多次讉KQ?br />?果用的?byrequests 的分配方式,要想看到真正的效果,必须用一些压力测试工P可用微YMicrosoft Web Application Stress Toolq行单压力测试,不然你靠不停h是体C出来的,你只会在一个tomcat的控制台有输出结果?br />只用用压力测试工h拟大量用户同时访问,你会发现四个tomcat控制台均有打出控制信息,说明均衡器工作正常?
而如果配|ؓ bytraffic q且tomcat6-a ?tomcat6-b 讄?loadfactor=1Q则h会均匀的分配给不同的tomcatQ很Ҏ试出来?br />如果惛_此感兴趣Q请查看apache 的文档ƈ试修改
httpd.conf
----------------------
ProxyRequests Off
<proxy balancer://cluster>
BalancerMember ajp://127.0.0.1:8009 loadfactor=1 route=jvm1
BalancerMember ajp://127.0.0.1:9009 loadfactor=1 route=jvm2
</proxy>
----------------------
 中的 loadfactor  参数?br />extra/httpd-vhosts.conf
----------------------
<VirtualHost *:80>
 ServerAdmin adminname
 ServerName localhost
 ServerAlias localhost
 ProxyPass / balancer://cluster/ stickysession=jsessionid nofailover=On lbmethod=bytraffic
 ProxyPassReverse / balancer://cluster/
</VirtualHost>
----------------------
中的 lbmethod 参数


注意Q如果apache 中出现如下错?br />Encountered too many errors accepting client connections. Possible causes: dynamic address renewal, or incompatible VPN or firewall software. Try using the Win32DisableAcceptEx directive.

~辑httpd.conf 加入
Win32DisableAcceptEx ##加入q行
重启apachep决了?/p>

如果修改后还是不行,ȝ有错误记录,
cmd?br />netsh winsock reset

因ؓq个错误可能与winsock有关Q有|友也出Cq个问题Q他认ؓ是金山毒霸或者升U精灵修改了WINSOCKD的。我没有安装但是pȝl常自动更新Q别的Y件也?可能会有冲突?br />使用此条命o恢复Winsock后,重启电脑后这个问题就会解决了?/div>

gdufo 2012-06-02 08:55 发表评论
]]>
Tomcat6.0负蝲均衡{略 _ 1http://www.aygfsteel.com/gdufo/archive/2012/06/02/379785.htmlgdufogdufoSat, 02 Jun 2012 00:54:00 GMThttp://www.aygfsteel.com/gdufo/archive/2012/06/02/379785.htmlhttp://www.cnblogs.com/shiyangxt/archive/2009/02/26/1398902.html

               开学以后,q箋几天休息不好QL犯困Q也许这是“春困U乏”的症状吧。最q老师提出了负载均衡功能的需求,以减?/p>

|站的高峰期的服务器负担Q现在学校的g设施q是蛮好的,有三Q四台服务器可以提供使用Q也很大E度的上方便了我做一些测试?/p>

因ؓq个子项目,假期三个同学已经基本完工Q所以我也只能出点微薄之力,把这个负载均衡搞定,具体用不用我不管Qv码是我的一?/p>

功能?/p>

 

               其实无论是分布式Q数据缓存,q是负蝲均衡Q无非就是改善网站的性能瓉Q在|站源码不做优化的情况下Q负载均衡可以说

是最直接的手D了。其实抛开q个名词Q放开了说Q就是希望用戯够分,也就是说把所有用L讉K压力分散到多台服务器上,也可?/p>

分散到多个tomcat里,如果一台服务器装多个tomcatQ那么即使是负蝲均衡Q性能也提高不了太多,不过可以提高E_性,卛_错性?/p>

当其中一个主tomcat当掉Q其他的tomcat也可以补上,因ؓtomcat之间实现了Session׃n。待tomcat服务器修复后再次启动Q就?/p>

自动拯所有session数据Q然后加入集。这样就可以不间断的提供服务。如果要真正从本质上提升性能Q必要分布到多台服务器?/p>

同样tomcat也可以做到。网上相兌料比较多Q可以很方便的查刎ͼ但是质量不算高。我希望可以通过q篇随笔Q系l的ȝ。本文的

例子是同一台服务器上运行两个tomcatQ做两个tomcat之间的负载均衡。其实多台服务器各配|一个tomcat也可以,而且那样的话Q可以?/p>

安装版的tomcatQ而不用是下文中的免安装的tomcatQ而且tomcat端口配置也就不用修改了。下文也会提到?/p>

 

               tomcat的负载均衡需要apache服务器的加入来实现。在q行配置之前请先卸蝲调已安装的tomcatQ然后检查apache的版本?/p>

我这ơ配|用的是apache-tomcat-6.0.18免安装版本,我亲自测试后推断安装版的tomcat在同一台机子上会不能启动两个以上,可能?/p>

因ؓ安装版的tomcat侵入了系l,D即在server.xml里修改了配置Q还是会引v冲突。所以我使用tomcat免安装版?/p>

apache使用的是apache_2.2.11-win32-x86-no_ssl.msi。如果版本低?.2负蝲均衡的配|要有所不同Q因?.2.11?.2.8版本

集成了jk2{负载均衡工P所以配|要单许多。别的版本我没有具体试Q有待考究。这两个软g可以到官方网站下载?/p>

 

                 把Apache安装行在80端口的Windows服务Q安装成功后在系l服务列表中可以看到Apache2.2服务。服务启动后在浏览器?/p>

输入http://localhostq行试Q如果能看到一?It works!"的页面就代表Apache已经正常工作了。把tomcat解压CQ意目录,赋g个另命名?/p>

起名和\径对配置没有影响。但要保证端口不要冲H,如果装有Oracle或IIS的用户需要修Ҏ关闭相关接口的服务。当然jdk的配|也?/p>

必须的,q个不再q多叙述?/p>

     

                 首先Q在Apache安装目录下找到conf/httpd.conf文g,L以下文本前的注释W(#Q以便让Apache在启动时自动加蝲代理QproxyQ?/p>

模块?/p>

 

    LoadModule proxy_module modules/mod_proxy.so
     LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
     LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
     LoadModule proxy_connect_module modules/mod_proxy_connect.so
     LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
     LoadModule proxy_http_module modules/mod_proxy_http.so

 

向下拉动文档扑ֈ<IfModule dir_module>节点Q在DirectoryIndex index.html后加上index.jspQ这一步只是ؓ了待会配|完tomcat后能看到?/p>

猫首,可以不做。l下拉文档找到Include conf/extra/httpd-vhosts.confQ去掉前面的注释W?/p>

 

然后打开conf/extra/httpd-vhosts.confQ配|虚拟站点,在最下面加上

 

复制代码
<VirtualHost *:80> 
         ServerAdmin 理员邮?br />           ServerName localhost
         ServerAlias localhost 
         ProxyPass / balancer://sy/ stickysession=jsessionid nofailover=On 
         ProxyPassReverse / balancer://sy/ 
         ErrorLog "logs/sy-error.log"
         CustomLog "logs/sy-access.log" common
</VirtualHost>

复制代码

 

然后回到httpd.confQ在文档最下面加上

 

ProxyRequests Off 
<proxy balancer://sy> 
       BalancerMember ajp://127.0.0.1:8009 loadfactor=1 route=jvm1
       BalancerMember ajp://127.0.0.1:9009 loadfactor=1 route=jvm2
</proxy>

 

ProxyRequests Off 是告诉Apache需要用反向代理,ip地址和端口唯一定了tomcat节点和配|的ajp接受端口。loadfactor是负载因子,

Apache会按负蝲因子的比例向后端tomcat节点转发hQ负载因子越大,对应的tomcat服务器就会处理越多的hQ如两个tomcat?/p>

?QApache按1Q?的比例{发,如果??按2Q?的比例{发。这样就可以佉K|更灉|Q例如可以给性能好的服务器增加处?/p>

工作的比例,如果采取多台服务器,只需要修改ip地址和端口就可以了。route参数对应后箋tomcat配置中的引擎路径QjvmRouteQ?/p>

                 如果仅仅Z配置一个可用的集群QTomcat的配|将会非常简单。分别打开两个tomcat的server.xml配置文gQ其中一台可以采用默?/p>

的设|,只需要修改两个地方,而另一个要有较大改动以避免与前一台冲H。如果两C在同一台服务器上运行,对于端口׃需做改动。首先是

配置关闭端口Q找?lt;Server port="8005" shutdown="SHUTDOWN">Q第一C变,把第二台改ؓ9005?/p>

                下面配置Connector的端口,扑ֈnon-SSL HTTP/1.1 ConnectorQ即tomcat单独工作时的默认ConnectorQ保留第一台默认配|,?080?/p>

口侦听,而把W二台设|ؓ?080端口侦听。往下找到AJP 1.3 ConnectorQ?lt;Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />Q这?/p>

tomcat接收从Apacheq来的ajpq接h时用的端口Q保留第一台默认设|,把第二台端口改ؓ9009。第一台tomcat的server.xml中找?/p>

<Engine name="Catalina" defaultHost="localhost">Q去掉这D|改ؓ注释Q把上方紧挨?lt;Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">

注释W去掉,对于W二収ͼL注释Wƈ把jvm1改ؓjvm2?/p>

               向下扑ֈ<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>Q去掉注释,q里的配|是Z可以在集中的所有tomcat节点

间共享会话(SessionQ。如果仅仅ؓ了获得一个可用的tomcat集群QCluster只需要这么配|就可以了?/p>

               只需要简单的几步配|完成,然后可以试一下是否配|成功。引用网上的一个测试方法,是在webapps目录下新建test目录Q在test?/p>

录下新徏test.jsp文gQ代码我E作改动如下Q?/p>

 

复制代码
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.util.*" %>
<html><head><title>shiyang</title></head>
<body>
服务信息:
<%
out.println(request.getLocalAddr() 
+ " : " + request.getLocalPort()+"<br/>");%>
<%
out.println(
"<br> ID " + session.getId()+"<br/>"); 
String dataName = request.getParameter("dataName");

if (dataName != null && dataName.length() > 0) {
String dataValue = request.getParameter("dataValue");
session.setAttribute(dataName, dataValue);
}

out.print(
"<b>Session 列表</b><br/>");
Enumeration e 
= session.getAttributeNames();

while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = session.getAttribute(name).toString();
out.println( name 
+ " = " + value+"<br/>");
System.out.println( name 
+ " = " + value);
}
%>
<form action="test.jsp" method="POST">
名称:
<input type=text size=20 name="dataName">
<br/>
?
<input type=text size=20 name="dataValue">
<br/>
<input type=submit value="提交">
</form>
</body>
</html>
复制代码

 

在test目录下l新建WEB-INF目录和web.xmlQ在<web-app>节点下加?lt;distributable />Q这一步非帔R要,是ؓ了通知tomcat服务器,

当前应用需要在集群中的所有节炚w实现Session׃n。如果tomcat中的所有应用都需要Session׃nQ也可以把conf/context.xml中的

<Context>改ؓ<Context distributable="true">Q这样就不需Ҏ有应用的web.xml再进行单独配|。测试代码完成!

 

先启动Apache服务Q在先后启动两台tomcatQ分别点startup.bat批处理。如果一切顺利的话,׃启动成功。再ơ访?a href="http://localhost/">http://localhostQ?/p>

可以看到猫面。访?a href="http://localhost/test/test.jsp">http://localhost/test/test.jsp。可以看到包括服务器地址Q端口,session{信息在内的面?/p>

                然后你可以测试一下容错功能,关闭一个tomcatQ看看服务是否正常,然后重启tomcatQ关掉另一台tomcatQ看?/p>

是否也可以l提供服务。当然你也可以配|多台tomcatQ但是原理都一栗?/p>

 OKQ讲到这里?/p>



gdufo 2012-06-02 08:54 发表评论
]]>
jmeter试zkosshttp://www.aygfsteel.com/gdufo/archive/2012/05/31/379700.htmlgdufogdufoThu, 31 May 2012 15:35:00 GMThttp://www.aygfsteel.com/gdufo/archive/2012/05/31/379700.htmlhttp://books.zkoss.org/wiki/Small_Talks/2012/May/Perform_stress_test_on_ZK_using_JMeter-take_Shopping_Cart_as_an_example

Contents

[hide]

Preface

Dennis Chen has shared a small talk illustrating how you can execute a loading test with ZK applications using JMeter. Now, in this small talk we will take a real application as an example to demonstrate in detail how you can actually apply the ideas illustrated in Dennis’ article to perform a stress test.

Test plan

We will be using the "shopping cart" example from ZK Essentials as the template application to perform the stress test.

Setup

  • ZK 5.0.11
  • zk testing demo ( a demo based on the shopping cart sample)
  • Jmeter 2.5.1

Test Scenario

  1. User enters his user name and password for authentication
  2. Login successfully to the shopping site, redirect to index.zul
  3. User selects an item and drag to the shopping cart
  4. User checks out

Since this is a stress test, we can apply 50, 100, 150,... concurrent users to perform the test scenario simultaneously. In our example we have created a max of 300 accounts, which allows you to perform the test with as many as 300 concurrent users.

Before we start

As mentioned above we will be using the "shopping cart" example from ZK Essentials as the template application. However there is only one set of login/password in the current shopping cart implementation which is not sufficient for multiple users. To support multiple users, we have modified the shopping cart example to generate multiple accounts, so that each user will be logged in using a different account. This is done as follows, and it will be triggered as you click "createUserBtn" in login.zul:

1. prepare a CSV file that includes a list of user names and passwords:

Csv.png

2. Add the following code to LoginViewCtrl.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public void onClick$createUserBtn() {
        Map map = userinfo();
        Session session = StoreHibernateUtil.openSession();
        Transaction t = session.beginTransaction();
         
        Iterator entries = map.entrySet().iterator();
        int i = 0;
        while (entries.hasNext()) {
            i ++;
            Map.Entry entry = (Map.Entry) entries.next();
            String name = (String)entry.getKey();
            String pwd = (String)entry.getValue();
            User user = new User(i, name, pwd, "user");
            session.save(user);
            if (i % 20 == 0) {
                session.flush();
                session.clear();
            }
        }
        t.commit();
        session.close();
    }

Configuring ZK

As illustrated in Dennis’ small talk, you need to define IdGenerator to fix the desktop IDs and component IDs so that we can record and play the testing script. The IdGenerator is implemented as follows:

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
public class MyIdgenerator implements IdGenerator {
    private static ThreadLocal<HttpServletResponse> response = new ThreadLocal<HttpServletResponse>();
    private static AtomicInteger ai = new AtomicInteger();
 
    public String nextComponentUuid(Desktop desktop, Component comp) {
        String number;
        if ((number = (String) desktop.getAttribute("Id_Num")) == null) {
            number = "0";
            desktop.setAttribute("Id_Num", number);
        }
        int i = Integer.parseInt(number);
        i++;// Start from 1
        desktop.setAttribute("Id_Num", String.valueOf(i));
        return "t_" + i;
    }
 
    public String nextDesktopId(Desktop desktop) {
        HttpServletRequest req = (HttpServletRequest)Executions.getCurrent().getNativeRequest();
        String dtid = req.getParameter("tdtid");
        if(dtid!=null){
        }
        return dtid==null?null:dtid;
    }
 
    public String nextPageUuid(Page page) {
        return null;
    }
}
  • Define your IdGenerator in zk.xml

Then, define your IdGenerator in zk.xml, for example,

1
2
3
<system-config>
        <id-generator-class>foo.MyIdgenerator</id-generator-class>
</system-config>

Preparing Testing Scripts

Now we are ready to record the scripts. We will be recording 6 HTTP requests as illustrated in the image below. What we need to do is to configure the parameters of these 6 requests based on the application that we wish to test.

All.png

Load CSV file as the variable of the user name and password

  • Add a CSV Data Set Config

First we need to add a CSV Data Set Config here. The element will iterate the csv data set to simulate muti-users login into the application. Please specify a fully qualified name to the Filename field (ex: C:\mycsv\users.csv ), and specify the variable name to the Variable Names field for later use.

Csv data set.png

  • Add BSF PostProcessor

Then we need to ask jmeter to generate the accounts and passwords automatically based on our CSV file. What we need to do is to add a BSF PostProcessor element, set the language to beanshell, and define:


var username = vars.get("username");

var password = vars.get("password");

vars.put("user","{\"value\":\""+username+"\",\"start\":2}");

vars.put("pwd","{\"value\":\""+password+"\",\"start\":2}");


This script will get the username and password variables generated by CSV Data Set Config element, and combine the result and some text as a parameter which will be used as user names and passwords later.

BSF PostProcessor.png

Set account & password as variables

With these settings ready, we can now set the parameter dtid as ${dtid} and use EL to replace a fixed account and password in the first ajax request (i.e. the login request). For example if we send zk/zk as user name and password, then we will be seeing

data_3: {"value":"zk","start":2} //for username

data_4: {"value":"zk","start":2} //for password

in the recorded jmeter’s request. Then, we use ${user} and ${pwd} to replace {"value":"zk","start":2} for handling the accounts and passwords dynamically.

Submit.png

Generate new desktop ID for redirecting to a new page

After an user logged into the system, he will be redirected to index.zul. Since the URL is changed, the desktop and it’s id will also be changed, we need to retrieve the desktop id again using ${__intSum(${dtid},1,dtid)}.

Specify parameter

The last 3 http requests are for adding products to the shopping cart, check out, and close the browser tab. What we need to do is just to modify their tdtid to ${__intSum(${dtid},1,dtid).

DTID.png

Add the listeners for creating reports

There are many different elements that allows you to generate different kinds of reports, such as Aggregate Report and Graph Results. You can add these listeners to Thread Group or HTTP request depending on the report you wish to generate.

Listener1.png

Now we have completed all the settings and have saved these configurations as test.jmx.

Running the test

Now we are ready to start the application and to run the test.

  1. Generate accounts
  2. Start your web server, and access login.zul. Click createUserBtn for creating multiple accounts.

    CreateAccounts.png

  3. Run the testing script
    1. Open jmeter’s menu, File > Open , and load test.jmx.
    2. Specify your IP and port, for example we use localhost/8080 as ip and port number
    3. Http request default.png

    4. In Thread Group ( the root element), set the number of concurrent users to test.
    5. Set number of Users .png

    6. Perform Run > Start to run the test.
    7. You can then observe the average response time, 90% line response time, median response time and other results by accessing the Aggregate Report .

      Aggregate report.png

Trouble-shooting & Tips

  1. Tips: Performing repeating tests
  2. If you have finished a round of test (for example 0~50) you should restart your server before performing another round of test. This is because after you finish a round of test, there will be an extra item listed in each user’s page because they all ordered an item. This extra item is displayed at the bottom of the page (see the image on the right). As there is a DOM change due to this extra item, components’ IDs and orders are also changed thus different from the script you recorded earlier. To solve this problem, just restart your server before performing another round of test.

    Without order.png One order.png

  3. Trouble-shooting: Erred response
  4. Nothing response.png

    If you encounter the Response data error shown as the image above, it is most likely that you did not implement IdGenerator correctly. Please refer to Configuring ZK section to implement UUID.

  5. Trouble-shooting: Timeout error
  6. Timeout.png

    Timeout errors occur when the desktop id in the Ajax request is no longer available at the server side. This normally happens when the URL is changed. If this happens, you need to retrieve desktop ID again. Please refer to Testing Scripts section to implement Desktop ID.

    Timeout may also relate to the max allowed desktops. In ZK there is a setting called “max-desktops-per-session” which defines the max concurrent desktops for each session. The more browser tabs an user opens the more desktops will be saved on the session. If the number exceeds the max allowed desktops then some desktops will be dropped with the timeout error.

    By default the number is 15 which means an user can open as many as 15 tabs in a same browser at the same time. If you have configured it to a smaller number for saving the memory, and in your use case the users will be opening up multiple tabs then you should double check whether this is the reason causing the timeout error. To change this setting, use:

    1
    2
    3
    <session-config>
        <max-desktops-per-session>1</max-desktops-per-session>
    </session-config>
  7. Tips: close browser tab for saving memory
  8. ZK stores desktops in sessions, when user closes the browser tab ZK will send the rmDesktop command to remove the desktop. We can simulate this behavior to save memory when performing a stress test. This is done in the last http request defined in test.jmx. You can refer to the image below:

    RmDesktop.png

Downloads

users.csv - users.csv (Please place the csv file under C:/mycsv/)

zk testing demo – the modified shopping cart application used in this small talk

jmeter 2.5.1 – http://jmeter.apache.org/download_jmeter.cgi

test.jmx – test.jmx




gdufo 2012-05-31 23:35 发表评论
]]>
Tomcat5.5配置-多域名绑定和虚拟目录 http://www.aygfsteel.com/gdufo/archive/2009/01/06/250021.htmlgdufogdufoTue, 06 Jan 2009 00:30:00 GMThttp://www.aygfsteel.com/gdufo/archive/2009/01/06/250021.htmlhttp://www.aygfsteel.com/gdufo/comments/250021.htmlhttp://www.aygfsteel.com/gdufo/archive/2009/01/06/250021.html#Feedback0http://www.aygfsteel.com/gdufo/comments/commentRss/250021.htmlhttp://www.aygfsteel.com/gdufo/services/trackbacks/250021.html阅读全文

gdufo 2009-01-06 08:30 发表评论
]]>
tomcat理界面常用讄 -- 不解压war文ghttp://www.aygfsteel.com/gdufo/archive/2008/07/02/212193.htmlgdufogdufoWed, 02 Jul 2008 12:17:00 GMThttp://www.aygfsteel.com/gdufo/archive/2008/07/02/212193.html

?
1. war文g内的WEB-INF/classes目录下的所有class文g
2. war文g内的/WEB-INF/lib目录下的所有jar文g
3. war文g内的/WEB-INF目录下的web.xml文g
4. war文g内的环境配置文g
上述四项中的MҎ变后自动重蝲。这样就无须手工重新deployQ节省调试时间?br />
1.登陆理界面
http://localhost:8080/admin

密码和用户名在你安装的时候设定的Q如果忘?或没?的话Q去改tomcat\conf\tomcat-users.xmlQ添加admin?manager两个roleQ一个用P该用Lrole为admin和manager可以了Q按原有的xml复制修改可以?br />
2.讄步骤
  2.1 点击左边框架中Service菜单左边的圆Q展开列表 
  2.2 点击左边框架中Host (localhost)菜单,双框架出现讄?br />   2.3 把右Ҏ架中Unpack WARs双的下拉列表改为false
  2.4 点击双框架中右上角save按钮 
  2.5 点击剙框架Commit Changes按钮

注意Q?span style="color: red">要保证文件不是只ȝ





gdufo 2008-07-02 20:17 发表评论
]]>
不能讉KTomcat5.5的admin面 http://www.aygfsteel.com/gdufo/archive/2008/07/02/212189.htmlgdufogdufoWed, 02 Jul 2008 12:00:00 GMThttp://www.aygfsteel.com/gdufo/archive/2008/07/02/212189.html
Tomcat 5可以通过以运行在|页览器的配置应用E序非常方便地进行服务器的配|。这个应用程序称为Tomcat Administration Web Application。然而,Tomcat 5.5 以后的binary 核心安装版不再提供Tomcat Administration Web Application。要安装后者,需要单独下载和安装。Tomcat q没有ؓAdministration Web Application提供一U自动整合的安装E序。本文将讲述安装和配|的详细q程?br />
W一步,认你的Tomcat 中是否已安装了Administration Web Application。首先确定Tomcat Service 正在q行。然后在览器中Q键?http://localhost:8080/adminQ如果看到Tomcat Web Server Administration Tool 的页面,说明Administration Web Application 已安装好了。你可以省点旉Q不必读下文了。如果看到的?br /> Tomcat's administration web application is no longer installed by default. Download and install the "admin" package to use it.
那么q篇文章q你看对了Q就是专门ؓ你写的?br />
W二步,下蝲admin package。说实话Q很多h居然找不到在哪里下蝲。这不怪你们。Apache Tomcat 的下载页面的指示不是很清楚,当然技术文档也不甚详尽。但是h家已l给你提供了功能强大的open source 软gQ你q能抱怨什么呢Q要怪就怪的工夫没下刎ͼ功夫不够深?br />
仔细看,http://tomcat.apache.org/download-55.cgi Q?在下载页面的Binary Distributions栏下的第四大,Administration Web Application x?br />
W三步,当解压下载的Administration Web Application 文gQ比如放在c:\tom中,你会发现解压后的文g?c:\tom\apache-tomcat-5.5.17?q时键入 http://localhost:8080/admin L验adminQ会发现Tomcat什么都没有改变。因压的admin文gq没有配|到Tomcat 的系l中。下面的步骤告诉你如何将admin文g配置到Tomcat 的服务器中?br />
W四步,?c:\tom\apache-tomcat-5.5.17\conf\Catalina\localhost\admin.xml?br /> admin.xml 文g拯到c:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\Catalina\localhost. 的文件夹中。注意一定要攑֜正确的\径的文g夹中?br />
W五步,c:\tom\apache-tomcat-5.5.17\server\webapps中的admin整个文gҎ贝到c:\Program Files\Apache SoftwareFoundation\Tomcat5.5\server\webapps 文g夹中?br />
W六步,用具有编辑功能的notepad{打开 c:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\中的tomcat-users.xml 文g。在</tomcat-user>最后一行之前,加入下列一?br />
<user username="admin" password="tomcat" roles="admin,manager"/>

注意username/password可以是你喜欢的Q意组合,但roles=”admin” 不可随意改动?br />
W七步,重启Tomcat ServerQ然后打开http://127.0.0.1Q?080/q入manager里面把admin服务启动hQ然后再q入admin模块里,在web览器中键入 http://localhost:8080/adminQ?q时你如果能看到 Tomcat Server Web Administration Tool 的login界面Q?大功告成。若是还看不Cq页面,可检查浏览器的代理服务器的设定,使之能够接受localhost?

q打不开q下面的终极绝招!

目录: E:\Tomcat5.5\conf\web.xml
<!-- listings Should directory listings be produced if there -->
<!-- is no welcome file in this directory? [false] -->
<!-- WARNING: Listings for directories with many -->
<!-- entries can be slow and may consume -->
<!-- significant proportions of server resources. -->
<!-- -->
.....
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>
org.apache.catalina.servlets.DefaultServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
......
false --> true
q样可以浏览了Q不q整个Tomcat都是可以览Q有点危险?br /> 其他按你自q?
目录:E:\Tomcat5.5\conf\Catalina\localhost\jspweb.xml
<?xml version='1.0' encoding='utf-8'?>
<Context docBase="/c:/jspweb/" path="/jspweb">
</Context>
因该?.0一样了,不过你绝Ҏ费5.5的安全特?....
目录: E:\Tomcat5.5\conf\web.xml
<!-- listings Should directory listings be produced if there -->
<!-- is no welcome file in this directory? [false] -->
<!-- WARNING: Listings for directories with many -->
<!-- entries can be slow and may consume -->
<!-- significant proportions of server resources. -->
<!-- -->
.....
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>
org.apache.catalina.servlets.DefaultServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
......
false --> true
q样可以浏览了Q不q整个Tomcat都是可以览Q有点危险?br /> 其他按你自q?
目录:E:\Tomcat5.5\conf\Catalina\localhost\jspweb.xml
<?xml version='1.0' encoding='utf-8'?>
<Context docBase="/c:/jspweb/" path="/jspweb">
</Context>
因该?.0一样了,不过你绝Ҏ费5.5的安全特?....

目录: E:\Tomcat5.5\conf\web.xml
<!-- listings Should directory listings be produced if there -->
<!-- is no welcome file in this directory? [false] -->
<!-- WARNING: Listings for directories with many -->
<!-- entries can be slow and may consume -->
<!-- significant proportions of server resources. -->
<!-- -->
.....
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>
org.apache.catalina.servlets.DefaultServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
......
false --> true
q样可以浏览了Q不q整个Tomcat都是可以览Q有点危险?br /> 其他按你自q?
目录:E:\Tomcat5.5\conf\Catalina\localhost\jspweb.xml
<?xml version='1.0' encoding='utf-8'?>
<Context docBase="/c:/jspweb/" path="/jspweb">
</Context>
因该?.0一样了,不过你绝Ҏ费5.5的安全特?....



gdufo 2008-07-02 20:00 发表评论
]]>
վ֩ģ壺 | ƽ| | | | | | | | ̶| ƽ| | | | ׳| | | | пѷ| | | | | | ¡| | ѷ| ̩| | ɽ| | | üɽ| »| | | | | | ľ| γ|