??xml version="1.0" encoding="utf-8" standalone="yes"?>
最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箋几天休息不好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配|虚拟站点,在最下面加上
然后回到httpd.confQ在文档最下面加上
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>
在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>
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.
We will be using the "shopping cart" example from ZK Essentials as the template application to perform the stress test.
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.
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:
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(); } |
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 ; } } |
Then, define your IdGenerator in zk.xml, for example,
1 2 3 | < system-config > < id-generator-class >foo.MyIdgenerator</ id-generator-class > </ system-config > |
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.
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.
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.
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.
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)}.
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).
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.
Now we have completed all the settings and have saved these configurations as test.jmx.
Now we are ready to start the application and to run the test.
Start your web server, and access login.zul. Click createUserBtn for creating multiple accounts.
You can then observe the average response time, 90% line response time, median response time and other results by accessing the Aggregate Report .
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.
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.
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 > |
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:
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
?
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">要保证文件不是只ȝ
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的安全特?....