mirror of https://github.com/Icinga/icinga2.git
Performance improvements.
This commit is contained in:
parent
cae84e9827
commit
d1f4d9b829
|
@ -173,15 +173,6 @@ size_t TcpClient::FillRecvQueue(void)
|
|||
return rc;
|
||||
}
|
||||
|
||||
void TcpClient::Flush(void)
|
||||
{
|
||||
/* try to speculatively flush the buffer if there's a reasonable amount
|
||||
* of data, this may fail, e.g. when the socket cannot immediately
|
||||
* send this much data - the event loop will take care of this later on */
|
||||
if (GetSendQueue()->GetSize() > 128 * 1024)
|
||||
FlushSendQueue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes data that is available for this socket.
|
||||
*/
|
||||
|
|
|
@ -58,8 +58,6 @@ public:
|
|||
FIFO::Ptr GetSendQueue(void);
|
||||
FIFO::Ptr GetRecvQueue(void);
|
||||
|
||||
void Flush(void);
|
||||
|
||||
virtual bool WantsToRead(void) const;
|
||||
virtual bool WantsToWrite(void) const;
|
||||
|
||||
|
|
|
@ -40,6 +40,9 @@ long Timer::ProcessTimers(void)
|
|||
{
|
||||
long wakeup = 30;
|
||||
|
||||
time_t st;
|
||||
time(&st);
|
||||
|
||||
Timer::CollectionType::iterator prev, i;
|
||||
for (i = Timers.begin(); i != Timers.end(); ) {
|
||||
Timer::Ptr timer = i->lock();
|
||||
|
@ -73,6 +76,13 @@ long Timer::ProcessTimers(void)
|
|||
|
||||
assert(wakeup > 0);
|
||||
|
||||
time_t et;
|
||||
time(&et);
|
||||
|
||||
stringstream msgbuf;
|
||||
msgbuf << "Timers took " << et - st << " seconds";
|
||||
Application::Log(LogDebug, "base", msgbuf.str());
|
||||
|
||||
return wakeup;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,20 +65,7 @@ void DelegationComponent::AssignService(const Endpoint::Ptr& checker, const Serv
|
|||
|
||||
Application::Log(LogDebug, "delegation", "Trying to delegate service '" + service.GetName() + "'");
|
||||
|
||||
GetEndpointManager()->SendAPIMessage(m_DelegationEndpoint, checker, request,
|
||||
boost::bind(&DelegationComponent::AssignServiceResponseHandler, this, service, _2, _5));
|
||||
}
|
||||
|
||||
void DelegationComponent::AssignServiceResponseHandler(Service& service, const Endpoint::Ptr& sender, bool timedOut)
|
||||
{
|
||||
/* ignore the message if it's not from the designated checker for this service */
|
||||
if (sender && service.GetChecker() != sender->GetIdentity())
|
||||
return;
|
||||
|
||||
if (timedOut) {
|
||||
Application::Log(LogInformation, "delegation", "Service delegation for service '" + service.GetName() + "' timed out.");
|
||||
service.SetChecker("");
|
||||
}
|
||||
GetEndpointManager()->SendUnicastMessage(m_DelegationEndpoint, checker, request);
|
||||
}
|
||||
|
||||
void DelegationComponent::ClearServices(const Endpoint::Ptr& checker)
|
||||
|
|
|
@ -41,8 +41,6 @@ private:
|
|||
void NewEndpointHandler(const Endpoint::Ptr& endpoint);
|
||||
void SessionEstablishedHandler(const Endpoint::Ptr& endpoint);
|
||||
|
||||
void AssignServiceResponseHandler(Service& service, const Endpoint::Ptr& sender, bool timedOut);
|
||||
|
||||
void DelegationTimerHandler(void);
|
||||
|
||||
vector<Endpoint::Ptr> GetCheckerCandidates(const Service& service) const;
|
||||
|
|
|
@ -40,7 +40,7 @@ JsonRpcClient::JsonRpcClient(TcpClientRole role, shared_ptr<SSL_CTX> sslContext)
|
|||
*/
|
||||
void JsonRpcClient::SendMessage(const MessagePart& message)
|
||||
{
|
||||
Netstring::WriteStringToSocket(GetSelf(), message.ToJsonString());
|
||||
Netstring::WriteStringToFIFO(GetSendQueue(), message.ToJsonString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,7 +53,7 @@ void JsonRpcClient::DataAvailableHandler(void)
|
|||
string jsonString;
|
||||
MessagePart message;
|
||||
|
||||
if (!Netstring::ReadStringFromSocket(GetSelf(), &jsonString))
|
||||
if (!Netstring::ReadStringFromFIFO(GetRecvQueue(), &jsonString))
|
||||
return;
|
||||
|
||||
message = MessagePart(jsonString);
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
using namespace icinga;
|
||||
|
||||
/**
|
||||
* Reads data from a TCP client in netstring format.
|
||||
* Reads data from a FIFO in netstring format.
|
||||
*
|
||||
* @param fifo The FIFO to read from.
|
||||
* @param[out] str The string that has been read from the FIFO.
|
||||
|
@ -30,9 +30,8 @@ using namespace icinga;
|
|||
* @exception InvalidNetstringException The input stream is invalid.
|
||||
* @see https://github.com/PeterScott/netstring-c/blob/master/netstring.c
|
||||
*/
|
||||
bool Netstring::ReadStringFromSocket(const TcpClient::Ptr& client, string *str)
|
||||
bool Netstring::ReadStringFromFIFO(const FIFO::Ptr& fifo, string *str)
|
||||
{
|
||||
FIFO::Ptr fifo = client->GetRecvQueue();
|
||||
size_t buffer_length = fifo->GetSize();
|
||||
char *buffer = (char *)fifo->GetReadBuffer();
|
||||
|
||||
|
@ -76,15 +75,13 @@ bool Netstring::ReadStringFromSocket(const TcpClient::Ptr& client, string *str)
|
|||
}
|
||||
|
||||
/**
|
||||
* Writes data into a TCP client's send buffer using the netstring format.
|
||||
* Writes data into a FIFO using the netstring format.
|
||||
*
|
||||
* @param fifo The FIFO.
|
||||
* @param str The string that is to be written.
|
||||
*/
|
||||
void Netstring::WriteStringToSocket(const TcpClient::Ptr& client, const string& str)
|
||||
void Netstring::WriteStringToFIFO(const FIFO::Ptr& fifo, const string& str)
|
||||
{
|
||||
FIFO::Ptr fifo = client->GetSendQueue();
|
||||
|
||||
stringstream prefixbuf;
|
||||
prefixbuf << str.size() << ":";
|
||||
|
||||
|
@ -93,6 +90,4 @@ void Netstring::WriteStringToSocket(const TcpClient::Ptr& client, const string&
|
|||
fifo->Write(str.c_str(), str.size());
|
||||
|
||||
fifo->Write(",", 1);
|
||||
|
||||
client->Flush();
|
||||
}
|
||||
|
|
|
@ -24,8 +24,7 @@ namespace icinga
|
|||
{
|
||||
|
||||
/**
|
||||
* Thrown when an invalid netstring was encountered while reading from a
|
||||
* TCP client.
|
||||
* Thrown when an invalid netstring was encountered while reading from a FIFO.
|
||||
*
|
||||
* @ingroup jsonrpc
|
||||
*/
|
||||
|
@ -41,8 +40,8 @@ DEFINE_EXCEPTION_CLASS(InvalidNetstringException);
|
|||
class I2_JSONRPC_API Netstring
|
||||
{
|
||||
public:
|
||||
static bool ReadStringFromSocket(const TcpClient::Ptr& client, string *message);
|
||||
static void WriteStringToSocket(const TcpClient::Ptr& client, const string& message);
|
||||
static bool ReadStringFromFIFO(const FIFO::Ptr& fifo, string *message);
|
||||
static void WriteStringToFIFO(const FIFO::Ptr& fifo, const string& message);
|
||||
|
||||
private:
|
||||
Netstring(void);
|
||||
|
|
Loading…
Reference in New Issue