Limit the frequency of db sync

If exception occurs when processing a northbound event, one second delay
will be introduced by db sync, it leads to more exceptions because of
the delay. Avalanche will occur then. This patch limits the frequency of
db sync by one time every three minutes at maximum.

Closes-Bug: #1583992

Change-Id: I2f2635467b8fc5ab816ea4ac355e3e1cc488d5a2
This commit is contained in:
duankebo 2016-05-23 08:18:00 +00:00 committed by Kebo Duan
parent 8b96a42ebf
commit 6062a43170
2 changed files with 7 additions and 2 deletions

View File

@ -26,7 +26,8 @@ from oslo_serialization import jsonutils
from dragonflow._i18n import _LI, _LW, _LE
from dragonflow.common import utils as df_utils
from dragonflow.db.db_common import DbUpdate, SEND_ALL_TOPIC
from dragonflow.db.db_common import DbUpdate, SEND_ALL_TOPIC, \
DB_SYNC_MINIMUM_INTERVAL
from dragonflow.db import pub_sub_api
eventlet.monkey_patch()
@ -157,6 +158,8 @@ class NbApi(object):
eventlet.sleep(0)
def _read_db_changes_from_queue(self):
sync_rate_limiter = df_utils.RateLimiter(
max_rate=1, time_unit=DB_SYNC_MINIMUM_INTERVAL)
while True:
self.next_update = self._queue.get(block=True)
LOG.debug("Event update: %s", self.next_update)
@ -176,7 +179,8 @@ class NbApi(object):
except Exception as e:
if "ofport is 0" not in e.message:
LOG.exception(e)
self.apply_db_change(None, None, 'sync', None)
if not sync_rate_limiter():
self.apply_db_change(None, None, 'sync', None)
def apply_db_change(self, table, key, action, value):
# determine if the action is allowed or not

View File

@ -15,6 +15,7 @@
from oslo_utils import timeutils
SEND_ALL_TOPIC = b'D'
DB_SYNC_MINIMUM_INTERVAL = 180
class DbUpdate(object):