]> granicus.if.org Git - icinga2/commitdiff
Performance improvements.
authorGunnar Beutner <gunnar@beutner.name>
Fri, 22 Jun 2012 21:19:10 +0000 (23:19 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Fri, 22 Jun 2012 21:19:10 +0000 (23:19 +0200)
base/tcpclient.cpp
base/tcpclient.h
base/timer.cpp
components/delegation/delegationcomponent.cpp
components/delegation/delegationcomponent.h
jsonrpc/jsonrpcclient.cpp
jsonrpc/netstring.cpp
jsonrpc/netstring.h

index 0314f132af84c65a8d8306c40c76b012b1c77f19..70fa814067a91dbfb25b6e04193586a89045a893 100644 (file)
@@ -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.
  */
index 59e8392c1169f1315da472b01a4a1d3aef158474..048e8dad692765649e958dabfde7b984ca4b97ab 100644 (file)
@@ -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;
 
index 61ad89c9ce3e350a8547028f507d7771bd8cffcf..5e97e585981cf54e56926ee98a1234ea583e448c 100644 (file)
@@ -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;
 }
 
index da2c503932aef1ab1fa96cf6e067943e950474c6..bc4a40acdcf32cded9581f099d01388521cc0262 100644 (file)
@@ -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)
index 1369f04253a41b5e14955b1cc0d5848137870dcf..dea7ce26c814bc8f95da28b742787c87ec383564 100644 (file)
@@ -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;
index 76ecc483a050def5f12175e7b6f5d988de829422..c95b049b119b40ea6a26b0ce31eac2141050a61d 100644 (file)
@@ -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);
index 9b9c4428fd25093f3978da31e4924bf535753f06..fb4c9673447449b5bdc808a90dd6ed62b3abc255 100644 (file)
@@ -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();
 }
index e59540bcf43b3f609818db6669aaf733f935c0fa..7561a312418df371204df4ac0cfb584e12903f9a 100644 (file)
@@ -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);