From 1682ff283936fd5c6f127b73678292c72985ad1d Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 5 Apr 2013 14:05:00 +0200 Subject: [PATCH] Optimize replication messages. --- components/replication/replicationcomponent.cpp | 4 ++++ lib/base/dynamicobject.cpp | 12 ++++++++++-- lib/base/dynamicobject.h | 3 +++ lib/base/fifo.cpp | 16 ++-------------- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/components/replication/replicationcomponent.cpp b/components/replication/replicationcomponent.cpp index a347fc662..34912851e 100644 --- a/components/replication/replicationcomponent.cpp +++ b/components/replication/replicationcomponent.cpp @@ -181,6 +181,10 @@ void ReplicationComponent::FlushObjectHandler(double tx, const DynamicObject::Pt if (!ShouldReplicateObject(object)) return; + /* Don't replicate objects that haven't had any local updates. */ + if (object->GetLocalTx() < tx) + return; + RequestMessage request = MakeObjectMessage(object, "config::ObjectUpdate", tx, true); EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint, request); } diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp index fe1873d76..1418d1756 100644 --- a/lib/base/dynamicobject.cpp +++ b/lib/base/dynamicobject.cpp @@ -49,7 +49,7 @@ boost::signals2::signal&)> boost::signals2::signal DynamicObject::OnFlushObject; DynamicObject::DynamicObject(const Dictionary::Ptr& serializedObject) - : m_ConfigTx(0), m_Registered(false) + : m_ConfigTx(0), m_LocalTx(0), m_Registered(false) { RegisterAttribute("__name", Attribute_Config, &m_Name); RegisterAttribute("__type", Attribute_Config, &m_Type); @@ -241,7 +241,9 @@ void DynamicObject::Touch(const String& name) if (it == m_Attributes.end()) BOOST_THROW_EXCEPTION(std::runtime_error("Touch() called for unknown attribute: " + name)); - it->second.SetTx(GetCurrentTx()); + double tx = GetCurrentTx(); + it->second.SetTx(tx); + m_LocalTx = tx; m_ModifiedAttributes.insert(name); @@ -251,6 +253,12 @@ void DynamicObject::Touch(const String& name) } } +double DynamicObject::GetLocalTx(void) const +{ + boost::mutex::scoped_lock lock(m_AttributeMutex); + return m_LocalTx; +} + Value DynamicObject::Get(const String& name) const { ASSERT(!OwnsLock()); diff --git a/lib/base/dynamicobject.h b/lib/base/dynamicobject.h index b3a809454..0ad599c74 100644 --- a/lib/base/dynamicobject.h +++ b/lib/base/dynamicobject.h @@ -90,6 +90,8 @@ public: virtual void Start(void); virtual void Stop(void); + double GetLocalTx(void) const; + const AttributeMap& GetAttributes(void) const; static DynamicObject::Ptr GetObject(const String& type, const String& name); @@ -117,6 +119,7 @@ private: AttributeMap m_Attributes; std::set m_ModifiedAttributes; double m_ConfigTx; + double m_LocalTx; Attribute m_Name; Attribute m_Type; diff --git a/lib/base/fifo.cpp b/lib/base/fifo.cpp index d0f6bbc8b..cc12f422f 100644 --- a/lib/base/fifo.cpp +++ b/lib/base/fifo.cpp @@ -65,26 +65,14 @@ void FIFO::ResizeBuffer(size_t newSize) */ void FIFO::Optimize(void) { - //char *newBuffer; - if (m_DataSize < m_Offset) { memcpy(m_Buffer, m_Buffer + m_Offset, m_DataSize); m_Offset = 0; + ResizeBuffer(m_DataSize); + return; } - - /*newBuffer = (char *)ResizeBuffer(NULL, 0, m_BufferSize - m_Offset); - - if (newBuffer == NULL) - return; - - memcpy(newBuffer, m_Buffer + m_Offset, m_BufferSize - m_Offset); - - free(m_Buffer); - m_Buffer = newBuffer; - m_BufferSize -= m_Offset; - m_Offset = 0;*/ } /**