Skip to content

Instantly share code, notes, and snippets.

@tkardi
Created May 9, 2018 09:13
Show Gist options
  • Save tkardi/353172f7b61f8dd45512d522797dcb38 to your computer and use it in GitHub Desktop.
Save tkardi/353172f7b61f8dd45512d522797dcb38 to your computer and use it in GitHub Desktop.
Benchmarking GeoServer WMS 1.3.0/1.1.1 version differences using the same dataset in different native SRS
import argparse
import requests
from PIL import Image
from io import BytesIO
URL = 'http://localhost:8080/geoserver/test/ows?'
params = {
'service':'wms',
'request':'getmap',
'format': 'image/png',
'styles':'point',
'transparent':'true',
'width': 768,
'height':486
}
layerparams = {
'puurkaev_3301' : {
'layers':'puurkaev_3301',
'EPSG': 3301,
'minx': 320676.1358612784,
'miny': 6349387.490053313,
'maxx': 789779.5117497771,
'maxy': 6646241.970107753
},
'puurkaev_3035' : {
'layers':'puurkaev_3035',
'EPSG': 3035,
'minx': 4953071.972760203,
'miny': 3888121.7958570817,
'maxx': 5422175.348648702,
'maxy': 4208797.93171836
},
'puurkaev_4326': {
'layers':'puurkaev_4326',
'EPSG': 4326,
'minx': 20.7861328125,
'miny': 56.788330078125,
'maxx': 29.2236328125,
'maxy': 60.413818359375
},
'puurkaev_4326_3301': {
'layers':'puurkaev_4326',
'EPSG': 3301,
'minx': 320676.1358612784,
'miny': 6349387.490053313,
'maxx': 789779.5117497771,
'maxy': 6646241.970107753
}
}
def layer_params_by_version(fname, v):
assert v in ['1.0.0', '1.1.0', '1.1.1', '1.3.0'], 'Unknown version: %s' % v
lparams = layerparams[fname]
p = {'layers':lparams['layers'], 'version':v}
if v == '1.3.0':
p['crs'] = 'EPSG:%s' % lparams['EPSG']
p['bbox'] = ','.join(['%s' % lparams[k] for k in ['miny','minx','maxy','maxx']])
else:
p['srs'] = 'EPSG:%s' % lparams['EPSG']
p['bbox'] = ','.join(['%s' % lparams[k] for k in ['minx','miny','maxx','maxy']])
return p
def getmap(fname, saveimg=False, **kwargs):
r = requests.get(URL, params=kwargs)
r.raise_for_status()
# SAVE THE IMAGE
# but only if requested
if saveimg:
i = Image.open(BytesIO(r.content))
filename = 'output/%s_%s.png' % (fname, kwargs['version'])
i.save(filename )
if __name__ == '__main__':
parser = argparse.ArgumentParser(prog='benchmarking')
parser.add_argument(
'-N', '--number', help=u"Number of times to run the query.",
type=int, default='10')
parser.add_argument(
'-S', '--save', help=u"Save image: y|n",
type=str, default='n')
args = parser.parse_args()
num = args.number
saveimg = args.save.lower() == 'y'
import timeit, functools
for fname in ['puurkaev_3301', 'puurkaev_3035', 'puurkaev_4326', 'puurkaev_4326_3301']:
for version in ['1.1.1', '1.3.0']:
p = layer_params_by_version(fname, version)
q = params.copy()
q.update(p)
print '***'
print fname, version, 'running %s times' % num
print 'REQUEST: %s%s' % (URL, '&'.join(['%s=%s' % (k, v) for k, v in q.items()]))
t = timeit.Timer(functools.partial(getmap, fname, saveimg, **q))
print 'AVG for %s reqs: %s sec' % (num, t.timeit(num)/num,)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment