From: Gunnar Beutner Date: Fri, 22 Jun 2012 21:19:10 +0000 (+0200) Subject: Performance improvements. X-Git-Tag: v0.0.1~370 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d1f4d9b8298cc02f58c478fbc0543ded665727fa;p=icinga2 Performance improvements. --- diff --git a/base/tcpclient.cpp b/base/tcpclient.cpp index 0314f132a..70fa81406 100644 --- a/base/tcpclient.cpp +++ b/base/tcpclient.cpp @@ -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. */ diff --git a/base/tcpclient.h b/base/tcpclient.h index 59e8392c1..048e8dad6 100644 --- a/base/tcpclient.h +++ b/base/tcpclient.h @@ -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; diff --git a/base/timer.cpp b/base/timer.cpp index 61ad89c9c..5e97e5859 100644 --- a/base/timer.cpp +++ b/base/timer.cpp @@ -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; } diff --git a/components/delegation/delegationcomponent.cpp b/components/delegation/delegationcomponent.cpp index da2c50393..bc4a40acd 100644 --- a/components/delegation/delegationcomponent.cpp +++ b/components/delegation/delegationcomponent.cpp @@ -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) diff --git a/components/delegation/delegationcomponent.h b/components/delegation/delegationcomponent.h index 1369f0425..dea7ce26c 100644 --- a/components/delegation/delegationcomponent.h +++ b/components/delegation/delegationcomponent.h @@ -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 GetCheckerCandidates(const Service& service) const; diff --git a/jsonrpc/jsonrpcclient.cpp b/jsonrpc/jsonrpcclient.cpp index 76ecc483a..c95b049b1 100644 --- a/jsonrpc/jsonrpcclient.cpp +++ b/jsonrpc/jsonrpcclient.cpp @@ -40,7 +40,7 @@ JsonRpcClient::JsonRpcClient(TcpClientRole role, shared_ptr 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); diff --git a/jsonrpc/netstring.cpp b/jsonrpc/netstring.cpp index 9b9c4428f..fb4c96734 100644 --- a/jsonrpc/netstring.cpp +++ b/jsonrpc/netstring.cpp @@ -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(); } diff --git a/jsonrpc/netstring.h b/jsonrpc/netstring.h index e59540bcf..7561a3124 100644 --- a/jsonrpc/netstring.h +++ b/jsonrpc/netstring.h @@ -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);