ingest_benchmark.py 1.8 KB

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