lease: prune lease as soon as expired
We detected a performance issue on a dnsmasq running many dhcp sessions
(more than 10 000). At the end of the day, the server was only releasing
old DHCP leases but was consuming a lot of CPU.
It looks like curent dhcp pruning:
1) it's pruning old sessions (iterate on all current leases). It's
important to note that it's only pruning session expired since more
than one second
2) it's looking for next lease to expire (iterate on all current leases
again)
3) it launchs an alarm to catch next expiration found in step 2). This
value can be zero for leases just expired (but not pruned).
So, for a second, dnsmasq could fall in a "prune loop" by doing:
* Not pruning anything, since difftime() is not > 0
* Run alarm again with zero as argument
On a server with very large number of leases and releasing often
sessions, that can waste a very big CPU time.
Signed-off-by: Florent Fourcot <florent.fourcot@wifirst.fr>
diff --git a/src/lease.c b/src/lease.c
index 86862cc..f14d128 100644
--- a/src/lease.c
+++ b/src/lease.c
@@ -558,7 +558,7 @@
for (lease = leases, up = &leases; lease; lease = tmp)
{
tmp = lease->next;
- if ((lease->expires != 0 && difftime(now, lease->expires) > 0) || lease == target)
+ if ((lease->expires != 0 && difftime(now, lease->expires) >= 0) || lease == target)
{
file_dirty = 1;
if (lease->hostname)