From ea0a9ae7abd6b3aed44fa4051ecaca6476f788fa Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Mon, 30 Jul 2007 14:48:56 +0100 Subject: [PATCH] EventCollector: tune the parameters and add a shrinking heuristic. --- src/simulator/event-collector.cc | 23 +++++++++++++++++++---- src/simulator/event-collector.h | 2 ++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/simulator/event-collector.cc b/src/simulator/event-collector.cc index a804df4d8..d47b4cc84 100644 --- a/src/simulator/event-collector.cc +++ b/src/simulator/event-collector.cc @@ -19,10 +19,9 @@ * Author: Gustavo J. A. M. Carneiro */ #include "event-collector.h" -#include #define CLEANUP_CHUNK_MIN_SIZE 8 -#define CLEANUP_CHUNK_MAX_SIZE 1024 +#define CLEANUP_CHUNK_MAX_SIZE 128 namespace ns3 { @@ -46,6 +45,21 @@ EventExpiredPredicate (const EventId &event) return event.IsExpired (); } +void +EventCollector::Grow () +{ + m_nextCleanupSize += (m_nextCleanupSize < CLEANUP_CHUNK_MAX_SIZE? + m_nextCleanupSize : CLEANUP_CHUNK_MAX_SIZE); +} + +void +EventCollector::Shrink () +{ + while (m_nextCleanupSize > m_events.size ()) + m_nextCleanupSize >>= 1; + Grow (); +} + // Called when a new event was added and the cleanup limit was exceeded in consequence. void EventCollector::Cleanup () @@ -54,8 +68,9 @@ EventCollector::Cleanup () // If after cleanup we are still over the limit, increase the limit. if (m_events.size () >= m_nextCleanupSize) - m_nextCleanupSize = std::min (std::list::size_type (CLEANUP_CHUNK_MAX_SIZE), - m_nextCleanupSize<<1); + Grow (); + else + Shrink (); } diff --git a/src/simulator/event-collector.h b/src/simulator/event-collector.h index 7cf7c28db..d0e48460d 100644 --- a/src/simulator/event-collector.h +++ b/src/simulator/event-collector.h @@ -53,6 +53,8 @@ private: std::list m_events; void Cleanup (); + void Grow (); + void Shrink (); }; }; // namespace ns3