summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/broker/RateTracker.cpp
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2008-10-14 11:06:41 +0000
committerGordon Sim <gsim@apache.org>2008-10-14 11:06:41 +0000
commit137eaf938a010d8bb5d248c094891f7a2925ef55 (patch)
treec5760a56966c1b48ba50cc516d1cbb8f42d2a7d2 /cpp/src/qpid/broker/RateTracker.cpp
parent76dc7ca3e92919d83932e66906425067652e76f5 (diff)
downloadqpid-python-137eaf938a010d8bb5d248c094891f7a2925ef55.tar.gz
Update to periodic purge of expired messages: check the dequeue rate to avoid interfering unnecessarily where the dequeing is sufficient to remove expired messages.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@704461 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/broker/RateTracker.cpp')
-rw-r--r--cpp/src/qpid/broker/RateTracker.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/cpp/src/qpid/broker/RateTracker.cpp b/cpp/src/qpid/broker/RateTracker.cpp
new file mode 100644
index 0000000000..5377bcfc0b
--- /dev/null
+++ b/cpp/src/qpid/broker/RateTracker.cpp
@@ -0,0 +1,48 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+#include "RateTracker.h"
+
+using qpid::sys::AbsTime;
+using qpid::sys::Duration;
+using qpid::sys::TIME_SEC;
+
+namespace qpid {
+namespace broker {
+
+RateTracker::RateTracker() : currentCount(0), lastCount(0), lastTime(AbsTime::now()) {}
+
+RateTracker& RateTracker::operator++()
+{
+ ++currentCount;
+ return *this;
+}
+
+double RateTracker::sampleRatePerSecond()
+{
+ int32_t increment = currentCount - lastCount;
+ AbsTime now = AbsTime::now();
+ Duration interval(lastTime, now);
+ lastCount = currentCount;
+ lastTime = now;
+ return increment ? increment / (interval / TIME_SEC) : 0;
+}
+
+}} // namespace qpid::broker