ingest_benchmark.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import json
  2. from timeit import default_timer as timer
  3. from django.conf import settings
  4. from django.core.management.base import BaseCommand
  5. from django.shortcuts import reverse
  6. from django.test import RequestFactory
  7. from events.models import Event
  8. from events.test_data.event_generator import get_seeded_benchmark_events
  9. from events.views import EventStoreAPIView
  10. from organizations_ext.models import Organization
  11. from projects.models import Project
  12. class Command(BaseCommand):
  13. help = "Time (for performance) ingesting fake events, including celery processing."
  14. def handle(self, *args, **options):
  15. settings.CELERY_TASK_ALWAYS_EAGER = True
  16. slug = "benchark-test-jfhr3e3jlek8eewmksde"
  17. name = "Benchark Test Do Not Use"
  18. organization, _ = Organization.objects.get_or_create(
  19. slug=slug, defaults={"name": name}
  20. )
  21. project, _ = Project.objects.get_or_create(
  22. slug=slug, defaults={"name": name, "organization": organization}
  23. )
  24. project.issue_set.all().delete()
  25. key = project.projectkey_set.first()
  26. project_id = project.id
  27. url = (
  28. reverse("event_store", args=[project_id])
  29. + "?glitchtip_key="
  30. + key.public_key_hex
  31. )
  32. factory = RequestFactory()
  33. quantity = 300
  34. requests = [
  35. factory.post(url, data=json.dumps(event), content_type="application/json")
  36. for event in get_seeded_benchmark_events(quantity=quantity)
  37. ]
  38. view = EventStoreAPIView.as_view()
  39. start = timer()
  40. for request in requests:
  41. view(request, id=project_id)
  42. end = timer()
  43. print(end - start)
  44. assert Event.objects.filter(issue__project=project).count() == quantity
  45. project.issue_set.all().delete()