mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-28 08:04:14 +02:00
[Refactor] CpuBoundWork#CpuBoundWork(): require an io_context::strand
This commit is contained in:
parent
9018385c1a
commit
659bb9e03a
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
CpuBoundWork::CpuBoundWork(boost::asio::yield_context yc)
|
CpuBoundWork::CpuBoundWork(boost::asio::yield_context yc, boost::asio::io_context::strand&)
|
||||||
: m_Done(false)
|
: m_Done(false)
|
||||||
{
|
{
|
||||||
auto& ioEngine (IoEngine::Get());
|
auto& ioEngine (IoEngine::Get());
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <boost/exception/all.hpp>
|
#include <boost/exception/all.hpp>
|
||||||
#include <boost/asio/deadline_timer.hpp>
|
#include <boost/asio/deadline_timer.hpp>
|
||||||
#include <boost/asio/io_context.hpp>
|
#include <boost/asio/io_context.hpp>
|
||||||
|
#include <boost/asio/io_context_strand.hpp>
|
||||||
#include <boost/asio/spawn.hpp>
|
#include <boost/asio/spawn.hpp>
|
||||||
|
|
||||||
#if BOOST_VERSION >= 108700
|
#if BOOST_VERSION >= 108700
|
||||||
@ -37,7 +38,7 @@ namespace icinga
|
|||||||
class CpuBoundWork
|
class CpuBoundWork
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CpuBoundWork(boost::asio::yield_context yc);
|
CpuBoundWork(boost::asio::yield_context yc, boost::asio::io_context::strand&);
|
||||||
CpuBoundWork(const CpuBoundWork&) = delete;
|
CpuBoundWork(const CpuBoundWork&) = delete;
|
||||||
CpuBoundWork(CpuBoundWork&&) = delete;
|
CpuBoundWork(CpuBoundWork&&) = delete;
|
||||||
CpuBoundWork& operator=(const CpuBoundWork&) = delete;
|
CpuBoundWork& operator=(const CpuBoundWork&) = delete;
|
||||||
|
@ -424,7 +424,8 @@ bool ProcessRequest(
|
|||||||
bool& hasStartedStreaming,
|
bool& hasStartedStreaming,
|
||||||
const WaitGroup::Ptr& waitGroup,
|
const WaitGroup::Ptr& waitGroup,
|
||||||
std::chrono::steady_clock::duration& cpuBoundWorkTime,
|
std::chrono::steady_clock::duration& cpuBoundWorkTime,
|
||||||
boost::asio::yield_context& yc
|
boost::asio::yield_context& yc,
|
||||||
|
boost::asio::io_context::strand& strand
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
namespace http = boost::beast::http;
|
namespace http = boost::beast::http;
|
||||||
@ -432,7 +433,7 @@ bool ProcessRequest(
|
|||||||
try {
|
try {
|
||||||
// Cache the elapsed time to acquire a CPU semaphore used to detect extremely heavy workloads.
|
// Cache the elapsed time to acquire a CPU semaphore used to detect extremely heavy workloads.
|
||||||
auto start (std::chrono::steady_clock::now());
|
auto start (std::chrono::steady_clock::now());
|
||||||
CpuBoundWork handlingRequest (yc);
|
CpuBoundWork handlingRequest (yc, strand);
|
||||||
cpuBoundWorkTime = std::chrono::steady_clock::now() - start;
|
cpuBoundWorkTime = std::chrono::steady_clock::now() - start;
|
||||||
|
|
||||||
Defer resetHandlingRequest ([&m_HandlingRequest] { m_HandlingRequest = nullptr; });
|
Defer resetHandlingRequest ([&m_HandlingRequest] { m_HandlingRequest = nullptr; });
|
||||||
@ -555,7 +556,7 @@ void HttpServerConnection::ProcessMessages(boost::asio::yield_context yc)
|
|||||||
|
|
||||||
m_Seen = std::numeric_limits<decltype(m_Seen)>::max();
|
m_Seen = std::numeric_limits<decltype(m_Seen)>::max();
|
||||||
|
|
||||||
if (!ProcessRequest(*m_Stream, request, authenticatedUser, response, *this, m_HandlingRequest, m_HasStartedStreaming, m_WaitGroup, cpuBoundWorkTime, yc)) {
|
if (!ProcessRequest(*m_Stream, request, authenticatedUser, response, *this, m_HandlingRequest, m_HasStartedStreaming, m_WaitGroup, cpuBoundWorkTime, yc, m_IoStrand)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ void JsonRpcConnection::HandleIncomingMessages(boost::asio::yield_context yc)
|
|||||||
auto start (ch::steady_clock::now());
|
auto start (ch::steady_clock::now());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CpuBoundWork handleMessage (yc);
|
CpuBoundWork handleMessage (yc, m_IoStrand);
|
||||||
|
|
||||||
// Cache the elapsed time to acquire a CPU semaphore used to detect extremely heavy workloads.
|
// Cache the elapsed time to acquire a CPU semaphore used to detect extremely heavy workloads.
|
||||||
cpuBoundDuration = ch::steady_clock::now() - start;
|
cpuBoundDuration = ch::steady_clock::now() - start;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user