]> granicus.if.org Git - icinga2/commitdiff
/v1/events: don't over-consume CPU-bound threads
authorAlexander A. Klimov <alexander.klimov@icinga.com>
Mon, 8 Apr 2019 07:43:00 +0000 (09:43 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Thu, 25 Apr 2019 13:56:38 +0000 (15:56 +0200)
lib/remote/eventshandler.cpp

index 5ac1062df2d8bb0f353ad85784a46f1fce0f4b9c..e92b14a2d4cb33ad4a0e7a6ea2f015ca45cd0aba 100644 (file)
@@ -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);