Caching and thread safety (largeish) #13
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a large-ish patch that adds thread locks where necessary and precompilation support. I think it's reasonable that we don't necessarily want to accept this patch, but I wanted to get feedback on whether this is something you'd be willing to accept, either in a more completed form, or after we get all the way to certain goals.
This is meant to gesture towards the following goals:
This work came about when originally trying to deploy djangobars in a multithreaded production environment with high traffic. Two kinds of errors surfaced that lead to a (temporary) rollback. The first were context errors -- logic like {{#if foo.bar}} {{foo.bar}} {{/if}} would fail saying 'no foo.bar' exists! The second is that templates were being outputted in corupted ways. It became clear that there was a threading issue, and sure-enough, in pybars._compiler, there's a note saying that the Compiler is not thread-safe.
After fixing thread-safety, there was still a big issue with performance. Locking the threads destroyed the performance value of a threaded environment. Measuring performance, the bottleneck was compiling the templates. Thus, the precompilation support.
It is organized as follows:
Some current issues:
dirs
list rather than being passed the legacy loaders objects in its place. When running the test suite against current django 1.8, we clearly also need to try/catch some django imports that no longer exist there.Originally, I separated the thread safety and precompilation as projects, but in production, we found that locking threads, still blocks too many requests, so they are really necessary combined, at least, in practice.