OmniSciDB
a5dc49c757
|
ExecutorResourceMgr
is the central manager for resources available to all executors in the system. It manages an ExecutorResourcePool
to keep track of available and allocated resources (currently CPU slots/threads, GPUs, CPU result memory, and CPU and GPU buffer pool memory). It also manages a thread queue which keeps requesting threads (from Executor::launchKernelsViaResourceMgr
) waiting until there it can schedule them. At that point, it gives the calling executor thread a ResourceHandle
detailing the resources granted to the query, which once it goes out of scope will return the granted resources to the ExecutorResourcePool.
More...
#include <ExecutorResourceMgr.h>
Public Member Functions | |
ExecutorResourceMgr (const std::vector< std::pair< ResourceType, size_t >> &total_resources, const std::vector< ConcurrentResourceGrantPolicy > &concurrent_resource_grant_policies, const std::vector< ResourceGrantPolicy > &max_per_request_resource_grant_policies, const double max_available_resource_use_ratio) | |
The constructor instantiates an ExecutorResourcePool with the provided parameters, and starts the process queue by launching a thread to invoke process_queue_loop. More... | |
~ExecutorResourceMgr () | |
The destructor ensures that the process queue thread (process_queue_thread ) is stopped and that any threads waiting for resources are joined. Currently only called on database shutdown. More... | |
std::unique_ptr < ExecutorResourceHandle > | request_resources_with_timeout (const RequestInfo &request_info, const size_t timeout_in_ms) |
Requests resources from ExecutorResourceMgr , will throw if request takes longer than time specified by timeout_in_ms. More... | |
std::unique_ptr < ExecutorResourceHandle > | request_resources (const RequestInfo &request_info) |
Requests resources from ExecutorResourceMgr , with no timeout (unlike request_resources_with_timeout ) More... | |
void | release_resources (const RequestId request_id, const ResourceGrant &resource_grant) |
Instructs ExecutorResourceMgr that the resources held by the requestor with the given request_id can be freed/returned to the ExecutorResourcePool . More... | |
ExecutorStats | get_executor_stats () const |
Returns a copy of the ExecutorStats struct held by ExecutorResourceMgr . Used for testing currently. More... | |
void | print_executor_stats () const |
Prints the ExecutorStats struct. Use for debugging. More... | |
std::pair< size_t, size_t > | get_resource_info (const ResourceType resource_type) const |
Returns the allocated and total available amount of the resource specified. More... | |
ResourcePoolInfo | get_resource_info () const |
Returns a struct containing the total and allocated amounts of all resources tracked by ExecutorResourceMgr /ExecutorResourcePool , as well as the number of outstanding requests (in total and by resource type) More... | |
void | set_resource (const ResourceType resource_type, const size_t resoure_quantity) |
Used to change the total amount available of a specified resource after construction of ExecutorResourceMgr More... | |
ConcurrentResourceGrantPolicy | get_concurrent_resource_grant_policy (const ResourceType resource_type) const |
Get the concurrent resource grant policy for a given resource type. More... | |
void | set_concurrent_resource_grant_policy (const ConcurrentResourceGrantPolicy &concurrent_resource_grant_policy) |
Set the concurrent resource grant policy for a given resource type (stored in ConcurrentResourceGrantPolicy ) More... | |
void | pause_process_queue () |
Pauses the process queue in a thread-safe manner, waiting for all queries in the executing stage to finish before yielding to the caller (ensuring that the ExecutorResourcePool has no outstanding allocations). If the process queue is already paused, the call is a no-op. This method is used to live-change parameters associated with ExecutorResourcePool. More... | |
void | resume_process_queue () |
Resumes the process queue in a thread-safe manner. If the process queue is already paused, the call is a no-op. More... | |
Private Member Functions | |
void | process_queue_loop () |
Internal method: A thread is assigned to run this function in the constructor of ExecutorResourceMgr , where it loops continuously waiting for changes to the process queue (i.e. the introduction of a new resource request or the finish of an existing request). More... | |
RequestStats | get_request_for_id (const RequestId request_id) const |
Internal method: Returns the RequestStats for a request specified by request_id . More... | |
void | mark_request_error (const RequestId request_id, std::string error_msg) |
RequestId | choose_next_request () |
Internal method: Invoked from process_queue_loop , chooses the next resource request to grant. More... | |
RequestId | enqueue_request (const RequestInfo &request_info, const size_t timeout_in_ms, const ResourceGrant &min_resource_grant, const ResourceGrant &max_resource_grant) |
Internal method: Invoked from request_resource/request_resource_with_timeout, places request in the request queue where it will be wait to be granted the resources requested. More... | |
void | mark_request_dequed (const RequestId request_id) |
Internal method: Moves the request from the QUEUED stage to EXECUTING stage and performs other bookkeeping. More... | |
void | mark_request_timed_out (const RequestId request_id) |
Internal method: Called if the request times out (i.e. request was made via request_resources_with_timeout ), moves request out of QUEUED stage and does other bookkeeping on the request's RequestStats and on ExecutorStats . More... | |
void | mark_request_finished (const RequestId request_id) |
Internal method: Invoked on successful completion of a query step from release_resources method, removes request from EXECUTING stage and performs various bookkeeping, including recording execution and final times in request_stats. More... | |
void | set_process_queue_flag () |
Internal method: Set the should_process_queue_ flag to true, signifying that the queue should be processed. Protected by a lock on processor_queue_mutex_ . More... | |
void | stop_process_queue_thread () |
Internal method: Invoked from ExecutorResourceMgr destructor, sets stop_process_queue_thread_ to true (behind a lock on processor_queue_mutex_ ) and then attempts to join all threads left in the request queue on server shutdown. More... | |
std::vector< RequestId > | get_requests_for_stage (const ExecutionRequestStage request_status) const |
Internal method: Get the request ids for a given stage (QUEUED or EXECUTING ) More... | |
void | add_request_to_stage (const RequestId request_id, const ExecutionRequestStage request_status) |
Internal method: Adds the request specified by the provided request_id to the specified stage. More... | |
void | remove_request_from_stage (const RequestId request_id, const ExecutionRequestStage request_status) |
Internal method: Removes the request specified by the provided request_id from the specified stage. More... | |
ChunkRequestInfo | get_chunk_request_info (const RequestId request_id) |
Get the DataMgr chunk ids and associated sizes pertaining to the input data needed by a request. More... | |
Private Attributes | |
ExecutorResourcePool | executor_resource_pool_ |
Keeps track of available resources for execution. More... | |
std::atomic< size_t > | requests_count_ {0} |
An atomic that is incremented with each incoming request, and used to assign RequestIds to incoming request. More... | |
ExecutorStats | executor_stats_ |
Holds a single ExecutorStats struct that pertains to cummulative stats for ExecutorResourceMgr , i.e. number of requests, queue length, total execution time, etc. More... | |
const size_t | ACTUALLY_QUEUED_MIN_MS {2} |
std::thread | process_queue_thread_ |
The thread started in the ExecutorResourceMgr constructor that continuously loops inside of process_queue_loop to determine the next resource request that should be granted. More... | |
std::mutex | processor_queue_mutex_ |
RW mutex that protects access to stop_process_queue_thread_ and pause_processor_queue_ More... | |
std::mutex | pause_processor_queue_mutex_ |
std::mutex | print_mutex_ |
std::shared_mutex | queue_stats_mutex_ |
RW mutex that protects access to executor_stats_ and request_stats_ More... | |
std::shared_mutex | queued_set_mutex_ |
RW mutex that protects access to queued_requests_ More... | |
std::shared_mutex | executing_set_mutex_ |
RW mutex that protects access to executing_requests_ More... | |
std::condition_variable | processor_queue_condition_ |
std::condition_variable | pause_processor_queue_condition_ |
bool | should_process_queue_ {false} |
bool | stop_process_queue_thread_ {false} |
bool | pause_process_queue_ {false} |
bool | process_queue_is_paused_ {false} |
size_t | process_queue_counter_ {0} |
OutstandingQueueRequests | outstanding_queue_requests_ |
Stores and manages a map of request ids to BinarySemaphore objects to allow threads waiting for resources to be selectively queued/blocked and then when they are choosen for resource grants/execution, woken. More... | |
std::set< RequestId > | queued_requests_ |
Set of all request ids that are currently queued. Protected by queued_set_mutex_ . More... | |
std::set< RequestId > | executing_requests_ |
Set of all request ids that are currently executing (i.e. post-granting of resources). Protected by executing_set_mutex_ . More... | |
std::vector< RequestStats > | requests_stats_ |
Stores a vector of all requests that have been seen by ExecutorResourceMgr , with each incoming request appending a RequestStats struct to this vector. Protected by queue_stats_mutex_ . More... | |
const bool | enable_stats_printing_ {false} |
const bool | enable_debug_printing_ {false} |
const RequestId | INVALID_REQUEST_ID {std::numeric_limits<size_t>::max()} |
const double | max_available_resource_use_ratio_ |
ExecutorResourceMgr
is the central manager for resources available to all executors in the system. It manages an ExecutorResourcePool
to keep track of available and allocated resources (currently CPU slots/threads, GPUs, CPU result memory, and CPU and GPU buffer pool memory). It also manages a thread queue which keeps requesting threads (from Executor::launchKernelsViaResourceMgr
) waiting until there it can schedule them. At that point, it gives the calling executor thread a ResourceHandle
detailing the resources granted to the query, which once it goes out of scope will return the granted resources to the ExecutorResourcePool.
Definition at line 137 of file ExecutorResourceMgr.h.
ExecutorResourceMgr_Namespace::ExecutorResourceMgr::ExecutorResourceMgr | ( | const std::vector< std::pair< ResourceType, size_t >> & | total_resources, |
const std::vector< ConcurrentResourceGrantPolicy > & | concurrent_resource_grant_policies, | ||
const std::vector< ResourceGrantPolicy > & | max_per_request_resource_grant_policies, | ||
const double | max_available_resource_use_ratio | ||
) |
The constructor instantiates an ExecutorResourcePool
with the provided parameters, and starts the process queue by launching a thread to invoke process_queue_loop.
Definition at line 25 of file ExecutorResourceMgr.cpp.
References CHECK_GT, CHECK_LE, logger::EXECUTOR, LOG, max_available_resource_use_ratio_, process_queue_loop(), and process_queue_thread_.
ExecutorResourceMgr_Namespace::ExecutorResourceMgr::~ExecutorResourceMgr | ( | ) |
The destructor ensures that the process queue thread (process_queue_thread
) is stopped and that any threads waiting for resources are joined. Currently only called on database shutdown.
Definition at line 40 of file ExecutorResourceMgr.cpp.
References stop_process_queue_thread().
|
private |
Internal method: Adds the request specified by the provided request_id
to the specified stage.
request_id | - Request id to add to the specified stage |
request_status | - Stage (QUEUED or EXECUTING ) to add the specified request to |
Definition at line 576 of file ExecutorResourceMgr.cpp.
References CHECK, executing_requests_, executing_set_mutex_, ExecutorResourceMgr_Namespace::QUEUED, queued_requests_, and queued_set_mutex_.
Referenced by enqueue_request(), and mark_request_dequed().
|
private |
Internal method: Invoked from process_queue_loop
, chooses the next resource request to grant.
Currently based on FIFO logic, choosing the oldest request in the queue that we have enough resources in ExecutorResourcePool
to fulfill. Future variants could add more sophisticated logic for more optimal query scheduling (i.e. non-FIFO).
Definition at line 133 of file ExecutorResourceMgr.cpp.
References ExecutorResourceMgr_Namespace::ExecutorResourcePool::determine_dynamic_resource_grant(), enable_debug_printing_, logger::EXECUTOR, executor_resource_pool_, get_requests_for_stage(), INVALID_REQUEST_ID, LOG, max_available_resource_use_ratio_, print_mutex_, process_queue_counter_, queue_stats_mutex_, ExecutorResourceMgr_Namespace::QUEUED, logger::request_id(), and requests_stats_.
Referenced by process_queue_loop().
|
private |
Internal method: Invoked from request_resource/request_resource_with_timeout, places request in the request queue where it will be wait to be granted the resources requested.
Note that this method assigns a RequestId
to the request, adds the request to the RequestStats
, and adds the assigned request_id to the QUEUED stage, but does not actually notify the process queue or queue the request in the OutstandQueueRequests
object. Those tasks are done subsequently to invocation of this method in the parent call (request_resources_with_timeout
)
request_info | - info for the current resource request |
timeout_in_ms | - request timeout |
min_resource_grant | - min allowable resource request, calculated in caller request_resources_with_timeout method from request_info |
max_resource_grant | - max (ideal) resource request, calculated in caller request_resources_with_timeout method from request_info |
Definition at line 391 of file ExecutorResourceMgr.cpp.
References add_request_to_stage(), CPU, ExecutorResourceMgr_Namespace::ExecutorStats::cpu_queue_length, ExecutorResourceMgr_Namespace::ExecutorStats::cpu_requests, executor_stats_, GPU, ExecutorResourceMgr_Namespace::ExecutorStats::gpu_queue_length, ExecutorResourceMgr_Namespace::ExecutorStats::gpu_requests, ExecutorResourceMgr_Namespace::ExecutorStats::queue_length, queue_stats_mutex_, ExecutorResourceMgr_Namespace::QUEUED, ExecutorResourceMgr_Namespace::RequestInfo::request_device_type, logger::request_id(), ExecutorResourceMgr_Namespace::ExecutorStats::requests, requests_count_, requests_stats_, ExecutorResourceMgr_Namespace::ExecutorStats::requests_with_timeouts, ExecutorResourceMgr_Namespace::ExecutorStats::sum_cpu_queue_size_at_entry, ExecutorResourceMgr_Namespace::ExecutorStats::sum_gpu_queue_size_at_entry, ExecutorResourceMgr_Namespace::ExecutorStats::sum_queue_size_at_entry, and UNREACHABLE.
Referenced by request_resources_with_timeout().
|
private |
Get the DataMgr
chunk ids and associated sizes pertaining to the input data needed by a request.
request_id | - Request id to fetch the needed chunks for |
ChunkKey
and byte sizes as well as device memory space (CPU or GPU), total bytes, etc Definition at line 604 of file ExecutorResourceMgr.cpp.
References queue_stats_mutex_, logger::request_id(), and requests_stats_.
Referenced by release_resources().
ConcurrentResourceGrantPolicy ExecutorResourceMgr_Namespace::ExecutorResourceMgr::get_concurrent_resource_grant_policy | ( | const ResourceType | resource_type | ) | const |
Get the concurrent resource grant policy for a given resource type.
Queries the ExecutorResourcePool for the current concurrency policies (including normal and oversubscribed) for a resource type
resource_type | - Type of resource to get the concurrency policy for |
Definition at line 293 of file ExecutorResourceMgr.cpp.
References executor_resource_pool_, and ExecutorResourceMgr_Namespace::ExecutorResourcePool::get_concurrent_resource_grant_policy().
ExecutorStats ExecutorResourceMgr_Namespace::ExecutorResourceMgr::get_executor_stats | ( | ) | const |
Returns a copy of the ExecutorStats
struct held by ExecutorResourceMgr
. Used for testing currently.
Definition at line 168 of file ExecutorResourceMgr.cpp.
References executor_stats_, and queue_stats_mutex_.
Referenced by print_executor_stats().
|
private |
Internal method: Returns the RequestStats
for a request specified by request_id
.
Takes a read lock on queue_stats_mutex_
for thread safety. Note this method should not be used in internal methods where a lock is already taken on queue_stats_mutex_
.
request_id | - The RequestId for the request we want to retrieve stats for |
Definition at line 120 of file ExecutorResourceMgr.cpp.
References CHECK_LT, queue_stats_mutex_, logger::request_id(), and requests_stats_.
Referenced by process_queue_loop().
|
private |
Internal method: Get the request ids for a given stage (QUEUED
or EXECUTING
)
Invoked from choose_next_request
to get all outstanding queued requests
request_status | - request stage type to fetch request ids for |
Definition at line 562 of file ExecutorResourceMgr.cpp.
References executing_requests_, executing_set_mutex_, ExecutorResourceMgr_Namespace::QUEUED, queued_requests_, and queued_set_mutex_.
Referenced by choose_next_request().
|
inline |
Returns the allocated and total available amount of the resource specified.
Interally queries ExecutorResourcePool
Definition at line 224 of file ExecutorResourceMgr.h.
References executor_resource_pool_, and ExecutorResourceMgr_Namespace::ExecutorResourcePool::get_resource_info().
|
inline |
Returns a struct containing the total and allocated amounts of all resources tracked by ExecutorResourceMgr
/ExecutorResourcePool
, as well as the number of outstanding requests (in total and by resource type)
ExecutorResourcePool.h
, contains total and allocated amounts for all resources, and total requests outstanding and per type of resource Definition at line 237 of file ExecutorResourceMgr.h.
References executor_resource_pool_, and ExecutorResourceMgr_Namespace::ExecutorResourcePool::get_resource_info().
Referenced by set_resource().
|
private |
Internal method: Moves the request from the QUEUED
stage to EXECUTING
stage and performs other bookkeeping.
Invoked by process_queue_loop after determing the next resource request to serve (via choose_next_request
).
request_id | - RequestId of the request being moved out of the request queue (to be executed) |
Definition at line 435 of file ExecutorResourceMgr.cpp.
References ACTUALLY_QUEUED_MIN_MS, add_request_to_stage(), CHECK_LT, CPU, ExecutorResourceMgr_Namespace::ExecutorStats::cpu_queue_length, ExecutorResourceMgr_Namespace::ExecutorStats::cpu_requests_actually_queued, ExecutorResourceMgr_Namespace::ExecutorStats::cpu_requests_executing, ExecutorResourceMgr_Namespace::RequestStats::deque_time, ExecutorResourceMgr_Namespace::RequestStats::enqueue_time, ExecutorResourceMgr_Namespace::EXECUTING, executor_stats_, ExecutorResourceMgr_Namespace::RequestStats::finished_queueing, GPU, ExecutorResourceMgr_Namespace::ExecutorStats::gpu_queue_length, ExecutorResourceMgr_Namespace::ExecutorStats::gpu_requests_actually_queued, ExecutorResourceMgr_Namespace::ExecutorStats::gpu_requests_executing, ExecutorResourceMgr_Namespace::ExecutorStats::queue_length, queue_stats_mutex_, ExecutorResourceMgr_Namespace::RequestStats::queue_time_ms, ExecutorResourceMgr_Namespace::QUEUED, remove_request_from_stage(), ExecutorResourceMgr_Namespace::RequestInfo::request_device_type, logger::request_id(), ExecutorResourceMgr_Namespace::RequestStats::request_info, ExecutorResourceMgr_Namespace::ExecutorStats::requests_actually_queued, requests_count_, ExecutorResourceMgr_Namespace::ExecutorStats::requests_executing, requests_stats_, ExecutorResourceMgr_Namespace::ExecutorStats::total_cpu_queue_time_ms, ExecutorResourceMgr_Namespace::ExecutorStats::total_gpu_queue_time_ms, ExecutorResourceMgr_Namespace::ExecutorStats::total_queue_time_ms, and UNREACHABLE.
Referenced by process_queue_loop().
|
private |
Definition at line 126 of file ExecutorResourceMgr.cpp.
References CHECK_LT, queue_stats_mutex_, logger::request_id(), and requests_stats_.
Referenced by process_queue_loop().
|
private |
Internal method: Invoked on successful completion of a query step from release_resources method, removes request from EXECUTING
stage and performs various bookkeeping, including recording execution and final times in request_stats.
request_id | - RequestId for the resource request that has finished executing |
Definition at line 517 of file ExecutorResourceMgr.cpp.
References CHECK_LT, CPU, ExecutorResourceMgr_Namespace::ExecutorStats::cpu_requests_executed, ExecutorResourceMgr_Namespace::ExecutorStats::cpu_requests_executing, ExecutorResourceMgr_Namespace::RequestStats::deque_time, ExecutorResourceMgr_Namespace::RequestStats::enqueue_time, ExecutorResourceMgr_Namespace::EXECUTING, ExecutorResourceMgr_Namespace::RequestStats::execution_finished_time, ExecutorResourceMgr_Namespace::RequestStats::execution_time_ms, executor_stats_, ExecutorResourceMgr_Namespace::RequestStats::finished_executing, GPU, ExecutorResourceMgr_Namespace::ExecutorStats::gpu_requests_executed, ExecutorResourceMgr_Namespace::ExecutorStats::gpu_requests_executing, queue_stats_mutex_, remove_request_from_stage(), ExecutorResourceMgr_Namespace::RequestInfo::request_device_type, logger::request_id(), ExecutorResourceMgr_Namespace::RequestStats::request_info, requests_count_, ExecutorResourceMgr_Namespace::ExecutorStats::requests_executed, ExecutorResourceMgr_Namespace::ExecutorStats::requests_executing, requests_stats_, ExecutorResourceMgr_Namespace::ExecutorStats::total_cpu_execution_time_ms, ExecutorResourceMgr_Namespace::ExecutorStats::total_cpu_time_ms, ExecutorResourceMgr_Namespace::ExecutorStats::total_execution_time_ms, ExecutorResourceMgr_Namespace::ExecutorStats::total_gpu_execution_time_ms, ExecutorResourceMgr_Namespace::ExecutorStats::total_gpu_time_ms, ExecutorResourceMgr_Namespace::ExecutorStats::total_time_ms, ExecutorResourceMgr_Namespace::RequestStats::total_time_ms, and UNREACHABLE.
Referenced by release_resources().
|
private |
Internal method: Called if the request times out (i.e. request was made via request_resources_with_timeout
), moves request out of QUEUED
stage and does other bookkeeping on the request's RequestStats
and on ExecutorStats
.
Invoked from request_resources_with_timeout
if a QueryTimedOutWaitingInQueue
exception is thrown
request_id | - RequestId for the resource request that has timed out |
Definition at line 485 of file ExecutorResourceMgr.cpp.
References CHECK, CHECK_GT, CHECK_LT, CPU, ExecutorResourceMgr_Namespace::ExecutorStats::cpu_queue_length, executor_stats_, ExecutorResourceMgr_Namespace::RequestStats::finished_queueing, GPU, ExecutorResourceMgr_Namespace::ExecutorStats::gpu_queue_length, ExecutorResourceMgr_Namespace::ExecutorStats::queue_length, queue_stats_mutex_, ExecutorResourceMgr_Namespace::QUEUED, remove_request_from_stage(), ExecutorResourceMgr_Namespace::RequestInfo::request_device_type, logger::request_id(), ExecutorResourceMgr_Namespace::RequestStats::request_info, requests_count_, requests_stats_, ExecutorResourceMgr_Namespace::ExecutorStats::requests_timed_out, ExecutorResourceMgr_Namespace::RequestStats::timed_out, ExecutorResourceMgr_Namespace::RequestStats::timeout_in_ms, and UNREACHABLE.
Referenced by request_resources_with_timeout().
void ExecutorResourceMgr_Namespace::ExecutorResourceMgr::pause_process_queue | ( | ) |
Pauses the process queue in a thread-safe manner, waiting for all queries in the executing stage to finish before yielding to the caller (ensuring that the ExecutorResourcePool has no outstanding allocations). If the process queue is already paused, the call is a no-op. This method is used to live-change parameters associated with ExecutorResourcePool.
Note that when the queue is fully paused, there will be no executing requests but there can be one or more queued requests.
Definition at line 245 of file ExecutorResourceMgr.cpp.
References CHECK_EQ, executor_stats_, logger::INFO, LOG, pause_process_queue_, pause_processor_queue_condition_, pause_processor_queue_mutex_, process_queue_is_paused_, processor_queue_condition_, processor_queue_mutex_, and ExecutorResourceMgr_Namespace::ExecutorStats::requests_executing.
Referenced by set_concurrent_resource_grant_policy(), and set_resource().
void ExecutorResourceMgr_Namespace::ExecutorResourceMgr::print_executor_stats | ( | ) | const |
Prints the ExecutorStats
struct. Use for debugging.
Definition at line 173 of file ExecutorResourceMgr.cpp.
References get_executor_stats(), print_mutex_, and process_queue_counter_.
Referenced by process_queue_loop().
|
private |
Internal method: A thread is assigned to run this function in the constructor of ExecutorResourceMgr
, where it loops continuously waiting for changes to the process queue (i.e. the introduction of a new resource request or the finish of an existing request).
Definition at line 313 of file ExecutorResourceMgr.cpp.
References ExecutorResourceMgr_Namespace::ExecutorResourcePool::allocate_resources(), choose_next_request(), enable_debug_printing_, enable_stats_printing_, executor_resource_pool_, executor_stats_, get_request_for_id(), ExecutorResourceMgr_Namespace::ExecutorResourceMgrError::getErrorMsg(), ExecutorResourceMgr_Namespace::ExecutorResourceMgrError::getRequestId(), INVALID_REQUEST_ID, mark_request_dequed(), mark_request_error(), outstanding_queue_requests_, pause_process_queue_, pause_processor_queue_condition_, pause_processor_queue_mutex_, print_executor_stats(), print_mutex_, process_queue_counter_, process_queue_is_paused_, processor_queue_condition_, processor_queue_mutex_, ExecutorResourceMgr_Namespace::ExecutorStats::requests_executing, should_process_queue_, stop_process_queue_thread_, and ExecutorResourceMgr_Namespace::OutstandingQueueRequests::wake_request_by_id().
Referenced by ExecutorResourceMgr().
void ExecutorResourceMgr_Namespace::ExecutorResourceMgr::release_resources | ( | const RequestId | request_id, |
const ResourceGrant & | resource_grant | ||
) |
Instructs ExecutorResourceMgr
that the resources held by the requestor with the given request_id
can be freed/returned to the ExecutorResourcePool
.
This method is only called automatically in the destructor of ExecutorResourceHandle
(i.e. when it goes out of scope along with the parent executor thread)
request_id | - RequestId for the query step that requested the resources |
resource_grant | - The resources that were granted from ExecutorResourcePool and that now will be freed/returned to the pool |
Definition at line 108 of file ExecutorResourceMgr.cpp.
References ExecutorResourceMgr_Namespace::ExecutorResourcePool::deallocate_resources(), executor_resource_pool_, get_chunk_request_info(), ExecutorResourceMgr_Namespace::ResourceGrant::is_empty(), mark_request_finished(), processor_queue_condition_, and set_process_queue_flag().
|
private |
Internal method: Removes the request specified by the provided request_id
from the specified stage.
request_id | - Request id to remove from the specified stage |
request_status | - Stage (QUEUED or EXECUTING ) to remove the specified request from |
Definition at line 590 of file ExecutorResourceMgr.cpp.
References CHECK_EQ, executing_requests_, executing_set_mutex_, ExecutorResourceMgr_Namespace::QUEUED, queued_requests_, and queued_set_mutex_.
Referenced by mark_request_dequed(), mark_request_finished(), and mark_request_timed_out().
std::unique_ptr< ExecutorResourceHandle > ExecutorResourceMgr_Namespace::ExecutorResourceMgr::request_resources | ( | const RequestInfo & | request_info | ) |
Requests resources from ExecutorResourceMgr
, with no timeout (unlike request_resources_with_timeout
)
Internally calls request_resources_with_timeout
with 0 timeout, specifying no-timeout.
request_info | - Details the resources requested |
ExecutorResourcePool
Definition at line 101 of file ExecutorResourceMgr.cpp.
References request_resources_with_timeout().
std::unique_ptr< ExecutorResourceHandle > ExecutorResourceMgr_Namespace::ExecutorResourceMgr::request_resources_with_timeout | ( | const RequestInfo & | request_info, |
const size_t | timeout_in_ms | ||
) |
Requests resources from ExecutorResourceMgr
, will throw if request takes longer than time specified by timeout_in_ms.
request_info | - Details the resources requested |
timeout_in_ms | - Specifies the max time in ms the requesting thread should wait for a request before an exception is thrown |
ExecutorResourcePool
Definition at line 45 of file ExecutorResourceMgr.cpp.
References ExecutorResourceMgr_Namespace::RequestStats::actual_resource_grant, ExecutorResourceMgr_Namespace::ExecutorResourcePool::calc_min_max_resource_grants_for_request(), CHECK_GE, ExecutorResourceMgr_Namespace::ResourceGrant::cpu_result_mem, ExecutorResourceMgr_Namespace::ResourceGrant::cpu_slots, enable_debug_printing_, enqueue_request(), ExecutorResourceMgr_Namespace::RequestStats::error, executor_resource_pool_, ExecutorResourceMgr_Namespace::ResourceGrant::gpu_slots, mark_request_timed_out(), outstanding_queue_requests_, print_mutex_, processor_queue_condition_, ExecutorResourceMgr_Namespace::OutstandingQueueRequests::queue_request_and_wait(), ExecutorResourceMgr_Namespace::OutstandingQueueRequests::queue_request_and_wait_with_timeout(), queue_stats_mutex_, logger::request_id(), requests_stats_, and set_process_queue_flag().
Referenced by request_resources().
void ExecutorResourceMgr_Namespace::ExecutorResourceMgr::resume_process_queue | ( | ) |
Resumes the process queue in a thread-safe manner. If the process queue is already paused, the call is a no-op.
Definition at line 265 of file ExecutorResourceMgr.cpp.
References CHECK_EQ, executor_stats_, logger::INFO, LOG, pause_process_queue_, process_queue_is_paused_, processor_queue_condition_, processor_queue_mutex_, ExecutorResourceMgr_Namespace::ExecutorStats::requests_executing, and should_process_queue_.
Referenced by set_concurrent_resource_grant_policy(), and set_resource().
void ExecutorResourceMgr_Namespace::ExecutorResourceMgr::set_concurrent_resource_grant_policy | ( | const ConcurrentResourceGrantPolicy & | concurrent_resource_grant_policy | ) |
Set the concurrent resource grant policy for a given resource type (stored in ConcurrentResourceGrantPolicy
)
concurrent_resource_grant_policy | - Object containing the resource type and the concurrency policies for when the resource is undersubscribed and oversubscribed |
Definition at line 298 of file ExecutorResourceMgr.cpp.
References CHECK, ExecutorResourceMgr_Namespace::ConcurrentResourceGrantPolicy::concurrency_policy, executor_resource_pool_, ExecutorResourceMgr_Namespace::ExecutorResourcePool::get_concurrent_resource_grant_policy(), ExecutorResourceMgr_Namespace::ConcurrentResourceGrantPolicy::oversubscription_concurrency_policy, pause_process_queue(), ExecutorResourceMgr_Namespace::ConcurrentResourceGrantPolicy::resource_type, resume_process_queue(), and ExecutorResourceMgr_Namespace::ExecutorResourcePool::set_concurrent_resource_grant_policy().
|
inlineprivate |
Internal method: Set the should_process_queue_
flag to true, signifying that the queue should be processed. Protected by a lock on processor_queue_mutex_
.
Invoked in two places: 1) release_resources
(as the resources have been returned to the pool, potentially permitting granting of resources to another request) 2) After enqueue_request
, as we have a new request to evaluate whether if it can be served
Definition at line 401 of file ExecutorResourceMgr.h.
References processor_queue_mutex_, and should_process_queue_.
Referenced by release_resources(), and request_resources_with_timeout().
void ExecutorResourceMgr_Namespace::ExecutorResourceMgr::set_resource | ( | const ResourceType | resource_type, |
const size_t | resoure_quantity | ||
) |
Used to change the total amount available of a specified resource after construction of ExecutorResourceMgr
Currently only used for testing, but could also be used to provide adminstrator DDL commands to change resource availability in a running server
resource_type | - Type of resource to alter the quantity of |
resoure_quantity | - The new quantity available of the resource |
Definition at line 282 of file ExecutorResourceMgr.cpp.
References CHECK_EQ, executor_resource_pool_, get_resource_info(), pause_process_queue(), resume_process_queue(), and ExecutorResourceMgr_Namespace::ExecutorResourcePool::set_resource().
|
private |
Internal method: Invoked from ExecutorResourceMgr
destructor, sets stop_process_queue_thread_
to true (behind a lock on processor_queue_mutex_
) and then attempts to join all threads left in the request queue on server shutdown.
Definition at line 236 of file ExecutorResourceMgr.cpp.
References process_queue_thread_, processor_queue_condition_, processor_queue_mutex_, and stop_process_queue_thread_.
Referenced by ~ExecutorResourceMgr().
|
private |
Definition at line 477 of file ExecutorResourceMgr.h.
Referenced by mark_request_dequed().
|
private |
Definition at line 558 of file ExecutorResourceMgr.h.
Referenced by choose_next_request(), process_queue_loop(), and request_resources_with_timeout().
|
private |
Definition at line 557 of file ExecutorResourceMgr.h.
Referenced by process_queue_loop().
|
private |
Set of all request ids that are currently executing (i.e. post-granting of resources). Protected by executing_set_mutex_
.
Definition at line 540 of file ExecutorResourceMgr.h.
Referenced by add_request_to_stage(), get_requests_for_stage(), and remove_request_from_stage().
|
mutableprivate |
RW mutex that protects access to executing_requests_
Definition at line 512 of file ExecutorResourceMgr.h.
Referenced by add_request_to_stage(), get_requests_for_stage(), and remove_request_from_stage().
|
private |
Keeps track of available resources for execution.
Definition at line 461 of file ExecutorResourceMgr.h.
Referenced by choose_next_request(), get_concurrent_resource_grant_policy(), get_resource_info(), process_queue_loop(), release_resources(), request_resources_with_timeout(), set_concurrent_resource_grant_policy(), and set_resource().
|
private |
Holds a single ExecutorStats
struct that pertains to cummulative stats for ExecutorResourceMgr
, i.e. number of requests, queue length, total execution time, etc.
Definition at line 475 of file ExecutorResourceMgr.h.
Referenced by enqueue_request(), get_executor_stats(), mark_request_dequed(), mark_request_finished(), mark_request_timed_out(), pause_process_queue(), process_queue_loop(), and resume_process_queue().
|
private |
Definition at line 560 of file ExecutorResourceMgr.h.
Referenced by choose_next_request(), and process_queue_loop().
|
private |
Definition at line 562 of file ExecutorResourceMgr.h.
Referenced by choose_next_request(), and ExecutorResourceMgr().
|
private |
Stores and manages a map of request ids to BinarySemaphore
objects to allow threads waiting for resources to be selectively queued/blocked and then when they are choosen for resource grants/execution, woken.
Definition at line 528 of file ExecutorResourceMgr.h.
Referenced by process_queue_loop(), and request_resources_with_timeout().
|
private |
Definition at line 519 of file ExecutorResourceMgr.h.
Referenced by pause_process_queue(), process_queue_loop(), and resume_process_queue().
|
private |
Definition at line 515 of file ExecutorResourceMgr.h.
Referenced by pause_process_queue(), and process_queue_loop().
|
mutableprivate |
Definition at line 495 of file ExecutorResourceMgr.h.
Referenced by pause_process_queue(), and process_queue_loop().
|
mutableprivate |
Definition at line 496 of file ExecutorResourceMgr.h.
Referenced by choose_next_request(), print_executor_stats(), process_queue_loop(), and request_resources_with_timeout().
|
private |
Definition at line 521 of file ExecutorResourceMgr.h.
Referenced by choose_next_request(), print_executor_stats(), and process_queue_loop().
|
private |
Definition at line 520 of file ExecutorResourceMgr.h.
Referenced by pause_process_queue(), process_queue_loop(), and resume_process_queue().
|
private |
The thread started in the ExecutorResourceMgr
constructor that continuously loops inside of process_queue_loop
to determine the next resource request that should be granted.
When the database is stopped/shut down, join will be called on this thread to clean up outstanding threads waiting on resource requests
Definition at line 487 of file ExecutorResourceMgr.h.
Referenced by ExecutorResourceMgr(), and stop_process_queue_thread().
|
private |
Definition at line 514 of file ExecutorResourceMgr.h.
Referenced by pause_process_queue(), process_queue_loop(), release_resources(), request_resources_with_timeout(), resume_process_queue(), and stop_process_queue_thread().
|
mutableprivate |
RW mutex that protects access to stop_process_queue_thread_
and pause_processor_queue_
Definition at line 493 of file ExecutorResourceMgr.h.
Referenced by pause_process_queue(), process_queue_loop(), resume_process_queue(), set_process_queue_flag(), and stop_process_queue_thread().
|
mutableprivate |
RW mutex that protects access to executor_stats_
and request_stats_
Definition at line 502 of file ExecutorResourceMgr.h.
Referenced by choose_next_request(), enqueue_request(), get_chunk_request_info(), get_executor_stats(), get_request_for_id(), mark_request_dequed(), mark_request_error(), mark_request_finished(), mark_request_timed_out(), and request_resources_with_timeout().
|
private |
Set of all request ids that are currently queued. Protected by queued_set_mutex_
.
Definition at line 534 of file ExecutorResourceMgr.h.
Referenced by add_request_to_stage(), get_requests_for_stage(), and remove_request_from_stage().
|
mutableprivate |
RW mutex that protects access to queued_requests_
Definition at line 507 of file ExecutorResourceMgr.h.
Referenced by add_request_to_stage(), get_requests_for_stage(), and remove_request_from_stage().
|
private |
An atomic that is incremented with each incoming request, and used to assign RequestIds
to incoming request.
Definition at line 468 of file ExecutorResourceMgr.h.
Referenced by enqueue_request(), mark_request_dequed(), mark_request_finished(), and mark_request_timed_out().
|
private |
Stores a vector of all requests that have been seen by ExecutorResourceMgr
, with each incoming request appending a RequestStats
struct to this vector. Protected by queue_stats_mutex_
.
With a long-running server this vector could become quite long, but the RequestStats
objects are light enough where the total memory needed should still be negligible compared to all the other things stored in the server (even 100K requests would only total to a handful of MB). The longer-term goal for this state is for ExecutorResourceMgr
to use it as historical data to optimize query/request scheduling based on usage/request patterns.
Definition at line 555 of file ExecutorResourceMgr.h.
Referenced by choose_next_request(), enqueue_request(), get_chunk_request_info(), get_request_for_id(), mark_request_dequed(), mark_request_error(), mark_request_finished(), mark_request_timed_out(), and request_resources_with_timeout().
|
private |
Definition at line 517 of file ExecutorResourceMgr.h.
Referenced by process_queue_loop(), resume_process_queue(), and set_process_queue_flag().
|
private |
Definition at line 518 of file ExecutorResourceMgr.h.
Referenced by process_queue_loop(), and stop_process_queue_thread().