[ovs-dev] [PATCH] bridge: Rate limit instant stats.
Ethan Jackson
ethan at nicira.com
Wed Sep 19 21:57:15 UTC 2012
The during a typical run loop, the refresh_instant_stats() function
creates a transaction, populates it with writes that do nothing,
and destroys it. This turns out to be fairly expensive causing
ovs-vswitchd to show higher than expected cpu usage. This patch
remedies the issue by rate limiting refresh_instant_stats() to once
every 50 milliseconds.
Signed-off-by: Ethan Jackson <ethan at nicira.com>
---
vswitchd/bridge.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index 53bb7b9..2e6ce81 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -153,6 +153,13 @@ static unsigned int idl_seqno;
#define IFACE_STATS_INTERVAL (5 * 1000) /* In milliseconds. */
static long long int iface_stats_timer = LLONG_MIN;
+/* Rate limter for refresh_instant_stats(). Should be small enough that
+ * changes appear in the database "instantly", but large enough that
+ * performance isn't penalized by creating and destroying empty transactions.
+ */
+#define INSTANT_STATS_RATE_LIMIT 50 /* In milliseconds.*/
+static long long int instant_stats_timer = 0;
+
/* In some datapaths, creating and destroying OpenFlow ports can be extremely
* expensive. This can cause bridge_reconfigure() to take a long time during
* which no other work can be done. To deal with this problem, we limit port
@@ -1960,10 +1967,12 @@ static void
refresh_instant_stats(void)
{
static struct ovsdb_idl_txn *txn = NULL;
+ long long int now = time_msec();
- if (!txn) {
+ if (!txn && instant_stats_timer <= now) {
struct bridge *br;
+ instant_stats_timer = now + INSTANT_STATS_RATE_LIMIT;
txn = ovsdb_idl_txn_create(idl);
HMAP_FOR_EACH (br, node, &all_bridges) {
@@ -2014,7 +2023,7 @@ refresh_instant_stats(void)
}
}
- if (ovsdb_idl_txn_commit(txn) != TXN_INCOMPLETE) {
+ if (txn && ovsdb_idl_txn_commit(txn) != TXN_INCOMPLETE) {
ovsdb_idl_txn_destroy(txn);
txn = NULL;
}
@@ -2184,6 +2193,10 @@ bridge_wait(void)
ofproto_wait(br->ofproto);
}
poll_timer_wait_until(iface_stats_timer);
+
+ if (time_msec() <= instant_stats_timer) {
+ poll_timer_wait_until(instant_stats_timer);
+ }
}
system_stats_wait();
--
1.7.12
More information about the dev
mailing list