Multi-Mechanize
is an open source framework for performance and load testing. It runs concurrent Python scripts to generate load (synthetic transactions) against a remote site or service. Test output reports are saved as HTML or JMeter-compatible XML.
I will use pip
to install the package but you can download the source and install it manually:
(bicofino.io)danilochilene@undead:~$ pip install multi-mechanize
Downloading/unpacking multi-mechanize
Downloading multi-mechanize-1.2.0.tar.gz
Running setup.py egg_info for package multi-mechanize
Downloading/unpacking Mechanize (from multi-mechanize)
Downloading mechanize-0.2.5.tar.gz (383kB): 383kB downloaded
Running setup.py egg_info for package Mechanize
Installing collected packages: multi-mechanize, Mechanize
Running setup.py install for multi-mechanize
Installing multimech-run script to /home/danilochilene/envs/bicofino.io/bin
Installing multimech-newproject script to /home/danilochilene/envs/bicofino.io/bin
Installing multimech-gridgui script to /home/danilochilene/envs/bicofino.io/bin
Running setup.py install for Mechanize
Successfully installed multi-mechanize Mechanize
Cleaning up...
(bicofino.io)danilochilene@undead:~$
Install matplotlib to generate graphics
danilochilene@undead:~$ sudo apt-get install python-matplotlib
Create our test project
The name of our project will be weather
since the goal of it is to check weather though a webservice:
danilochilene@undead:~$ multimech-newproject weather
danilochilene@undead:~$ cd weather/
danilochilene@undead:~/weather$ find .
.
./config.cfg
./test_scripts
./test_scripts/v_user.py
config.cfg config file, you can set your options here
./test_scripts -> directory with your test scripts
./results -> results
Every new project you create come with a default script in test_scripts/v_user.py
you can use it as a template to create your own.
Below it's content
import random
import time
class Transaction(object):
def __init__(self):
pass
def run(self):
r = random.uniform(1, 2)
time.sleep(r)
self.custom_timers['Example_Timer'] = r
if __name__ == '__main__':
trans = Transaction()
trans.run()
print trans.custom_timers
Every test script must have a Transaction
class.
We are going to use Suds here which is a lightweight SOAP
python client for consuming Web Services. For more information about it please access https://fedorahosted.org/suds/
danilochilene@undead:~/weather$ sudo pip install suds
[sudo] password for danilochilene:
Downloading/unpacking suds
Downloading suds-0.4.tar.gz (104kB): 104kB downloaded
Running setup.py egg_info for package suds
Installing collected packages: suds
Running setup.py install for suds
/usr/bin/python -O /tmp/tmpgAvTwm.py
removing /tmp/tmpgAvTwm.py
Successfully installed suds
Cleaning up...
Below our test script that checks the weather using the webservice http://www.deeptraining.com/webservices/weather.asmx?WSDL
Keep in mind that the webservice isn’t real it just returns random results like: Rain, Sunny, Clooudy, etc. The main idea is just use it for testing purposes.
danilochilene@undead:~/weather/test_scripts$ cat weather.py
#!/usr/bin/env python
from suds.client import *
class Transaction(object):
def run(city):
city = 'New York'
url = 'http://www.deeptraining.com/webservices/weather.asmx?WSDL'
client = Client(url)
result = client.service.GetWeather(city)
print result
if __name__ =='__main__':
trans = Transaction()
trans.run()
Lets run it to check if it’s working:
danilochilene@undead:~/weather/test_scripts$ python weather.py
Sunny
Remove the default script v_user.py
since we are not going to use it:
danilochilene@undead:~/weather/test_scripts$ rm -f v_user.py
Edit the file config.cfg
inside the directory weather to match below:
[global]
run_time = 30
rampup = 0
results_ts_interval = 10
progress_bar = on
console_logging = off
xml_report = on
[weather]
threads = 3
script = weather.py
Lets run the test
danilochilene@undead:~$ multimech-run weather
user_groups: 1
threads: 3
[================100%==================] 30s/30s transactions: 224 timers: 0 errors: 0
analyzing results...
transactions: 227
errors: 0
test start: 2013-05-18 19:48:47
test finish: 2013-05-18 19:49:16
created: ./weather/results/results_2013.05.18_19.48.46/results.html
created: ./weather/results/results_2013.05.18_19.48.46/results.jtl
created: last_results.jtl
It worked. :)
Lets take a look at the results:
In case of any error you can activate the option console_logging at config.cfg
.
Multi-mechanize
is a powerfull and yet simple framework to performance test, for more information access http://testutils.org/multi-mechanize/
If you have any questions feel encouraged to comment. :)