qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject svn commit: r1154377 - /qpid/trunk/qpid/cpp/src/qpid/sys/PollableQueue.h
Date Fri, 05 Aug 2011 20:52:37 GMT
Author: aconway
Date: Fri Aug  5 20:52:37 2011
New Revision: 1154377

URL: http://svn.apache.org/viewvc?rev=1154377&view=rev
Log:
QPID-3399: Qpidd possible memory leaks

Replace vector with deque in PollableQueue.  Under load the queue can
get long, and a vector, which allocates space in a single block, is a
memory hog. A deque will give and take memory in reasonable chunks as
the queue grows and shrinks.

Modified:
    qpid/trunk/qpid/cpp/src/qpid/sys/PollableQueue.h

Modified: qpid/trunk/qpid/cpp/src/qpid/sys/PollableQueue.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/PollableQueue.h?rev=1154377&r1=1154376&r2=1154377&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/PollableQueue.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/PollableQueue.h Fri Aug  5 20:52:37 2011
@@ -10,9 +10,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -28,7 +28,8 @@
 #include <boost/function.hpp>
 #include <boost/bind.hpp>
 #include <algorithm>
-#include <vector>
+#include <deque>
+#include "qpid/log/Statement.h" // FIXME aconway 2011-08-05:
 
 namespace qpid {
 namespace sys {
@@ -44,7 +45,7 @@ class Poller;
 template <class T>
 class PollableQueue {
   public:
-    typedef std::vector<T> Batch;
+    typedef std::deque<T> Batch;
     typedef T value_type;
 
     /**
@@ -68,11 +69,11 @@ class PollableQueue {
                   const boost::shared_ptr<sys::Poller>& poller);
 
     ~PollableQueue();
-    
+
     /** Push a value onto the queue. Thread safe */
     void push(const T& t);
 
-    /** Start polling. */ 
+    /** Start polling. */
     void start();
 
     /** Stop polling and wait for the current callback, if any, to complete. */
@@ -90,14 +91,14 @@ class PollableQueue {
      * ensure clean shutdown with no events left on the queue.
      */
     void shutdown();
-    
+
   private:
     typedef sys::Monitor::ScopedLock ScopedLock;
     typedef sys::Monitor::ScopedUnlock ScopedUnlock;
 
     void dispatch(PollableCondition& cond);
     void process();
-    
+
     mutable sys::Monitor lock;
     Callback callback;
     PollableCondition condition;
@@ -107,7 +108,7 @@ class PollableQueue {
 };
 
 template <class T> PollableQueue<T>::PollableQueue(
-    const Callback& cb, const boost::shared_ptr<sys::Poller>& p) 
+    const Callback& cb, const boost::shared_ptr<sys::Poller>& p)
   : callback(cb),
     condition(boost::bind(&PollableQueue<T>::dispatch, this, _1), p),
     stopped(true)
@@ -151,7 +152,7 @@ template <class T> void PollableQueue<T>
             putBack = callback(batch);
         }
         // put back unprocessed items.
-        queue.insert(queue.begin(), putBack, typename Batch::const_iterator(batch.end()));

+        queue.insert(queue.begin(), putBack, typename Batch::const_iterator(batch.end()));
         batch.clear();
     }
 }



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org


Mime
View raw message