Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/crow/http_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ namespace crow
res_stream_threshold_(handler->stream_threshold()),
queue_length_(queue_length)
{
queue_length_++;
#ifdef CROW_ENABLE_DEBUG
connectionCount++;
CROW_LOG_DEBUG << "Connection (" << this << ") allocated, total: " << connectionCount;
Expand All @@ -77,6 +78,7 @@ namespace crow

~Connection()
{
queue_length_--;
#ifdef CROW_ENABLE_DEBUG
connectionCount--;
CROW_LOG_DEBUG << "Connection (" << this << ") freed, total: " << connectionCount;
Expand Down
22 changes: 8 additions & 14 deletions include/crow/http_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ namespace crow // NOTE: Already documented in "crow/app.h"
uint16_t concurrency = 1,
uint8_t timeout = 5,
typename Adaptor::context* adaptor_ctx = nullptr):
concurrency_(concurrency),
task_queue_length_pool_(concurrency_ - 1),
acceptor_(io_context_),
signals_(io_context_),
tick_timer_(io_context_),
handler_(handler),
concurrency_(concurrency),
timeout_(timeout),
server_name_(server_name),
task_queue_length_pool_(concurrency_ - 1),
middlewares_(middlewares),
adaptor_ctx_(adaptor_ctx)
{
Expand Down Expand Up @@ -300,12 +300,11 @@ namespace crow // NOTE: Already documented in "crow/app.h"
{
uint16_t context_idx = pick_io_context_idx();
asio::io_context& ic = *io_context_pool_[context_idx];
task_queue_length_pool_[context_idx]++;
CROW_LOG_DEBUG << &ic << " {" << context_idx << "} queue length: " << task_queue_length_pool_[context_idx];

auto p = std::make_shared<Connection<Adaptor, Handler, Middlewares...>>(
ic, handler_, server_name_, middlewares_,
get_cached_date_str_pool_[context_idx], *task_timer_pool_[context_idx], adaptor_ctx_, task_queue_length_pool_[context_idx]);
ic, handler_, server_name_, middlewares_,
get_cached_date_str_pool_[context_idx], *task_timer_pool_[context_idx], adaptor_ctx_, task_queue_length_pool_[context_idx]);

CROW_LOG_DEBUG << &ic << " {" << context_idx << "} queue length: " << task_queue_length_pool_[context_idx];

acceptor_.async_accept(
p->socket(),
Expand All @@ -317,11 +316,6 @@ namespace crow // NOTE: Already documented in "crow/app.h"
p->start();
});
}
else
{
task_queue_length_pool_[context_idx]--;
CROW_LOG_DEBUG << &ic << " {" << context_idx << "} queue length: " << task_queue_length_pool_[context_idx];
}
do_accept();
});
}
Expand All @@ -336,6 +330,8 @@ namespace crow // NOTE: Already documented in "crow/app.h"
}

private:
uint16_t concurrency_{2};
std::vector<std::atomic<unsigned int>> task_queue_length_pool_;
std::vector<std::unique_ptr<asio::io_context>> io_context_pool_;
asio::io_context io_context_;
std::vector<detail::task_timer*> task_timer_pool_;
Expand All @@ -351,10 +347,8 @@ namespace crow // NOTE: Already documented in "crow/app.h"
asio::basic_waitable_timer<std::chrono::high_resolution_clock> tick_timer_;

Handler* handler_;
uint16_t concurrency_{2};
std::uint8_t timeout_;
std::string server_name_;
std::vector<std::atomic<unsigned int>> task_queue_length_pool_;

std::chrono::milliseconds tick_interval_;
std::function<void()> tick_function_;
Expand Down
Loading