locustfile_exportImage.py
Home
/
oregon /
locustfile_exportImage.py
# Purpose: Response times from exportImage REST Endpoint
from locust import HttpLocust, TaskSet, task
import random
import json
import locustEvents
import time
import webui
import resource
#resource.setrlimit(resource.RLIMIT_NOFILE, (999999, 999999))
# Host
service_host = "http://imagery.oregonexplorer.info"
# Routes for ArcGIS Server
routes = {
"1995": "/arcgis/rest/services/NAIP_1995/NAIP_1995_Dynamic/ImageServer/",
"2000": "/arcgis/rest/services/NAIP_2000/NAIP_2000_Dynamic/ImageServer/",
"2005": "/arcgis/rest/services/NAIP_2005/NAIP_2005_Dynamic/ImageServer/",
"2009": "/arcgis/rest/services/NAIP_2009/NAIP_2009_Dynamic/ImageServer/",
"2011": "/arcgis/rest/services/NAIP_2011/NAIP_2011_Dynamic/ImageServer/",
}
class UserBehavior(TaskSet):
extent=None
def on_start(self):
# @Assumption
# All services are same extent
if self.extent is None:
print "Grab Extent"
with self.client.post(routes['1995'],{'f':'json'}, catch_response=True) as response:
try:
params = json.loads(response.content)
except:
locustEvents.reqError.fire(message='Bad Response Content - Definition')
response.failure('Could not parse json')
return
self.extent = params['extent']
def baseQuery(self, route):
x1 = random.uniform(self.extent['xmin'], self.extent['xmax'])
x2 = random.uniform(x1, self.extent['xmax'])
y1 = random.uniform(self.extent['ymin'], self.extent['ymax'])
y2 = y1 + (x2-x1) #create a square envelope
queryData = {
'f': 'image',
'dpi': 96,
'transparent': 'true',
'bbox': ','.join(map(str, [x1, y1, x2, y2])),
'bboxSR': 2992,
'imageSR': 2992,
'size': '1908,612',
'format': 'jpeg'
}
qstr = "?"
val = None
for k,v in queryData.items():
if k =='geom':
val = json.dumps(geom)
else:
val = v
qstr += "%s=%s&"%(k, str(val))
qstr = qstr[0:-1]
self.client.get(route+'exportImage'+qstr, name=route)
@task(2)
def service1(self):
self.baseQuery(routes['1995'])
@task(3)
def service2(self):
self.baseQuery(routes['2000'])
@task(5)
def service3(self):
self.baseQuery(routes['2005'])
@task(10)
def service4(self):
self.baseQuery(routes['2009'])
@task(80)
def service5(self):
self.baseQuery(routes['2011'])
class WebsiteUser(HttpLocust):
host = service_host
task_set = UserBehavior
# Assume most users wait about 0.3 - 5 seconds between requests
# when browsing imagery
min_wait = 0.3 * 1000
max_wait = 5 * 1000