From c209cf830bebf2de98afe4167b9f06de042f02b2 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 8 Apr 2019 09:43:00 +0200 Subject: [PATCH] /v1/events: don't over-consume CPU-bound threads --- lib/remote/eventshandler.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/remote/eventshandler.cpp b/lib/remote/eventshandler.cpp index 5ac1062df..e92b14a2d 100644 --- a/lib/remote/eventshandler.cpp +++ b/lib/remote/eventshandler.cpp @@ -102,12 +102,10 @@ bool EventsHandler::HandleRequest( response.result(http::status::ok); response.set(http::field::content_type, "application/json"); - { - IoBoundWorkSlot dontLockTheIoThreadWhileWriting (yc); + IoBoundWorkSlot dontLockTheIoThread (yc); - http::async_write(stream, response, yc); - stream.async_flush(yc); - } + http::async_write(stream, response, yc); + stream.async_flush(yc); asio::const_buffer newLine ("\n", 1); @@ -115,13 +113,15 @@ bool EventsHandler::HandleRequest( auto event (subscriber.GetInbox()->Shift(yc)); if (event) { + CpuBoundWork buildingResponse (yc); + String body = JsonEncode(event); boost::algorithm::replace_all(body, "\n", ""); asio::const_buffer payload (body.CStr(), body.GetLength()); - IoBoundWorkSlot dontLockTheIoThreadWhileWriting (yc); + buildingResponse.Done(); asio::async_write(stream, payload, yc); asio::async_write(stream, newLine, yc);