-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expire: Add EXP_Reduce() for better softpurges #4085
Conversation
Can't this be done with just a few lines of changes to |
I think one goal is precisely to not prevent |
Changing the behavior of Regarding code duplication, I tried to strike a middleground between code reuse and readability. But maybe there is a better way to structure it that I'm not seeing? |
How would changing the logging break VMODs? |
I had something like this in mind: diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index 2b27371ba..2d8b34de4 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -262,6 +262,23 @@ EXP_Rearm(struct objcore *oc, vtim_real now,
oc->timer_when, when, oc->flags);
}
+
+void
+EXP_Reduce(struct objcore *oc, vtim_real now,
+ vtim_real ttl, vtim_real grace, vtim_real keep)
+{
+
+ CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+
+ if (!isnan(ttl)) {
+ ttl = now + ttl - oc->t_origin;
+ if (ttl >= oc->ttl)
+ ttl = nan("");
+ }
+
+ EXP_Rearm(oc, now, ttl, grace, keep);
+}
+
/*--------------------------------------------------------------------
* Handle stuff in the inbox
*/ |
Ah, now I get what you mean, that is a clever solution I had not considered. I will reattempt the patch series based on your example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, except one detail.
bin/varnishd/cache/cache_expire.c
Outdated
EXP_Reduce(struct objcore *oc, vtim_real now, | ||
vtim_real ttl, vtim_real grace, vtim_real keep) | ||
{ | ||
float next_ttl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vtim_dur
for everything except now
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I will change ttl
, grace
and keep
to vtim_dur
. As for next_ttl
, looks like this local variable can be eliminated now
This commit introduces EXP_Reduce(), a function to reduce object timers. The goal is to provide a function better suited to soft-purging objects, as EXP_Rearm() has some non-obvious disadvantages when used or this purpose. When EXP_Rearm() is used to soft-purge an object by setting its TTL to 0, the expiry is effectively reset to the start of the objects grace period. This happens because the object TTL includes a time delta between object insertion time (oc->t_origin) and now. The result is that a soft-purge extends the lifetime of an already stale object, and repeated soft-purges can keep the object away from expiry indefinitely. The EXP_Reduce() function is better suited for soft-purging, as it only updates an objects TTL if it would reduce the objects lifetime. The function also has facilities for reducing grace and keep.
When a stale object is soft-purged, the time until the object expires should not be reset, as repeated soft-purges could keep the object around indefinitely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @nigoroll too!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a good and useful change, and this is the right time to merge it. I have one question, but it can be left for "later".
also approved by @bsdphk during bugwash |
Hi, Is it possible to report this fix on 7.5 branch and release a minor version ? We have a similar behavior when expiring objects that could look like this. |
This PR resolves an issue where softpurging an object would reset its expiry timer to the start of the objects grace period. Repeated softpurges of the same object would keep it away from expiry indefinetly, and softpurging an object in keep would bring it back into grace.
The effects of the current softpurge implementation are most severe when the cache contains a high number of objects that are regularly hit by key-based invalidation. This can result in a growing number of objects in cache, increasing load on the expiry thread mailbox, and contention on the
exp
mutex. Grace hits on stale objects long past their indended lifetime can also occur.This patch series introduces
EXP_Reduce()
as an alternative toEXP_Rearm()
for softpurging applications.purge.soft()
has been changed to use the new function, and the VCC has been updated with the following: