Branch: Tag:

2017-06-21

2017-06-21 10:12:36 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Filesystem.Monitor: Improved polling heuristic in update().

415:    int delta = max_dir_check_interval || global::max_dir_check_interval;    this::st = st;    +  if (!st || !st->isdir) { +  delta *= file_interval_factor || global::file_interval_factor; +  } +     if (st) {    // Start with a delta proportional to the time since mtime/ctime,    // but bound this to the max setting. A stat in the future will be    // adjusted to the max interval. -  int d = -  (stable_time || global::stable_time) + -  ((time(1) - max(st->mtime, st->ctime)) >> 2); -  if (d < 0) d = max_dir_check_interval || global::max_dir_check_interval; -  if (d < delta) delta = d; +  int mtime = max(st->mtime, st->ctime); +  int d = ((time(1) - mtime) >> 2); +  if (!next_poll && (d >= 0)) { +  // Assume that mtime is reasonable at startup. +  last_change = mtime;    } -  +  if ((d >= 0) && (d < delta)) delta = d; +  }    if (last_change <= time(1)) {    // Time until stable.    int d = last_change + (stable_time || global::stable_time) - time(1);    d >>= 1;    if (d < 0) d = 1;    if (d < delta) delta = d; -  } else if (!st || !st->isdir) { -  delta *= file_interval_factor || global::file_interval_factor; +     } -  +     if (!next_poll) {    // Attempt to distribute polls evenly at startup.    delta = 1 + random(delta);    }    -  +  MON_WERR("Next poll in %d seconds.\n", (delta || 1));    next_poll = time(1) + (delta || 1);    adjust_monitor(this);    }