locustfile_exportImage.py

113 lines | 3.265 kB Blame History Raw Download
# 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://arcgis-stateoregongeocluster-1571505066.us-west-2.elb.amazonaws.com"
# Routes for ArcGIS Server
routes = {
    "1995": "/arcgis/rest/services/NAIP_1995/NAIP_1995_SL/ImageServer/",
    "2000": "/arcgis/rest/services/NAIP_2000/NAIP_2000_SL/ImageServer/",
    "2005": "/arcgis/rest/services/NAIP_2005/NAIP_2005_SL/ImageServer/",
    "2009": "/arcgis/rest/services/NAIP_2009/NAIP_2009_SL/ImageServer/",
    "2011": "/arcgis/rest/services/NAIP_2011/NAIP_2011_SL/ImageServer/",
    "2012": "/arcgis/rest/services/NAIP_2012/NAIP_2012_SL/ImageServer/",
    "2014": "/arcgis/rest/services/NAIP_2014/NAIP_2014_SL/ImageServer/",
    "2016": "/arcgis/rest/services/NAIP_2016/NAIP_2016_SL/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': 102100,
            'imageSR': 102100,
            'size': '1160, 578',
            'format': 'png8'
        }

        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(3)
    def service1(self):
        self.baseQuery(routes['1995'])

    @task(3)
    def service2(self):
        self.baseQuery(routes['2000'])

    @task(3)
    def service3(self):
        self.baseQuery(routes['2005'])

    @task(3)
    def service4(self):
        self.baseQuery(routes['2009'])

    @task(3)
    def service5(self):
        self.baseQuery(routes['2011'])

    @task(5)
    def service5(self):
        self.baseQuery(routes['2012'])

    @task(10)
    def service5(self):
        self.baseQuery(routes['2014'])

    @task(70)
    def service5(self):
        self.baseQuery(routes['2016'])

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