locustfile.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import random
  2. from os import environ
  3. from uuid import uuid4
  4. import requests
  5. from locust import HttpLocust, TaskSet, task
  6. from rdflib import Graph, URIRef
  7. from lakesuperior.util.generators import random_graph, random_image
  8. ldp_root = environ.get(
  9. 'FCREPO_BENCHMARK_ROOT', 'http://localhost:8000/ldp/pomegranate'
  10. )
  11. print('Retrieving LDP graphs. Be patient, this may take a while...')
  12. rsp = requests.request('GET', ldp_root)
  13. root_gr = Graph().parse(data=rsp.text, format='ttl')
  14. subjects = {*root_gr.objects(
  15. None, URIRef('http://www.w3.org/ns/ldp#contains')
  16. )}
  17. class Graph(TaskSet):
  18. @task(1)
  19. def ingest_graph(self):
  20. uri = f'{ldp_root}/{uuid4()}'
  21. data = random_graph(200, ldp_root).serialize(format='ttl')
  22. headers = {'content-type': 'text/turtle'}
  23. rsp = self.client.request('PUT', uri, data=data, name='random_ingest', headers=headers)
  24. @task(50)
  25. def request_graph(self):
  26. uri = str(random.sample(subjects, 1)[0])
  27. self.client.request('get', uri, name='random_get')
  28. class LsupSwarmer(HttpLocust):
  29. task_set = Graph
  30. min_wait = 50
  31. max_wait = 500