performance / tuning tips. to the point.                
About Us | Site Map | Privacy
Disclaimer | Feedback
About RSS Feed
Add to My Yahoo!
Google Reader or Homepage
del.icio.us performancewiki.com Latest Items


© 2006-2007 PerformanceWiki.com
All Rights Reserved.







Automate Performance Testing With STAF and JMETER - Part 4 / 4



Step 4. Tying Everything Together with STAF

Now you have JMeter, nmon/perfmon, and STAF installed and working, it is time to tie the pieces together to automate your performance testing. Let's assume you have the following high-level tasks for each performance test (assuming a 3-tier application setup: Web server, App Server, and Database):


1. Make sure all servers are alive
2. Shutdown all test driver processes (e.g., jmeter itself)
3. Stop all resource monitoring processes (e.g., nmon or perfmon)
4. Shutdown all Web servers (e.g., httpd)
5. Shutdown all Application servers (e.g., websphere or weblogic)
6. Shutdown all Database servers (e.g., db2, oracle, mysql)
7. Clean up all logs (e.g., web server access log, resource monitoring logs, app logs)
8. Restore baseline copies of database, file systems (e.g., a database with 1 million records)
9. Restart all Database servers
10. Restart all Application servers
11. Restart all Web servers
12. Start resource monitoring for a given interval (e.g., nmon -f -s 15 -c 240 for one hour)
13. Start all test drivers with specific number of concurrent users
14. When test is done, copy all logs from all servers to test controller
15. Run post-processing (e.g., generate reports, update web site with stats, email results to someone)

You can choose any of the servers to be the controller - where you control all programs in your performance test - here is batch file code for running on Windows (I am sure you can easily port it over to Unix shell). Note: \\ is used to break long lines for better display:

REM automated staf script to drive prep, test, and post-processing
REM on a 3-tier application.
REM Copyright 2006 www.performancewiki.com All Rights Reserved.
REM Free to use and modify with credit.
REM ---

REM *********************************************************************************
REM global variables: hostnames, duration, scenario names, etc
REM *********************************************************************************

set duration=3600

REM ** assume lglist is linux, wslist and aslist are windows, and dblist is aix

SET controller=c1
SET lglist=loadgenerator1 loadgenerator2
SET wslist=webserver1 webserver2 webserver3 webserver4
SET aslist=appserver1 appserver2
SET dblist=dbserver1

SET scenario=pw-perfscenario1.jmx

REM *********************************************************************************
REM STAF ping ok?
REM *********************************************************************************

time /t

FOR %%H IN (%wslist% %aslist% %dblist% %lglist%) DO staf %%H ping ping

REM *********************************************************************************
REM shutdown test drivers if any - always start with nothing running
REM *********************************************************************************

time /t

FOR %%H IN (%lglist%) DO staf %%H process start shell command /mytools/automation/stopjmeter.sh \\
wait returnstdout returnstderr

REM *********************************************************************************
REM stop all resource collections if any left over
REM *********************************************************************************

time /t

FOR %%H IN (%lglist% %dblist%) DO staf %%H process  start shell command /mytools/stopnmon.sh \\
wait returnstdout returnstderr
FOR %%H IN (%lglist% %dblist%) DO staf %%H process  start shell command rm parms "-f /mytools/*.nmon \\
wait returnstdout returnstderr 
FOR %%H IN (%wslist% %aslist%) DO logman stop perf -s %%H

REM *********************************************************************************
REM Clean up logs...
REM *********************************************************************************

FOR %%H IN (%controller%) DO staf %%H process start shell command del parms c:\mytools\automation\logs\%%H
FOR %%H IN (%wslist% %aslist%) DO staf %%H process start shell command del parms "/F C:\mytools\logs\*.log" \\
wait returnstdout returnstderr
FOR %%H IN (%lglist% %dblist%) DO staf %%H process start shell command rm parms "-f /mytools/logs/*.log" \\
wait returnstdout returnstderr


REM *********************************************************************************
REM start resource collectors on all machines
REM *********************************************************************************

time /t

FOR %%H IN (%lglist% %dblist%) DO staf %%H process start shell command /mytools/nmon parms "-f -s 15 -c 240" \\
WORKDIR /mytools
FOR %%H IN (%wslist% %aslist%) DO logman start perf -s %%H


REM *********************************************************************************
REM start the tests...
REM *********************************************************************************

time /t

FOR %%H IN (%lglist%) DO sleep 5 & staf %%H process start shell command \\
/mytools/util/jakarta-jmeter-2.1.1/bin/jmeter.lucene parms " -n -t %scenario% -l %scenario%.log" \\
WORKDIR "/mytools/util/jakarta-jmeter-2.1.1"

REM *********************************************************************************
REM post processing
REM *********************************************************************************

time /t

REM stop all processes before copying logs...
REM if the awk command doesn't work below, simply create a .sh on those remote hosts, then call it

FOR %%H IN (%lglist%) DO staf %%H process start shell command kill parms "-9 `ps -ef | grep -v grep\\
 | grep jmeter| awk '{print $2}'`" wait returnstdout returnstderr

REM stop all resource collections

REM get reports and log files...

FOR %%H IN (%controller%) DO staf %%H fs copy directory "/mytools/util/jakarta-jmeter-2.1.1" \\
todirectory c:\mytools\automation\logs\ tomachine %controller% EXT log CASEINSENSITIVE

REM get resource files

FOR %%H IN (%lglist%) DO staf %%H process start shell command mv parms "/mytools/*.nmon /mytools/jmeter.nmon"  \\
WORKDIR /mytools
FOR %%H IN (%lglist%) DO staf %%H fs copy file "/mytools/jmeter.nmon" tofile \\
c:\mytools\automation\logs\%%H.nmon tomachine %controller%
goto end

REM generate the report...
cd /d c:\mytools\automation
REM do post-processing here: parse logs, create html, email, etc. do your thing
		
	

The script is easy, as you can see, but the hard part if to get those scripts under /mytools ready, and get database or file systems loaded before running the test. In other words, there are preparation work here, but the good news those are done only once. But your tests run multiple times until your management is satisficed with the performance of your application.

You see the power of STAF. If you look at STAX (extention to STAF), you will discover more things you can do: cron, email, HTTP sessions, and more. We will create more articles when results are available.

    Page 1    Page 2    Page 3    Page 4