Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
|
#include <thread-resource-mgr.h>
Classes | |
class | ResourcePool |
Public Types | |
typedef boost::function< void(ResourcePool *)> | ThreadAvailableCb |
Public Member Functions | |
ThreadResourceMgr (int threads_quota=0) | |
int | system_threads_quota () const |
ResourcePool * | RegisterPool () |
void | UnregisterPool (ResourcePool *pool) |
Private Types | |
typedef std::set< ResourcePool * > | Pools |
Pools currently being managed. More... | |
Private Member Functions | |
void | UpdatePoolQuotas (ResourcePool *new_pool=NULL) |
Private Attributes | |
int | system_threads_quota_ |
'Optimal' number of threads for the entire process. More... | |
boost::mutex | lock_ |
Lock for the entire object. Protects all fields below. More... | |
Pools | pools_ |
int | per_pool_quota_ |
std::list< ResourcePool * > | free_pool_objs_ |
Recycled list of pool objects. More... | |
Singleton object to manage CPU (aka thread) resources for the process. Conceptually, there is a fixed pool of threads that are shared between query fragments. If there is only one fragment running, it can use the entire pool, spinning up the maximum number of threads to saturate the hardware. If there are multiple fragments, the CPU pool must be shared between them. Currently, the total system pool is split evenly between all consumers. Each consumer gets ceil(total_system_threads / num_consumers). Each fragment must register with the ThreadResourceMgr to request threads (in the form of tokens). The fragment has required threads (it can't run with fewer threads) and optional threads. If the fragment is running on its own, it will be able to spin up more optional threads. When the system is under load, the ThreadResourceMgr will stop giving out tokens for optional threads. Pools should not use this for threads that are almost always idle (e.g. periodic reporting threads). Pools will temporarily go over the quota regularly and this is very much by design. For example, if a pool is running on its own with 4 required threads and 28 optional and another pool is added to the system, the first pool's quota is then cut by half (16 total) and will over time drop the optional threads. This class is thread safe. TODO: this is an initial simple version to improve the behavior with concurrency. This will need to be expanded post GA. These include:
Definition at line 63 of file thread-resource-mgr.h.
|
private |
Pools currently being managed.
Definition at line 215 of file thread-resource-mgr.h.
typedef boost::function<void (ResourcePool*)> impala::ThreadResourceMgr::ThreadAvailableCb |
This function will be called whenever the pool has more threads it can run on. This can happen on ReleaseThreadToken or if the quota for this pool increases. This is a good place, for example, to wake up anything blocked on available threads. This callback must not block. Note that this is not called once for each available thread or even guaranteed that when it is called, a thread is available (the quota could have changed again in between). It is simply that something might have happened (similar to condition variable semantics). TODO: this is manageable now since it just needs to call into the io mgr. What's the best model for something more general.
Definition at line 65 of file thread-resource-mgr.h.
ThreadResourceMgr::ThreadResourceMgr | ( | int | threads_quota = 0 | ) |
Create a thread mgr object. If threads_quota is non-zero, it will be the number of threads for the system, otherwise it will be determined based on the hardware.
Definition at line 35 of file thread-resource-mgr.cc.
References impala::CpuInfo::num_cores(), per_pool_quota_, and system_threads_quota_.
ThreadResourceMgr::ResourcePool * ThreadResourceMgr::RegisterPool | ( | ) |
Register a new pool with the thread mgr. Registering a pool will update the quotas for all existing pools.
Definition at line 61 of file thread-resource-mgr.cc.
References free_pool_objs_, lock_, pool, pools_, impala::ThreadResourceMgr::ResourcePool::Reset(), and UpdatePoolQuotas().
Referenced by impala::RuntimeState::Init(), and impala::TEST().
|
inline |
Definition at line 197 of file thread-resource-mgr.h.
References system_threads_quota_.
void ThreadResourceMgr::UnregisterPool | ( | ResourcePool * | pool | ) |
Unregisters the pool. 'pool' is no longer valid after this. This updates the quotas for the remaining pools.
Definition at line 81 of file thread-resource-mgr.cc.
References free_pool_objs_, lock_, pools_, and UpdatePoolQuotas().
Referenced by impala::PlanFragmentExecutor::Close(), and impala::TEST().
|
private |
Updates the per pool quota and notifies any pools that now have more threads they can use. Must be called with lock_ taken. If new_pool is non-null, new_pool will not be notified.
Definition at line 96 of file thread-resource-mgr.cc.
References impala::ThreadResourceMgr::ResourcePool::lock_, impala::ThreadResourceMgr::ResourcePool::num_available_threads(), per_pool_quota_, pool, pools_, system_threads_quota_, and impala::ThreadResourceMgr::ResourcePool::thread_available_fn_.
Referenced by RegisterPool(), and UnregisterPool().
|
private |
Recycled list of pool objects.
Definition at line 223 of file thread-resource-mgr.h.
Referenced by RegisterPool(), and UnregisterPool().
|
private |
Lock for the entire object. Protects all fields below.
Definition at line 212 of file thread-resource-mgr.h.
Referenced by RegisterPool(), impala::ThreadResourceMgr::ResourcePool::ReleaseThreadToken(), impala::ThreadResourceMgr::ResourcePool::SetThreadAvailableCb(), and UnregisterPool().
|
private |
Each pool currently gets the same share. This is the ceil of the system quota divided by the number of pools.
Definition at line 220 of file thread-resource-mgr.h.
Referenced by impala::ThreadResourceMgr::ResourcePool::quota(), ThreadResourceMgr(), and UpdatePoolQuotas().
|
private |
Definition at line 216 of file thread-resource-mgr.h.
Referenced by RegisterPool(), UnregisterPool(), and UpdatePoolQuotas().
|
private |
'Optimal' number of threads for the entire process.
Definition at line 209 of file thread-resource-mgr.h.
Referenced by system_threads_quota(), ThreadResourceMgr(), and UpdatePoolQuotas().