Skip to content

Instantly share code, notes, and snippets.

@bbinet
Created October 2, 2012 15:58
Show Gist options
  • Save bbinet/3820391 to your computer and use it in GitHub Desktop.
Save bbinet/3820391 to your computer and use it in GitHub Desktop.
funkload_bench

Installation steps

$ sudo apt-get install gnuplot
$ curl -s https://raw.github.com/brainsik/virtualenv-burrito/master/virtualenv-burrito.sh | $SHELL
$ mkvirtualenv -r requirements.txt funkload_benchs

Launch benchs

To actually launch the benchs, you can use the following command (html benchs reports will be generated in ./results directory):

(funkload_benchs) $ fab load
from fabric.api import local
from fabric.decorators import runs_once
def _getlist(raw, separator='\n'):
"""Return a list (multiline) from the configuration file."""
return [item.strip() for item in raw.split(separator) if item]
@runs_once
def _config():
from ConfigParser import RawConfigParser
config = RawConfigParser()
config.readfp(open('Load.conf'))
return config
def _get_urls():
config = _config()
url_sections = _getlist(config.get('main', 'url_sections'))
urls = []
for usection in url_sections:
urls += [(usection, key, url) for key, url in config.items(usection)]
return urls
def load_one(url, name=None, dirname=None):
import os
from hashlib import md5
### workaround varnish ###################################################
# from urlparse import urlparse, urlunparse, parse_qsl
# from urllib import urlencode
# from uuid import uuid4
# url_parts = list(urlparse(url))
# query = dict(parse_qsl(url_parts[4]))
# query.update({uuid4().hex: 0})
# url_parts[4] = urlencode(query)
# local("taskset -c 0 fl-run-bench --simple-fetch test_load.py "
# "Load.test_load -u \"%s\"" % urlunparse(url_parts))
##########################################################################
local("taskset -c 0 fl-run-bench --simple-fetch "
"test_load.py Load.test_load -u \"%s\"" % url)
config = _config()
reports_dir = config.get('main', 'reports_dir')
dirname = os.path.join(reports_dir, dirname) if dirname else dirname
name = name if name else md5(url).hexdigest()[0:10]
local("mkdir -p \"%s\"" % dirname)
local("fl-build-report load-bench.xml --html -r \"%s\""
% os.path.join(dirname, name))
def load(url=None, name=None, dirname=None):
if url: return load_one(url, name, dirname) # NOQA
for section, key, url in _get_urls():
load_one(url, name=key, dirname=section)
# FunkLoad test configuration file
# $Id: $
# ------------------------------------------------------------
# Main section
#
[main]
title=Load FunkLoad tests
description=Simply testing a default static page
reports_dir = results
# the server url to test
url=http://localhost/index.html
url_sections =
wsgi_pages
viewer
amazon_tiles
mapcache_tiles
wms_overlays
wms_basemaps
# mapcache_tiles_uncached
# the User-Agent header to send
#user_agent = Mozilla/5.0 Firefox/1.0.6
[wsgi_pages]
index_page = http://ref.geoview.bl.ch/
[viewer]
viewer.js = http://ref.geoview.bl.ch/main/wsgi/viewer.js
[amazon_tiles]
# tiles hosted on Amazon
amazon_tile = http://tile0.geo.bl.ch/1.0.0/grundkarte_farbig/default/2011/swissgrid/19/5/9.png
[mapcache_tiles]
# tiles served by Mapcache/Tilecache: cached or generated on-the-fly
grundkarte_farbig = http://ref.geoview.bl.ch/main/mapcache/wmts/1.0.0/grundkarte_farbig/default/2011/swissgrid/28/615/1260.png
grundkarte_sw = http://ref.geoview.bl.ch/main/mapcache/wmts/1.0.0/grundkarte_sw/default/2011/swissgrid/28/619/1256.png
dtm_av_relief_02m = http://ref.geoview.bl.ch/main/mapcache/wmts/1.0.0/dtm_av_relief_02m/default/200703/swissgrid/28/613/1257.png
richtplan = http://ref.geoview.bl.ch/main/mapcache/wmts/1.0.0/richtplan/default/20100908/swissgrid/28/615/1256.png
[wms_overlays]
# WMS requests for overlays, depending on the zoomlevel and the layer name
# (all available layers should be tested to identify potentially slow layers)
reptilieninventar = http://ref.geoview.bl.ch/main/wsgi/mapserv_proxy?LAYERS=reptilieninventar&FORMAT=image%2Fpng&TRANSPARENT=TRUE&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&SRS=EPSG%3A2056&BBOX=2621157.004,1259057.004,2623290.004,1260794.004&WIDTH=1422&HEIGHT=1158
[wms_basemaps]
# WMS requests for tiled layers (for instance basemaps):
# for basemaps composed of a group of mapserver layers (for instance
# "grundkarte_farbig"), it would be interesting to check all those mapserver
# layers separately to identify potentially slow layers example for
# grundkarte_farbig (note: all layers from a given basemaps are not displayed for
# all the resolutions): the list of layers composing a basemap is available in
# buildout.cfg or in apache/mapcache.xml
boflaeche = http://ref.geoview.bl.ch/main/wsgi/mapserv_proxy?LAYERS=boflaeche&FORMAT=image%2Fpng&TRANSPARENT=TRUE&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&SRS=EPSG%3A2056&BBOX=2621157.004,1259057.004,2623290.004,1260794.004&WIDTH=1422&HEIGHT=1158
grundkarte_farbig_group = http://ref.geoview.bl.ch/main/wsgi/mapserv_proxy?LAYERS=grundkarte_farbig_group&FORMAT=image%2Fpng&TRANSPARENT=TRUE&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&SRS=EPSG%3A2056&BBOX=2621157.004,1259057.004,2623290.004,1260794.004&WIDTH=1422&HEIGHT=1158
[mapcache_tiles_uncached]
# tiles served by Mapcache/Tilecache: cached or generated on-the-fly
grundkarte_farbig = http://ref.geoview.bl.ch/main/mapcache/wmts/1.0.0/grundkarte_farbig/default/2011/swissgrid/28/615/1260.png
# ------------------------------------------------------------
# Tests description and configuration
#
[test_load]
description=Access %(nb_time)s times
nb_time=5
# ------------------------------------------------------------
# Credential access
#
[credential]
# host=localhost
# port=8007
# ------------------------------------------------------------
# Monitoring configuration
#
[monitor]
# hosts=localhost
# Each host in [monitor]hosts should have a section
# with a 'port' and 'description' keys
# [localhost]
# port=8008
# description=The benching and benched machine
# ------------------------------------------------------------
# Configuration for unit test mode fl-run-test
#
[ftest]
# log_to destination =
# console - to the screen
# file - to a file
log_to = console file
# log_path = path and file name to store log file
log_path = load-test.log
# result_path = path to store the xml result file
result_path = load-test.xml
# ok_codes = list of successfull HTTP response code
#ok_codes = 200:301:302
# sleeptime_min = minimum amount of time in seconds to sleep between requests
# to the host
sleep_time_min = 0
# sleeptime_max = maximum amount of time in seconds to sleep between requests
# to the host
sleep_time_max = 0
# ------------------------------------------------------------
# Configuration for bench mode fl-run-bench
#
[bench]
# cycles = list of cycles with their number of concurrent users
cycles = 1:3:6:9
# duration = duration of a cycle in seconds
duration = 40
# startup_delay = time to wait between starting-up threads in seconds
startup_delay = 0.01
# sleep_time = time to wait between test in seconds
sleep_time = 0.01
# cycle_time = time to wait between cycle in seconds
cycle_time = 1
# same keys than in [ftest] section
log_to =
log_path = load-bench.log
result_path = load-bench.xml
#ok_codes = 200:301:302
sleep_time_min = 0
sleep_time_max = 0.5
[distribute]
log_path = log-distributed
funkload_location=http://pypi.python.org/packages/source/f/funkload/funkload-1.16.1.tar.gz
-e git+https://github.com/nuxeo/FunkLoad.git#egg=funkload-1.17.0
Fabric
# -*- coding: iso-8859-15 -*-
"""load FunkLoad test
$Id$
"""
import unittest
from funkload.FunkLoadTestCase import FunkLoadTestCase
class Load(FunkLoadTestCase):
"""This test use a configuration file load.conf."""
def setUp(self):
"""Setting up test."""
self.server_url = self.conf_get('main', 'url')
def test_load(self):
server_url = self.server_url
nb_time = self.conf_getInt('test_load', 'nb_time')
for i in range(nb_time):
self.get(server_url, description='Get url: %s' % server_url)
if __name__ in ('main', '__main__'):
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment