datacratic/graphite-web — pull request #1 by jraby (2014-07-24 23:01:05+00:00)
Title: Use threads for remote fetches

Add a thread pool to the Store class and use it when doing `/metrics/find` queries to remote stores.
Also add a thread pool to `render/datalib.py` which is used for all `/render` queries (local files and remote cluster peers)

The threadpools can be enabled via the `REMOTE_STORE_USE_THREADS` parameter and the pool size is controlled by `REMOTE_STORE_THREADPOOL_SIZE` (defaults to 8 threads)

In a suboptimal test environment (9 nodes, 1 close and 8 far on the internet and quite loaded) this patch brings the time required to generate a (pretty heavy) graph from 18ish seconds to 4.5seconds.

I haven't yet stress tested this and it is my first time using mutiprocessing, so YMMV...
(in particular we may be leaking open sockets in fetchData - dbFile.fetch())