Skip to content

Instantly share code, notes, and snippets.

@geographika
Created August 24, 2016 21:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save geographika/55b8f4c6ae721ce8f7986c3da790bcf6 to your computer and use it in GitHub Desktop.
Save geographika/55b8f4c6ae721ce8f7986c3da790bcf6 to your computer and use it in GitHub Desktop.
Sample OWS user for Locust
"""
To run, edit layer name, host, application path and bounding boxes.
Then:
locust -f ows_user.py --host=http://ubuntu-mapserver
http://localhost:8089
"""
from locust import HttpLocust, TaskSet, task
class OWSTaskSet(TaskSet):
def on_start(self):
self.layer = 'MyLayer'
self.app = "/cgi-bin/mapserv?"
def get_response(self, name, params):
with self.client.get(self.app, params=params, verify=False,
name=name, catch_response=True) as response:
if response.headers['content-type'] == 'application/vnd.ogc.se_xml':
# if MapServer returns an error then log this with Locust
response.failure(response.content)
@task(1)
def get_wfs_featurecount(self):
"""
Only supported by WFS 1.1.0 not 1.0.0
"""
params = {'SERVICE': 'WFS', 'VERSION': '1.1.0', 'REQUEST': 'GetFeature', 'resultType': 'hits'}
params["TYPENAME"] = self.layer
self.get_response("GetFeature_%s" % self.layer, params)
@task(1)
def get_wms_legendgraphic(self):
params = {u'EXCEPTIONS': u'application/vnd.ogc.se_xml', u'FORMAT': u'image/png',
u'LAYER': self.layer, u'REQUEST': u'GetLegendGraphic', u'SERVICE':
u'WMS', u'TRANSPARENT': u'TRUE', u'VERSION': u'1.1.1'}
self.get_response("GetLegendGraphic_%s" % self.layer, params)
@task(3)
def get_map_layer(self):
params_list = [
{u'BBOX': u'-860986.68725,7122708.04165,-821850.928775,7161843.800125', u'FORMAT': u'image/png', u'HEIGHT': u'256', u'LAYERS': self.layer, u'REQUEST': u'GetMap', u'SERVICE': u'WMS', u'SRS': u'EPSG:3857', u'TRANSPARENT': u'TRUE', u'VERSION': u'1.1.1', u'WIDTH': u'256'},
{u'BBOX': u'-821850.928775,7083572.283175,-782715.1703,7122708.04165', u'FORMAT': u'image/png', u'HEIGHT': u'256', u'LAYERS': self.layer, u'REQUEST': u'GetMap', u'SERVICE': u'WMS', u'SRS': u'EPSG:3857', u'TRANSPARENT': u'TRUE', u'VERSION': u'1.1.1', u'WIDTH': u'256'},
{u'BBOX': u'-821850.928775,7200979.5586,-782715.1703,7240115.317075', u'FORMAT': u'image/png', u'HEIGHT': u'256', u'LAYERS': self.layer, u'REQUEST': u'GetMap', u'SERVICE': u'WMS', u'SRS': u'EPSG:3857', u'TRANSPARENT': u'TRUE', u'VERSION': u'1.1.1', u'WIDTH': u'256'},
{u'BBOX': u'-821850.928775,7161843.800125,-782715.1703,7200979.5586', u'FORMAT': u'image/png', u'HEIGHT': u'256', u'LAYERS': self.layer, u'REQUEST': u'GetMap', u'SERVICE': u'WMS', u'SRS': u'EPSG:3857', u'TRANSPARENT': u'TRUE', u'VERSION': u'1.1.1', u'WIDTH': u'256'},
{u'BBOX': u'-821850.928775,7122708.04165,-782715.1703,7161843.800125', u'FORMAT': u'image/png', u'HEIGHT': u'256', u'LAYERS': self.layer, u'REQUEST': u'GetMap', u'SERVICE': u'WMS', u'SRS': u'EPSG:3857', u'TRANSPARENT': u'TRUE', u'VERSION': u'1.1.1', u'WIDTH': u'256'},
{u'BBOX': u'-1017529.72115,7083572.283175,-978393.962675,7122708.04165', u'FORMAT': u'image/png', u'HEIGHT': u'256', u'LAYERS': self.layer, u'REQUEST': u'GetMap', u'SERVICE': u'WMS', u'SRS': u'EPSG:3857', u'TRANSPARENT': u'TRUE', u'VERSION': u'1.1.1', u'WIDTH': u'256'},
{u'BBOX': u'-978393.962675,7083572.283175,-939258.2042,7122708.04165', u'FORMAT': u'image/png', u'HEIGHT': u'256', u'LAYERS': self.layer, u'REQUEST': u'GetMap', u'SERVICE': u'WMS', u'SRS': u'EPSG:3857', u'TRANSPARENT': u'TRUE', u'VERSION': u'1.1.1', u'WIDTH': u'256'},
{u'BBOX': u'-939258.2042,7083572.283175,-900122.445725,7122708.04165', u'FORMAT': u'image/png', u'HEIGHT': u'256', u'LAYERS': self.layer, u'REQUEST': u'GetMap', u'SERVICE': u'WMS', u'SRS': u'EPSG:3857', u'TRANSPARENT': u'TRUE', u'VERSION': u'1.1.1', u'WIDTH': u'256'},
{u'BBOX': u'-860986.68725,7083572.283175,-821850.928775,7122708.04165', u'FORMAT': u'image/png', u'HEIGHT': u'256', u'LAYERS': self.layer, u'REQUEST': u'GetMap', u'SERVICE': u'WMS', u'SRS': u'EPSG:3857', u'TRANSPARENT': u'TRUE', u'VERSION': u'1.1.1', u'WIDTH': u'256'}
]
for params in params_list:
self.get_response("GetMap_%s" % self.layer, params)
class OWSUser(HttpLocust):
task_set = OWSTaskSet
min_wait = 5000 # minimum time between user requests
max_wait = 15000 # maximum time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment