My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads
Wiki pages
Links

Multi-Mechanize - web performance and load testing framework




View the presentation:

Performance and Scalability Testing with Python and Multi-Mechanize (slideshare.net)



What is Multi-Mechanize? (the framework)

Multi-Mechanize is an open source framework for API performance and load testing. It allows you to run simultaneous python scripts to generate load (synthetic transactions) against a web site or API/service.

In your scripts, you have the convenience of mechanize along with the power of the full Python programming language at your disposal. You programmatically create test scripts to simulate virtual user activity. Your scripts will then generate HTTP requests to intelligently navigate a web site or send requests to a web service.

Multi-Mechanize uses a multi-process, multi-threaded engine to replay your scripts and generate concurrent virtual users.

Results are saved in CSV format along with an HTML report containing stats and graphs.

  • Sample Results Reports: 1, 2, 3

Optionally, results can be saved as XML (J-Meter compatible .JTL format)

Optionally, results can be stored in a database:

You should be proficient with Python, HTTP, and performance/load testing to use multi-mechanize successfully.


What is python-mechanize? (scripting language: python + mechanize)

Mechanize is a Python module for stateful programmatic web browsing, used for automating interaction with websites. It is similar to WWW::Mechanize for Perl.

Test scripts are written in python using mechanize*.

Features include:

  • HTTP methods
  • high-level hyperlink and HTML form support
  • SSL support
  • automatic cookies
  • custom headers
  • redirections
  • proxies
  • HTTP authentication

* scripts can also be written using any of Python's web/network modules (httplib, urllib, socket) or any third-party modules


Quick Instructions

from the command line:

$ python multi-mechanize.py default_project

(this will run the mock project, which just generates random data)


Detailed Instructions

To begin, you can use the "default_project" supplied with the release. If you need to manage multiple projects, just create a directory for each one and copy the contents/structure of the default project. You will specify the project you are running on the command line when you invoke a test run.

Each project contains the following:

  • config.cfg: configuration file. set your test options
  • test_scripts: directory for virtual user scripts
  • results: directory for results storage. a timestamped directory is created for each test run and contains raw csv data, html summary report, and png image files

Steps:

  • make sure you have Python 2.6 or 2.7 installed
  • install mechanize for python ("easy_install mechanize" or get it from your OS package repository)
  • install matplotlib for python (this requires numpy)
  • create a project or use the default_project
  • create your virtual user scripts
  • configure multi-mechanize (config.cfg), setting global and user-group sections

Once your project is configured, you can run your test from the command line like this:

$ python multi-mechanize.py default_project

Multi-Mechanize config.cfg file

Here is a sample config file:

[global]
run_time: 300
rampup: 300
console_logging: on
results_ts_interval: 30

[user_group-1]
threads: 10
script: search_simple.py

[user_group-2]
threads: 5
script: search_complex.py

Developing Virtual User Scripts

script development guide: DevelopingScripts

more script examples: AdvancedScripts


Sample Scripts (Virtual User Transactions)

simple web request

import mechanize

class Transaction:
    def run(self):
        br = mechanize.Browser()
        br.set_handle_robots(False)
        resp = br.open('http://www.example.com/')
        resp.read()

web request with timer and assertions

import mechanize
import time


class Transaction:
    def run(self):
        self.custom_timers = {}

        br = mechanize.Browser()
        br.set_handle_robots(False)
        
        start_timer = time.time()
        resp = br.open('http://www.example.com/')
        resp.read()
        latency = time.time() - start_timer
        
        self.custom_timers['Example_Homepage'] = latency
        
        assert (resp.code == 200), 'Bad HTTP Response'
        assert ('Example Web Page' in resp.get_data()), 'Failed Content Verification'

Help / Discussion

Frequently Asked Questions: FAQ

Feel free to post a message to the discussion group.
questions, bugs, patches, collaboration, comments, welcome...

Google Groups
multi-mechanize
Visit this group



Corey Goldberg © 2010-2011
goldb.org

Powered by Google Project Hosting