Skip to content

Instantly share code, notes, and snippets.

@ashokc
Created February 16, 2020 19:45
Show Gist options
  • Save ashokc/19e6939c9c95cb3bafa1f5c9a79e4759 to your computer and use it in GitHub Desktop.
Save ashokc/19e6939c9c95cb3bafa1f5c9a79e4759 to your computer and use it in GitHub Desktop.
from locust import HttpLocust, TaskSet, task, between
import random, sys, json
# We have 7 ways of engaging the API via Http
url = "http://localhost/gunicorn/quotes" # for nginx + gunicorn
#url = "http://localhost/uwsgi/quotes" # for nginx + uwsgi
#url = "http://localhost/uwsgi-http/quotes" # for nginx + uwsgi-http
#url = "http://localhost/werkzeug/quotes" # for nginx + werkzeug
#url = "http://localhost:9999/quotes" # for direct gunicorn
#url = "http://localhost:9997/quotes" # for direct uwsgi-http
#url = "http://localhost:9996/uwsgi/quotes" # for direct werkzeug
class UserBehaviour(TaskSet):
@task(1)
def getAQuote (self):
quoteId = random.randint(1,900000)
self.client.get(url + "/byId?id="+str(quoteId))
class WebsiteUser(HttpLocust):
task_set = UserBehaviour
wait_time = between(1, 3) # wait between 1 - 3 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment