~ubuntu-branches/ubuntu/trusty/mapcache/trusty

« back to all changes in this revision

Viewing changes to benchmark.py

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2013-09-11 19:16:06 UTC
  • Revision ID: package-import@ubuntu.com-20130911191606-9aydo919w4dgjx9v
Tags: upstream-1.2.0
ImportĀ upstreamĀ versionĀ 1.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
 
 
3
import commands
 
4
import os
 
5
import re
 
6
 
 
7
def do_ab_call(url,nthreads,reqs):
 
8
    cmd="ab -k -c %d -n %d '%s'" % (nthreads,reqs,url)
 
9
    print cmd
 
10
    summary={}
 
11
    ret = commands.getoutput(cmd)
 
12
    sList = ret.split(os.linesep)
 
13
    for i, line in enumerate(sList):
 
14
        if re.match("Requests per second", line) is not None:
 
15
            val = line.split()
 
16
            summary['reqspersec']=val[3]
 
17
        if re.match("Document Length", line) is not None:
 
18
            val = line.split()
 
19
            summary['size']=val[2]
 
20
    return summary
 
21
 
 
22
base="http://localhost:8081"
 
23
params="LAYERS=test,test3&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=-2.8125,47.8125,0,50.625&WIDTH=256&HEIGHT=256"
 
24
urls={}
 
25
nreqs=400
 
26
 
 
27
title="tile merging"
 
28
filebase=title
 
29
 
 
30
urls['tilecache']="%s/%s?%s" % (base,'tilecache',params)
 
31
urls['mapcache best compression']="%s/%s?%s" % (base,'mapcache-best',params)
 
32
urls['mapcache default compression']="%s/%s?%s" % (base,'mapcache-default',params)
 
33
urls['mapcache fast compression']="%s/%s?%s" % (base,'mapcache-fast',params)
 
34
urls['mapcache png quantization']="%s/%s?%s" % (base,'mapcache-pngq',params)
 
35
#urls['mapproxy']="http://localhost:8080/service?%s" % (params)
 
36
 
 
37
plotfile = open("%s.plot"%(filebase),"w")
 
38
datafile = open("%s.dat"%(filebase),"w")
 
39
 
 
40
plotfile.write("set terminal pdf\nset key autotitle columnhead\nset output \"%s.pdf\"\nset style data lines\n"%(filebase))
 
41
plotfile.write("set xlabel \"concurrent requests\"\n")
 
42
plotfile.write("set ylabel \"throughput (requests/sec)\"\n")
 
43
plotfile.write("set title \"%s\"\n"%(title))
 
44
count=0
 
45
for title,url in urls.iteritems():
 
46
    if count == 0:
 
47
        plotfile.write("plot \"%s.dat\" using 2:xticlabel(1) index 0"%(filebase))
 
48
    else:
 
49
        plotfile.write(",\"\" using 2 index %d"%(count))
 
50
    count += 1
 
51
    for nthreads in [1,2,3,4]:
 
52
        reqs = min(nthreads,4) * nreqs
 
53
        res = do_ab_call(url,nthreads,reqs)
 
54
        if nthreads == 1:
 
55
            datafile.write("\n\nthreads \"%s (%s bytes)\"\n"%(title,res['size']))
 
56
        datafile.write("%d %s\n"%(nthreads,res['reqspersec']))
 
57
plotfile.write("\n")
 
58