Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
impala::ThreadResourceMgr Class Reference

#include <thread-resource-mgr.h>

Collaboration diagram for impala::ThreadResourceMgr:

Classes

class  ResourcePool
 

Public Types

typedef boost::function< void(ResourcePool *)> ThreadAvailableCb
 

Public Member Functions

 ThreadResourceMgr (int threads_quota=0)
 
int system_threads_quota () const
 
ResourcePoolRegisterPool ()
 
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...
 

Detailed Description

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:

  • More places where threads are optional (e.g. hash table build side, data stream threads, etc).
  • Admission control
  • Integration with other nodes/statestore
  • Priorities for different pools If both the mgr and pool locks need to be taken, the mgr lock must be taken first.

Definition at line 63 of file thread-resource-mgr.h.

Member Typedef Documentation

typedef std::set<ResourcePool*> impala::ThreadResourceMgr::Pools
private

Pools currently being managed.

Definition at line 215 of file thread-resource-mgr.h.

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.

Constructor & Destructor Documentation

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_.

Member Function Documentation

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().

int impala::ThreadResourceMgr::system_threads_quota ( ) const
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().

void ThreadResourceMgr::UpdatePoolQuotas ( ResourcePool new_pool = NULL)
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().

Member Data Documentation

std::list<ResourcePool*> impala::ThreadResourceMgr::free_pool_objs_
private

Recycled list of pool objects.

Definition at line 223 of file thread-resource-mgr.h.

Referenced by RegisterPool(), and UnregisterPool().

boost::mutex impala::ThreadResourceMgr::lock_
private
int impala::ThreadResourceMgr::per_pool_quota_
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().

Pools impala::ThreadResourceMgr::pools_
private

Definition at line 216 of file thread-resource-mgr.h.

Referenced by RegisterPool(), UnregisterPool(), and UpdatePoolQuotas().

int impala::ThreadResourceMgr::system_threads_quota_
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().


The documentation for this class was generated from the following files: