Uninett / Argus

Argus is an alert aggregator for monitoring systems
GNU General Public License v3.0
18 stars 12 forks source link

Prefetch related data in incidents endpoint #837

Open lunkwill42 opened 5 days ago

lunkwill42 commented 5 days ago

The incidents endpoint does not appear to prefetch tag data when querying incidents. This may cause the response to be magnitudes slower that it needs to be.

For context, fetching 2.5K incidents is 99% faster if tag data is prefetched:

>>> timeit.timeit("""
... for i in x:
...     i.deprecated_tags
... """, setup="x = Incident.objects.all()[:2500]", number=2, globals=locals())
69.45030555600533
>>> timeit.timeit("""
... for i in x:
...    i.deprecated_tags
... """, setup="x = Incident.objects.prefetch_default_related()[:2500]", number=2, globals=locals())
0.4965064429998165
>>>

The difference may not be as stark in the API endpoint itself, as most of the time there is spent serializing the data to JSON (DRF's ModelSerializer is reaally slow). Simply testing the API before and after applying this change seems to indicate only a 36% speedup (which is still significant).

sonarcloud[bot] commented 5 days ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

codecov-commenter commented 5 days ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 84.81%. Comparing base (cdc23e5) to head (4884639).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #837 +/- ## ======================================= Coverage 84.81% 84.81% ======================================= Files 76 76 Lines 3846 3846 ======================================= Hits 3262 3262 Misses 584 584 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

github-actions[bot] commented 5 days ago

Test results

    7 files    616 suites   23m 2s :stopwatch:   489 tests   488 :white_check_mark: 1 :zzz: 0 :x: 3 423 runs  3 416 :white_check_mark: 7 :zzz: 0 :x:

Results for commit 48846393.