falconry / falcon

The no-magic web data plane API and microservices framework for Python developers, with a focus on reliability, correctness, and performance at scale.
https://falcon.readthedocs.io/en/stable/
Apache License 2.0
9.51k stars 937 forks source link

Investigate a tunable LRU cache on top of routing #1913

Open vytas7 opened 3 years ago

vytas7 commented 3 years ago

Some frameworks and custom applications opt to plop an LRU cache, such as functools.lru_cache, on top of the main routing function.

Investigate whether this could be a good idea to add to Falcon as an optional customization.

We probably don't want to do this by default, as there is probably no one-size-fits-all approach here. For contrived benchmarks exercising just a couple of end points, a cache of size 3 might be optimal, for a real-world application dealing with many objects or other dynamic segments, and running on many parallel processes/instances/containers, even a cache of 1000 might turn out to be a de-optimization.

Another idea by @kgriffs :

I wonder if we can do something clever to exclude certain routes from blowing up the LRU. Actually, it would be neat if the framework could learn and auto-tune the LRU.