[ovs-dev] [PATCH] bridge: Allow users to configure statistics update to OVSDB.
Alex Wang
alexw at nicira.com
Tue Apr 29 17:29:56 UTC 2014
This commit adds a new configuration "stats-update-interval" in
"other_config" of Open_Vswitch table. So users can control the
statistics update frequency. A possible use case is that, users
can lower the update frequency to reduce the cpu consumption of
the ovs-vswitchd thread.
Signed-off-by: Alex Wang <alexw at nicira.com>
---
tests/ovs-vswitchd.at | 45 +++++++++++++++++++++++++++++++++++++++++++++
vswitchd/bridge.c | 19 ++++++++++++++-----
vswitchd/vswitch.xml | 32 ++++++++++++++++++++++++--------
3 files changed, 83 insertions(+), 13 deletions(-)
diff --git a/tests/ovs-vswitchd.at b/tests/ovs-vswitchd.at
index c552741..e839160 100644
--- a/tests/ovs-vswitchd.at
+++ b/tests/ovs-vswitchd.at
@@ -25,3 +25,48 @@ AT_CAPTURE_FILE([ovs-vswitchd.log])
dnl ovs-vswitchd detached OK or we wouldn't have made it this far. Success.
AT_CLEANUP
+
+
+dnl ----------------------------------------------------------------------
+m4_define([OVS_VSCTL_CHECK_RX_PKT], [
+AT_CHECK([ovs-vsctl list int $1 | grep statistics | sed -n 's/^.*\(rx_packets=[[0-9]]\+\).*$/\1/p'],[0],
+[dnl
+rx_packets=$2
+])
+])
+
+AT_SETUP([ovs-vswitchd -- stats-update-interval])
+OVS_VSWITCHD_START([add-port br0 p1 -- set int p1 type=internal])
+ovs-appctl time/stop
+
+dnl at the beginning, the udpate of rx_packets should happen every 5 seconds.
+for i in `seq 0 10`; do ovs-appctl time/warp 1000; done
+OVS_VSCTL_CHECK_RX_PKT([p1], [0])
+AT_CHECK([ovs-appctl netdev-dummy/receive p1 'eth(src=50:54:00:00:00:09,dst=50:54:00:00:00:0a),eth_type(0x0800),ipv4(src=10.0.0.2,dst=10.0.0.1,proto=1,tos=0,ttl=64,frag=no),icmp(type=8,code=0)'])
+for i in `seq 0 10`; do ovs-appctl time/warp 1000; done
+OVS_VSCTL_CHECK_RX_PKT([p1], [1])
+
+dnl disable the stats update, the following 'recv' should not be updated.
+AT_CHECK([ovs-vsctl set O . other_config:stats-update-interval=10000000])
+for i in `seq 0 10`; do ovs-appctl time/warp 1000; done
+for i in `seq 1 5`; do
+ AT_CHECK([ovs-appctl netdev-dummy/receive p1 'eth(src=50:54:00:00:00:09,dst=50:54:00:00:00:0a),eth_type(0x0800),ipv4(src=10.0.0.2,dst=10.0.0.1,proto=1,tos=0,ttl=64,frag=no),icmp(type=8,code=0)'])
+done
+
+for i in `seq 0 50`; do
+ ovs-appctl time/warp 1000;
+ OVS_VSCTL_CHECK_RX_PKT([p1], [1])
+done
+
+dnl now remove the configuration. there should be an update.
+AT_CHECK([ovs-vsctl clear O . other_config])
+for i in `seq 0 5`; do ovs-appctl time/warp 1000; done
+OVS_VSCTL_CHECK_RX_PKT([p1], [6])
+
+dnl now, the stats should be updated normally (every 5 seconds by default).
+AT_CHECK([ovs-appctl netdev-dummy/receive p1 'eth(src=50:54:00:00:00:09,dst=50:54:00:00:00:0a),eth_type(0x0800),ipv4(src=10.0.0.2,dst=10.0.0.1,proto=1,tos=0,ttl=64,frag=no),icmp(type=8,code=0)'])
+for i in `seq 0 10`; do ovs-appctl time/warp 1000; done
+OVS_VSCTL_CHECK_RX_PKT([p1], [7])
+
+OVS_VSWITCHD_STOP
+AT_CLEANUP
\ No newline at end of file
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index 84e9ab8..741efeb 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -182,8 +182,8 @@ static struct ovsdb_idl_txn *status_txn;
/* Each time this timer expires, the bridge fetches interface and mirror
* statistics and pushes them into the database. */
-#define IFACE_STATS_INTERVAL (5 * 1000) /* In milliseconds. */
-static long long int iface_stats_timer = LLONG_MIN;
+static int stats_timer_interval;
+static long long int stats_timer = LLONG_MIN;
/* Set to true to allow experimental use of OpenFlow 1.4.
* This is false initially because OpenFlow 1.4 is not yet safe to use: it can
@@ -2282,6 +2282,7 @@ bridge_run(void)
bool vlan_splinters_changed;
struct bridge *br;
+ int stats_interval;
ovsrec_open_vswitch_init(&null_cfg);
@@ -2387,8 +2388,15 @@ bridge_run(void)
}
}
+ stats_interval = smap_get_int(&cfg->other_config,
+ "stats-update-interval", 5000);
+ if (stats_timer_interval != stats_interval) {
+ stats_timer_interval = stats_interval;
+ stats_timer = LLONG_MIN;
+ }
+
/* Refresh interface and mirror stats if necessary. */
- if (time_msec() >= iface_stats_timer) {
+ if (time_msec() >= stats_timer) {
if (cfg) {
struct ovsdb_idl_txn *txn;
@@ -2417,7 +2425,7 @@ bridge_run(void)
ovsdb_idl_txn_destroy(txn); /* XXX */
}
- iface_stats_timer = time_msec() + IFACE_STATS_INTERVAL;
+ stats_timer = time_msec() + stats_timer_interval;
}
if (!status_txn) {
@@ -2484,7 +2492,8 @@ bridge_wait(void)
HMAP_FOR_EACH (br, node, &all_bridges) {
ofproto_wait(br->ofproto);
}
- poll_timer_wait_until(iface_stats_timer);
+
+ poll_timer_wait_until(stats_timer);
}
/* If the status database transaction is 'TXN_INCOMPLETE' in this run,
diff --git a/vswitchd/vswitch.xml b/vswitchd/vswitch.xml
index 78594e7..4212a16 100644
--- a/vswitchd/vswitch.xml
+++ b/vswitchd/vswitch.xml
@@ -72,6 +72,16 @@
host as displayed by <code>xe host-list</code>.
</column>
+ <column name="other_config" key="stats-update-interval"
+ type='{"type": "integer"}'>
+ <p>
+ Period of statistics update to database, in milliseconds. This
+ option will affect the update of the <code>statistics</code> column
+ in the following tables: <code>Port</code>, <code>Interface</code>,
+ <code>Mirror</code>.
+ </p>
+ </column>
+
<column name="other_config" key="flow-restore-wait"
type='{"type": "boolean"}'>
<p>
@@ -1211,7 +1221,9 @@
<group title="Port Statistics">
<p>
- Key-value pairs that report port statistics.
+ Key-value pairs that report port statistics. The update period
+ is controlled by <ref column="other_config"
+ key="stats-update-interval"/> of <code>Open_vSwitch</code> table.
</p>
<group title="Statistics: STP transmit and receive counters">
<column name="statistics" key="stp_tx_count">
@@ -1769,12 +1781,14 @@
<group title="Statistics">
<p>
Key-value pairs that report interface statistics. The current
- implementation updates these counters periodically. Future
- implementations may update them when an interface is created, when they
- are queried (e.g. using an OVSDB <code>select</code> operation), and
- just before an interface is deleted due to virtual interface hot-unplug
- or VM shutdown, and perhaps at other times, but not on any regular
- periodic basis.
+ implementation updates these counters periodically. The update period
+ is controlled by <ref column="other_config"
+ key="stats-update-interval"/> of <code>Open_vSwitch</code> table.
+ Future implementations may update them when an interface is created,
+ when they are queried (e.g. using an OVSDB <code>select</code>
+ operation), and just before an interface is deleted due to virtual
+ interface hot-unplug or VM shutdown, and perhaps at other times, but
+ not on any regular periodic basis.
</p>
<p>
These are the same statistics reported by OpenFlow in its <code>struct
@@ -2894,7 +2908,9 @@
<group title="Statistics: Mirror counters">
<p>
- Key-value pairs that report mirror statistics.
+ Key-value pairs that report mirror statistics. The update period
+ is controlled by <ref column="other_config"
+ key="stats-update-interval"/> of <code>Open_vSwitch</code> table.
</p>
<column name="statistics" key="tx_packets">
Number of packets transmitted through this mirror.
--
1.7.9.5
More information about the dev
mailing list