-
-
Notifications
You must be signed in to change notification settings - Fork 10
Conversation
Make local_cache threadsafe
I'm not entirely sure about this change, it's moving a lot of the internals around. Also a recursive call to Can you explain the problem in a bit more depth? It should go in the Whilst looking at this I accidentally found your gargoyle fork at https://github.com/roverdotcom/gargoyle . If you're using that with |
Happy to give you a run down. We're talking about a threading issue in Python so sorry if this is a bit complex and long winded =) We ran into this issue because our production environment is a multithreaded and multiprocess uwsgi configuration. Multiprocess to do most of the heavy concurrency lifting, but also multithreaded to limit worker exhaustion when blocking on IO (primarily database calls). When Previously setting In our environment we make heavy use of gargoyle. This means the majority of requests check many flags and as a result frequently accesses the This addresses the issue by ensuring that the Infinite recursion is theoretically a possibility with this implementation, though the conditions required to cause it would be pretty far fetched for this use case. We only recurse if we get a We could alternatively fix this by doing a That fork was previously used as a quick fix workaround the previous (much larger and worse) threading issue where updates to the cache where not properly being invalidated before updates. We are no longer using it since that issue was already fixed in #25 (I think that was the one). |
Thanks for the long explanation! Since the test changes are pretty minor I'm also confident this should work. Merged in 7491f4a. A note: at YPlan we had a similar setup to what you describe, but when we dropped the multiple threads and moved to 2 processes per core, it actually improved our performance. Worth a try! Threads are complicated. |
Deployed on PyPI at 1.5.4: https://pypi.python.org/pypi/django-modeldict-yplan |
This should fix #18. I wasn't able to find a reasonable test to reproduce the behavior unfortunately, but this should cause
__getitem__
to recurse if a cross thread reset is detected.