mirror of
https://github.com/CrowCpp/Crow.git
synced 2024-06-07 21:10:44 +00:00
Change += to ++, add queue length decrementation on error
This commit is contained in:
parent
f8af9eb187
commit
2607bf5791
@ -407,7 +407,7 @@ namespace crow
|
|||||||
do_write_general();
|
do_write_general();
|
||||||
}
|
}
|
||||||
|
|
||||||
queue_length -= 1;
|
queue_length--;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -182,7 +182,7 @@ namespace crow
|
|||||||
int min_queue_idx = 0;
|
int min_queue_idx = 0;
|
||||||
|
|
||||||
// TODO improve load balancing
|
// TODO improve load balancing
|
||||||
for (uint i = 1; i < task_queue_length_pool_.size(); i += 1)
|
for (uint16_t i = 1; i < task_queue_length_pool_.size(); i++)
|
||||||
{
|
{
|
||||||
if (task_queue_length_pool_[i] < task_queue_length_pool_[min_queue_idx])
|
if (task_queue_length_pool_[i] < task_queue_length_pool_[min_queue_idx])
|
||||||
min_queue_idx = i;
|
min_queue_idx = i;
|
||||||
@ -194,10 +194,12 @@ namespace crow
|
|||||||
{
|
{
|
||||||
int service_idx = pick_io_service_idx();
|
int service_idx = pick_io_service_idx();
|
||||||
asio::io_service& is = *io_service_pool_[service_idx];
|
asio::io_service& is = *io_service_pool_[service_idx];
|
||||||
|
task_queue_length_pool_[service_idx]++;
|
||||||
|
|
||||||
auto p = new Connection<Adaptor, Handler, Middlewares...>(
|
auto p = new Connection<Adaptor, Handler, Middlewares...>(
|
||||||
is, handler_, server_name_, middlewares_,
|
is, handler_, server_name_, middlewares_,
|
||||||
get_cached_date_str_pool_[service_idx], *task_timer_pool_[service_idx], adaptor_ctx_, task_queue_length_pool_[service_idx]);
|
get_cached_date_str_pool_[service_idx], *task_timer_pool_[service_idx], adaptor_ctx_, task_queue_length_pool_[service_idx]);
|
||||||
task_queue_length_pool_[service_idx] += 1;
|
|
||||||
acceptor_.async_accept(
|
acceptor_.async_accept(
|
||||||
p->socket(),
|
p->socket(),
|
||||||
[this, p, &is](boost::system::error_code ec) {
|
[this, p, &is](boost::system::error_code ec) {
|
||||||
@ -210,6 +212,7 @@ namespace crow
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
task_queue_length_pool_[service_idx]--;
|
||||||
delete p;
|
delete p;
|
||||||
}
|
}
|
||||||
do_accept();
|
do_accept();
|
||||||
@ -221,7 +224,7 @@ namespace crow
|
|||||||
std::vector<std::unique_ptr<asio::io_service>> io_service_pool_;
|
std::vector<std::unique_ptr<asio::io_service>> io_service_pool_;
|
||||||
std::vector<detail::task_timer*> task_timer_pool_;
|
std::vector<detail::task_timer*> task_timer_pool_;
|
||||||
std::vector<std::function<std::string()>> get_cached_date_str_pool_;
|
std::vector<std::function<std::string()>> get_cached_date_str_pool_;
|
||||||
std::vector<int> task_queue_length_pool_;
|
std::vector<std::atomic<uint>> task_queue_length_pool_;
|
||||||
tcp::acceptor acceptor_;
|
tcp::acceptor acceptor_;
|
||||||
boost::asio::signal_set signals_;
|
boost::asio::signal_set signals_;
|
||||||
boost::asio::deadline_timer tick_timer_;
|
boost::asio::deadline_timer tick_timer_;
|
||||||
|
Loading…
Reference in New Issue
Block a user