Seastar
High performance C++ framework for concurrent servers
|
Fair queuing class.
This is a fair queue, allowing multiple request producers to queue requests that will then be served proportionally to their classes' shares.
To each request, a weight can also be associated. A request of weight 1 will consume 1 share. Higher weights for a request will consume a proportionally higher amount of shares.
The user of this interface is expected to register multiple priority_class_data
objects, which will each have a shares attribute.
Internally, each priority class may keep a separate queue of requests. Requests pertaining to a class can go through even if they are over its share limit, provided that the other classes have empty queues.
When the classes that lag behind start seeing requests, the fair queue will serve them first, until balance is restored. This balancing is expected to happen within a certain time window that obeys an exponential decay.
#include <seastar/core/fair_queue.hh>
Classes | |
struct | config |
Fair Queue configuration structure. More... | |
Public Types | |
using | class_id = unsigned int |
using | capacity_t = fair_group::capacity_t |
using | signed_capacity_t = std::make_signed< capacity_t >::type |
Public Member Functions | |
fair_queue (fair_group &shared, config cfg) | |
fair_queue (fair_queue &&) | |
sstring | label () const noexcept |
void | register_priority_class (class_id c, uint32_t shares) |
void | unregister_priority_class (class_id c) |
void | update_shares_for_class (class_id c, uint32_t new_shares) |
size_t | waiters () const |
size_t | requests_currently_executing () const |
fair_queue_ticket | resources_currently_waiting () const |
fair_queue_ticket | resources_currently_executing () const |
void | queue (class_id c, fair_queue_entry &ent) noexcept |
void | plug_class (class_id c) noexcept |
void | unplug_class (class_id c) noexcept |
void | notify_request_finished (fair_queue_ticket desc) noexcept |
void | notify_request_cancelled (fair_queue_entry &ent) noexcept |
void | dispatch_requests (std::function< void(fair_queue_entry &)> cb) |
Try to execute new requests if there is capacity left in the queue. | |
clock_type::time_point | next_pending_aio () const noexcept |
std::vector< seastar::metrics::impl::metric_definition_impl > | metrics (class_id c) |
|
explicit |
Constructs a fair queue with configuration parameters cfg
.
cfg | an instance of the class config |
|
noexcept |
Notifies that ont request finished
desc | an instance of fair_queue_ticket structure describing the request that just finished. |
|
noexcept |
Queue the entry ent
through this class' fair_queue
The user of this interface is supposed to call notify_requests_finished when the request finishes executing - regardless of success or failure.
void seastar::fair_queue::register_priority_class | ( | class_id | c, |
uint32_t | shares | ||
) |
Registers a priority class against this fair queue.
shares | how many shares to create this class with |
size_t seastar::fair_queue::requests_currently_executing | ( | ) | const |
fair_queue_ticket seastar::fair_queue::resources_currently_executing | ( | ) | const |
fair_queue_ticket seastar::fair_queue::resources_currently_waiting | ( | ) | const |
void seastar::fair_queue::unregister_priority_class | ( | class_id | c | ) |
Unregister a priority class.
It is illegal to unregister a priority class that still have pending requests.
size_t seastar::fair_queue::waiters | ( | ) | const |