Skip to content

Commit

Permalink
northd: Short sleeps to accumulate more IDL updates per run.
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya Maximets <[email protected]>
  • Loading branch information
igsilya committed Aug 10, 2023
1 parent 4433406 commit 771208d
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions northd/ovn-northd.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,22 +689,39 @@ run_idl_loop(struct ovsdb_idl_loop *idl_loop, const char *name)
unsigned long long duration, start = time_msec();
unsigned int seqno = UINT_MAX;
struct ovsdb_idl_txn *txn;
int n_before_sleep = -1;
int n = 0;

/* Accumulate database changes as long as there are some,
* but no longer than half a second. */
while (seqno != ovsdb_idl_get_seqno(idl_loop->idl)
&& time_msec() - start < 500) {
seqno = ovsdb_idl_get_seqno(idl_loop->idl);
ovsdb_idl_run(idl_loop->idl);
n++;
for (;;) {
while (seqno != ovsdb_idl_get_seqno(idl_loop->idl)
&& time_msec() - start < 500) {
seqno = ovsdb_idl_get_seqno(idl_loop->idl);
ovsdb_idl_run(idl_loop->idl);
n++;
}
/* If we're not out of time yet, try to sleep for a short 10ms
* in case we'll have more updates. Don't sleep again if there
* were no updates after the previous short sleep. */
if (n > n_before_sleep + 1 && time_msec() - start < 500) {
n_before_sleep = n;
poll_timer_wait(10);
ovsdb_idl_wait(idl_loop->idl);
poll_block();
/* Reset seqno, so we try to run IDL at least one more time. */
seqno = UINT_MAX;
} else {
/* Out of time or no updates since the last sleep. */
break;
}
}

txn = ovsdb_idl_loop_run(idl_loop);

duration = time_msec() - start;
/* ovsdb_idl_run() is called at least 2 times. Once directly and
* once in the ovsdb_idl_loop_run(). n > 2 means that we received
/* ovsdb_idl_run() is called at least 3 times. Once directly and
* once in the ovsdb_idl_loop_run(). n > 3 means that we received
* data on at least 2 subsequent calls. */
if (n > 2 || duration > 100) {
VLOG(duration > 500 ? VLL_INFO : VLL_DBG,
Expand Down

0 comments on commit 771208d

Please sign in to comment.