mirror of
https://github.com/Icinga/icinga2.git
synced 2025-05-19 22:10:22 +02:00
Merge pull request #6133 from Icinga/fix/cork-socket
Limit the number of HTTP/JSON-RPC requests we read in parallel
This commit is contained in:
commit
a3bf8cd26e
@ -91,6 +91,16 @@ bool Stream::WaitForData(int timeout)
|
|||||||
return IsDataAvailable() || IsEof();
|
return IsDataAvailable() || IsEof();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Stream::SetCorked(bool corked)
|
||||||
|
{
|
||||||
|
m_Corked = corked;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Stream::IsCorked() const
|
||||||
|
{
|
||||||
|
return m_Corked;
|
||||||
|
}
|
||||||
|
|
||||||
static void StreamDummyCallback()
|
static void StreamDummyCallback()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
@ -127,6 +127,9 @@ public:
|
|||||||
bool WaitForData();
|
bool WaitForData();
|
||||||
bool WaitForData(int timeout);
|
bool WaitForData(int timeout);
|
||||||
|
|
||||||
|
virtual void SetCorked(bool corked);
|
||||||
|
bool IsCorked() const;
|
||||||
|
|
||||||
virtual bool SupportsWaiting() const;
|
virtual bool SupportsWaiting() const;
|
||||||
|
|
||||||
virtual bool IsDataAvailable() const;
|
virtual bool IsDataAvailable() const;
|
||||||
@ -143,6 +146,8 @@ private:
|
|||||||
|
|
||||||
boost::mutex m_Mutex;
|
boost::mutex m_Mutex;
|
||||||
boost::condition_variable m_CV;
|
boost::condition_variable m_CV;
|
||||||
|
|
||||||
|
bool m_Corked{false};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -151,12 +151,17 @@ void TlsStream::OnEvent(int revents)
|
|||||||
char buffer[64 * 1024];
|
char buffer[64 * 1024];
|
||||||
|
|
||||||
if (m_CurrentAction == TlsActionNone) {
|
if (m_CurrentAction == TlsActionNone) {
|
||||||
if (revents & (POLLIN | POLLERR | POLLHUP))
|
bool corked = IsCorked();
|
||||||
|
if (!corked && (revents & (POLLIN | POLLERR | POLLHUP)))
|
||||||
m_CurrentAction = TlsActionRead;
|
m_CurrentAction = TlsActionRead;
|
||||||
else if (m_SendQ->GetAvailableBytes() > 0 && (revents & POLLOUT))
|
else if (m_SendQ->GetAvailableBytes() > 0 && (revents & POLLOUT))
|
||||||
m_CurrentAction = TlsActionWrite;
|
m_CurrentAction = TlsActionWrite;
|
||||||
else {
|
else {
|
||||||
ChangeEvents(POLLIN);
|
if (corked)
|
||||||
|
ChangeEvents(0);
|
||||||
|
else
|
||||||
|
ChangeEvents(POLLIN);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -399,6 +404,18 @@ bool TlsStream::IsDataAvailable() const
|
|||||||
return m_RecvQ->GetAvailableBytes() > 0;
|
return m_RecvQ->GetAvailableBytes() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TlsStream::SetCorked(bool corked)
|
||||||
|
{
|
||||||
|
Stream::SetCorked(corked);
|
||||||
|
|
||||||
|
boost::mutex::scoped_lock lock(m_Mutex);
|
||||||
|
|
||||||
|
if (corked)
|
||||||
|
m_CurrentAction = TlsActionNone;
|
||||||
|
else
|
||||||
|
ChangeEvents(POLLIN | POLLOUT);
|
||||||
|
}
|
||||||
|
|
||||||
Socket::Ptr TlsStream::GetSocket() const
|
Socket::Ptr TlsStream::GetSocket() const
|
||||||
{
|
{
|
||||||
return m_Socket;
|
return m_Socket;
|
||||||
|
@ -70,6 +70,8 @@ public:
|
|||||||
bool SupportsWaiting() const override;
|
bool SupportsWaiting() const override;
|
||||||
bool IsDataAvailable() const override;
|
bool IsDataAvailable() const override;
|
||||||
|
|
||||||
|
void SetCorked(bool corked) override;
|
||||||
|
|
||||||
bool IsVerifyOK() const;
|
bool IsVerifyOK() const;
|
||||||
String GetVerifyError() const;
|
String GetVerifyError() const;
|
||||||
|
|
||||||
|
@ -96,7 +96,6 @@ void HttpServerConnection::Disconnect()
|
|||||||
|
|
||||||
bool HttpServerConnection::ProcessMessage()
|
bool HttpServerConnection::ProcessMessage()
|
||||||
{
|
{
|
||||||
|
|
||||||
bool res;
|
bool res;
|
||||||
HttpResponse response(m_Stream, m_CurrentRequest);
|
HttpResponse response(m_Stream, m_CurrentRequest);
|
||||||
|
|
||||||
@ -174,6 +173,8 @@ bool HttpServerConnection::ProcessMessage()
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_Stream->SetCorked(true);
|
||||||
|
|
||||||
m_RequestQueue.Enqueue(std::bind(&HttpServerConnection::ProcessMessageAsync,
|
m_RequestQueue.Enqueue(std::bind(&HttpServerConnection::ProcessMessageAsync,
|
||||||
HttpServerConnection::Ptr(this), m_CurrentRequest, response, m_AuthenticatedUser));
|
HttpServerConnection::Ptr(this), m_CurrentRequest, response, m_AuthenticatedUser));
|
||||||
|
|
||||||
@ -328,6 +329,7 @@ void HttpServerConnection::ProcessMessageAsync(HttpRequest& request, HttpRespons
|
|||||||
|
|
||||||
response.Finish();
|
response.Finish();
|
||||||
m_PendingRequests--;
|
m_PendingRequests--;
|
||||||
|
m_Stream->SetCorked(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpServerConnection::DataAvailableHandler()
|
void HttpServerConnection::DataAvailableHandler()
|
||||||
|
@ -155,6 +155,8 @@ void JsonRpcConnection::MessageHandlerWrapper(const String& jsonString)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
MessageHandler(jsonString);
|
MessageHandler(jsonString);
|
||||||
|
|
||||||
|
m_Stream->SetCorked(false);
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
Log(LogWarning, "JsonRpcConnection")
|
Log(LogWarning, "JsonRpcConnection")
|
||||||
<< "Error while reading JSON-RPC message for identity '" << m_Identity
|
<< "Error while reading JSON-RPC message for identity '" << m_Identity
|
||||||
@ -255,6 +257,8 @@ bool JsonRpcConnection::ProcessMessage()
|
|||||||
if (srs != StatusNewItem)
|
if (srs != StatusNewItem)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
m_Stream->SetCorked(true);
|
||||||
|
|
||||||
l_JsonRpcConnectionWorkQueues[m_ID % l_JsonRpcConnectionWorkQueueCount].Enqueue(std::bind(&JsonRpcConnection::MessageHandlerWrapper, JsonRpcConnection::Ptr(this), message));
|
l_JsonRpcConnectionWorkQueues[m_ID % l_JsonRpcConnectionWorkQueueCount].Enqueue(std::bind(&JsonRpcConnection::MessageHandlerWrapper, JsonRpcConnection::Ptr(this), message));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user