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

Consider avoiding BaseHTTPMiddleware as parent of SlowAPIMiddleware #195

Open
KissPeter opened this issue Apr 18, 2024 · 2 comments
Open

Comments

@KissPeter
Copy link

Describe the bug
Thanks for your package, really useful. I made a collection of performance optimisations based on my real word examples. You can see them here: https://kisspeter.github.io/fastapi-performance-optimization/

One of the most impactful (negative on performance) item was the usage of BaseHTTPMiddleware the parent of your SlowAPIMiddleware. Therefore the global rate limiter impacts the app performance negatively.

To Reproduce

https://kisspeter.github.io/fastapi-performance-optimization/middleware

Expected behavior
SlowAPIMiddleware with minimal or no overall performance impact

Screenshots
If applicable, add screenshots to help explain your problem.

Your app (please complete the following information):

  • fastapi or starlette - irrelevant here
  • slowapi version - latest impacted

Additional context
Add any other context about the problem here.

@laurentS
Copy link
Owner

Hi @KissPeter thanks for sharing this!
Did you do any checks specifically on slowapi?

@thentgesMindee
Copy link
Collaborator

@KissPeter did you have a look at the ASGI middleware that doesn't inherit from BaseHTTPMiddleware ?
see docs here: https://github.com/laurentS/slowapi/blob/master/docs/examples.md#wsgi-vs-asgi-middleware

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants