Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance optimization: list endpoints slow due to permission checks #1365

Closed
stevenbal opened this issue Apr 18, 2023 · 3 comments · Fixed by #1405 or #1406
Closed

Performance optimization: list endpoints slow due to permission checks #1365

stevenbal opened this issue Apr 18, 2023 · 3 comments · Fixed by #1405 or #1406

Comments

@stevenbal
Copy link
Contributor

stevenbal commented Apr 18, 2023

Master US - #1344
Taiga issue 454

Performance testing showed that several list endpoints are slowed down if a JWT without superuser permissions:

  • GET openzaak.components.zaken.api.viewsets.RolViewSet 
  • GET openzaak.components.zaken.api.viewsets.ZaakInformatieObjectViewSet 
  • GET openzaak.components.zaken.api.viewsets.StatusViewSet

Notes:

  • determining the count for pagination seems to be the bottleneck here as well, in this case because the query contains an INNER JOIN on the zaken_zaak table, which seems to reduce performance significantly. I tested locally with a simple query: SELECT COUNT(*) FROM "zaken_rol" INNER JOIN "zaken_zaak" ON ("zaken_rol"."zaak_id" = "zaken_zaak"."identificatie_ptr_id"), this query takes around 800ms on my machine

Upd. by Anna
The optimization is done in several steps (and PRs):

  1. use only "pk" in pagination count for all viewsets - PR ⚡ optimize pagination count #1405 - OZ 1.9
  2. optimize authorization filtering (initially developed in PR [DRAFT] ⚡ [#1365] Performance improvements for permissions check #1368, then cherry picked into new PR Feature/1365 auth filter #1406) - OZ 1.9
  3. introduce fuzzy pagination - [DRAFT] ⚡ [#1365] Performance improvements for permissions check #1368 - planned for OZ 1.11
@stevenbal stevenbal self-assigned this Apr 18, 2023
@stevenbal stevenbal changed the title Performance optimization: EnkelvoudigInformatieObject list endpoint Performance optimization: list endpoints slow due to permission checks Apr 18, 2023
@stevenbal
Copy link
Contributor Author

I looked into this, I noticed that removing ordering from the authorization query improves performance by quite a bit, but it still remains fairly slow due to the inner join it seems

stevenbal added a commit that referenced this issue May 15, 2023
the .count for pagination is a big performance bottleneck. To fix this, a limit of 500 is set for the count to keep pagination links functioning and improve performance
stevenbal added a commit that referenced this issue May 15, 2023
the .count for pagination is a big performance bottleneck. To fix this, a limit of 500 is set for the count to keep pagination links functioning and improve performance
stevenbal added a commit that referenced this issue May 15, 2023
the .count for pagination is a big performance bottleneck. To fix this, a limit of 500 is set for the count to keep pagination links functioning and improve performance
stevenbal added a commit that referenced this issue May 15, 2023
the .count for pagination is a big performance bottleneck. To fix this, a limit of 500 is set for the count to keep pagination links functioning and improve performance
stevenbal added a commit that referenced this issue May 16, 2023
the .count for pagination is a big performance bottleneck. To fix this, a limit of 500 is set for the count to keep pagination links functioning and improve performance
stevenbal added a commit that referenced this issue May 16, 2023
the .count for pagination is a big performance bottleneck. To fix this, a limit of 500 is set for the count to keep pagination links functioning and improve performance
stevenbal added a commit that referenced this issue Jun 6, 2023
the original query first fetched the pks for the authorized objects and used those in a filter on the original queryset. This caused bad performance for big querysets, especially if DISTINCT was used (EIO/zaak). Now this step is skipped and the objects are fetched directly
stevenbal added a commit that referenced this issue Jun 6, 2023
EnkelvoudigInformatieObject is not marked with the fuzzy pagination parameter, because this functionality is disabled for CMIS and CMIS_ENABLED=True when generating the schema
stevenbal added a commit that referenced this issue Jun 6, 2023
the .count for pagination is a big performance bottleneck. To fix this, a limit of 500 is set for the count to keep pagination links functioning and improve performance
stevenbal added a commit that referenced this issue Jun 6, 2023
the original query first fetched the pks for the authorized objects and used those in a filter on the original queryset. This caused bad performance for big querysets, especially if DISTINCT was used (EIO/zaak). Now this step is skipped and the objects are fetched directly
stevenbal added a commit that referenced this issue Jun 6, 2023
EnkelvoudigInformatieObject is not marked with the fuzzy pagination parameter, because this functionality is disabled for CMIS and CMIS_ENABLED=True when generating the schema
@joeribekker joeribekker added this to the Release 1.9.0 milestone Jun 19, 2023
@joeribekker
Copy link
Member

I made a ticket for this at VNG: VNG-Realisatie/gemma-zaken#2284

@annashamray
Copy link
Contributor

I'll separate this into two parts:

  1. optimize pagination.count by removing unnecessary joints
  2. introducing FuzzyPagination

The first part doesn't create deviations from the standard, but can add some performance boost, so I'll add it in Release 1.9

@annashamray annashamray modified the milestones: Release 1.11, Release 1.9 Jul 13, 2023
@annashamray annashamray self-assigned this Jul 13, 2023
annashamray pushed a commit that referenced this issue Jul 14, 2023
the original query first fetched the pks for the authorized objects and used those in a filter on the original queryset. This caused bad performance for big querysets, especially if DISTINCT was used (EIO/zaak). Now this step is skipped and the objects are fetched directly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment