[ovs-dev] [PATCH 3/3] OVSDB: Flush JSON cache only when necessary

Andy Zhou azhou at nicira.com
Thu Jun 11 01:37:59 UTC 2015


Currently, JSON cache is always flushed whenever the monitor receives
a transaction. This patch improves the JSON cache efficiency by only
flush the JSON cache when a transaction causes client visible
changes, avoiding unnecessary flushes.

Suggested-by: Ben Pfaff <blp at nicira.com>
Signed-off-by: Andy Zhou <azhou at nicira.com>
---
 ovsdb/monitor.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/ovsdb/monitor.c b/ovsdb/monitor.c
index d9ac6d8..bf7dd6b 100644
--- a/ovsdb/monitor.c
+++ b/ovsdb/monitor.c
@@ -698,6 +698,7 @@ enum ovsdb_monitor_changes_efficacy {
 struct ovsdb_monitor_aux {
     const struct ovsdb_monitor *monitor;
     struct ovsdb_monitor_table *mt;
+    enum ovsdb_monitor_changes_efficacy efficacy;
 };
 
 static void
@@ -706,6 +707,7 @@ ovsdb_monitor_init_aux(struct ovsdb_monitor_aux *aux,
 {
     aux->monitor = m;
     aux->mt = NULL;
+    aux->efficacy = OVSDB_CHANGES_NO_EFFECT;
 }
 
 static void
@@ -807,6 +809,10 @@ ovsdb_monitor_change_cb(const struct ovsdb_row *old,
         if (efficacy > OVSDB_CHANGES_NO_EFFECT) {
             ovsdb_monitor_changes_update(old, new, mt, changes);
         }
+
+        if (aux->efficacy < efficacy) {
+            aux->efficacy = efficacy;
+        }
     }
 
     return true;
@@ -1001,10 +1007,13 @@ ovsdb_monitor_commit(struct ovsdb_replica *replica,
     struct ovsdb_monitor *m = ovsdb_monitor_cast(replica);
     struct ovsdb_monitor_aux aux;
 
-    ovsdb_monitor_json_cache_flush(m);
     ovsdb_monitor_init_aux(&aux, m);
     ovsdb_txn_for_each_change(txn, ovsdb_monitor_change_cb, &aux);
-    m->n_transactions++;
+
+    if (aux.efficacy == OVSDB_CHANGES_REQUIRE_EXTERNAL_UPDATE) {
+        ovsdb_monitor_json_cache_flush(m);
+        m->n_transactions++;
+    }
 
     return NULL;
 }
-- 
1.9.1




More information about the dev mailing list