bridge: Allow users to configure statistics update to OVSDB.
authorAlex Wang <alexw@nicira.com>
Thu, 3 Apr 2014 20:27:22 +0000 (13:27 -0700)
committerAlex Wang <alexw@nicira.com>
Fri, 2 May 2014 20:29:40 +0000 (13:29 -0700)
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.

The configured value should always be greater than or equal to
5000 ms.  And more frequent statistics update should be achieved
via OpenFlow.

Signed-off-by: Alex Wang <alexw@nicira.com>
Acked-by: Joe Stringer <joestringer@nicira.com>
tests/ovs-vswitchd.at
vswitchd/bridge.c
vswitchd/vswitch.xml

index c552741..a90477d 100644 (file)
@@ -25,3 +25,44 @@ AT_CAPTURE_FILE([ovs-vswitchd.log])
 
 dnl ovs-vswitchd detached OK or we wouldn't have made it this far.  Success.
 AT_CLEANUP
 
 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 set the stats update interval to 100K ms, the following 'recv' should not be updated.
+AT_CHECK([ovs-vsctl set O . other_config:stats-update-interval=100000])
+for i in `seq 0 50`; 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
+
+OVS_VSCTL_CHECK_RX_PKT([p1], [1])
+dnl advance the clock by 100K ms, the previous 'recv' should be updated.
+for i in `seq 0 99`; do ovs-appctl time/warp 1000; done
+OVS_VSCTL_CHECK_RX_PKT([p1], [6])
+
+dnl now remove the configuration. 'recv' one packet.  there should be an update after 5000 ms.
+AT_CHECK([ovs-vsctl clear O . other_config])
+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
index 12852b4..1145e98 100644 (file)
@@ -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. */
 
 /* 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
 
 /* 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
@@ -2275,6 +2275,7 @@ bridge_run(void)
 
     bool vlan_splinters_changed;
     struct bridge *br;
 
     bool vlan_splinters_changed;
     struct bridge *br;
+    int stats_interval;
 
     ovsrec_open_vswitch_init(&null_cfg);
 
 
     ovsrec_open_vswitch_init(&null_cfg);
 
@@ -2380,8 +2381,17 @@ bridge_run(void)
         }
     }
 
         }
     }
 
+    /* Statistics update interval should always be greater than or equal to
+     * 5000 ms. */
+    stats_interval = MAX(smap_get_int(&cfg->other_config,
+                                      "stats-update-interval", 5000), 5000);
+    if (stats_timer_interval != stats_interval) {
+        stats_timer_interval = stats_interval;
+        stats_timer = LLONG_MIN;
+    }
+
     /* Refresh interface and mirror stats if necessary. */
     /* 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;
 
         if (cfg) {
             struct ovsdb_idl_txn *txn;
 
@@ -2410,7 +2420,7 @@ bridge_run(void)
             ovsdb_idl_txn_destroy(txn); /* XXX */
         }
 
             ovsdb_idl_txn_destroy(txn); /* XXX */
         }
 
-        iface_stats_timer = time_msec() + IFACE_STATS_INTERVAL;
+        stats_timer = time_msec() + stats_timer_interval;
     }
 
     if (!status_txn) {
     }
 
     if (!status_txn) {
@@ -2477,7 +2487,8 @@ bridge_wait(void)
         HMAP_FOR_EACH (br, node, &all_bridges) {
             ofproto_wait(br->ofproto);
         }
         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,
     }
 
     /* If the status database transaction is 'TXN_INCOMPLETE' in this run,
index 7f2fd58..a351813 100644 (file)
         host as displayed by <code>xe host-list</code>.
       </column>
 
         host as displayed by <code>xe host-list</code>.
       </column>
 
+      <column name="other_config" key="stats-update-interval"
+              type='{"type": "integer", "minInteger": 5000}'>
+        <p>
+          Interval for updating statistics to the 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>
+        <p>
+          Default value is 5000 ms.
+        </p>
+        <p>
+          Getting statistics more frequently can be achieved via OpenFlow.
+        </p>
+      </column>
+
       <column name="other_config" key="flow-restore-wait"
               type='{"type": "boolean"}'>
         <p>
       <column name="other_config" key="flow-restore-wait"
               type='{"type": "boolean"}'>
         <p>
 
     <group title="Port Statistics">
       <p>
 
     <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"/> in the <code>Open_vSwitch</code> table.
       </p>
       <group title="Statistics: STP transmit and receive counters">
         <column name="statistics" key="stp_tx_count">
       </p>
       <group title="Statistics: STP transmit and receive counters">
         <column name="statistics" key="stp_tx_count">
     <group title="Statistics">
       <p>
         Key-value pairs that report interface statistics.  The current
     <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"/> in the <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
       </p>
       <p>
         These are the same statistics reported by OpenFlow in its <code>struct
 
     <group title="Statistics: Mirror counters">
       <p>
 
     <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"/> in the <code>Open_vSwitch</code> table.
       </p>
       <column name="statistics" key="tx_packets">
         Number of packets transmitted through this mirror.
       </p>
       <column name="statistics" key="tx_packets">
         Number of packets transmitted through this mirror.