mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 07:04:37 +02:00
/v1/events: don't over-consume CPU-bound threads
This commit is contained in:
parent
5e8b4280bc
commit
c209cf830b
@ -102,12 +102,10 @@ bool EventsHandler::HandleRequest(
|
|||||||
response.result(http::status::ok);
|
response.result(http::status::ok);
|
||||||
response.set(http::field::content_type, "application/json");
|
response.set(http::field::content_type, "application/json");
|
||||||
|
|
||||||
{
|
IoBoundWorkSlot dontLockTheIoThread (yc);
|
||||||
IoBoundWorkSlot dontLockTheIoThreadWhileWriting (yc);
|
|
||||||
|
|
||||||
http::async_write(stream, response, yc);
|
http::async_write(stream, response, yc);
|
||||||
stream.async_flush(yc);
|
stream.async_flush(yc);
|
||||||
}
|
|
||||||
|
|
||||||
asio::const_buffer newLine ("\n", 1);
|
asio::const_buffer newLine ("\n", 1);
|
||||||
|
|
||||||
@ -115,13 +113,15 @@ bool EventsHandler::HandleRequest(
|
|||||||
auto event (subscriber.GetInbox()->Shift(yc));
|
auto event (subscriber.GetInbox()->Shift(yc));
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
|
CpuBoundWork buildingResponse (yc);
|
||||||
|
|
||||||
String body = JsonEncode(event);
|
String body = JsonEncode(event);
|
||||||
|
|
||||||
boost::algorithm::replace_all(body, "\n", "");
|
boost::algorithm::replace_all(body, "\n", "");
|
||||||
|
|
||||||
asio::const_buffer payload (body.CStr(), body.GetLength());
|
asio::const_buffer payload (body.CStr(), body.GetLength());
|
||||||
|
|
||||||
IoBoundWorkSlot dontLockTheIoThreadWhileWriting (yc);
|
buildingResponse.Done();
|
||||||
|
|
||||||
asio::async_write(stream, payload, yc);
|
asio::async_write(stream, payload, yc);
|
||||||
asio::async_write(stream, newLine, yc);
|
asio::async_write(stream, newLine, yc);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user