-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
fix(cache): mlcache invalidation use separate cluster event channels to avoid useless invalidation #12321
Conversation
Single service creation test Before:
After:
|
kong/cache/init.lua
Outdated
@@ -140,8 +140,18 @@ function _M.new(opts) | |||
neg_ttl = neg_ttl, | |||
} | |||
|
|||
local ok, err = cluster_events:subscribe("invalidations_" .. shm_name, function(key) |
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.
This will already result in a new channel for each cache - invalidations_kong_db_cache
and invalidations_kong_core_db_cache
. Can we remove the old channel - it isn't part of a public interface so we should be fine removing it?
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 left the old channel deliberately because I've seen some of the custom plugins using this channel to do their validations, considering that this old channel has been here for a long time I think perhaps removing it suddenly will cause some noise
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.
In this case, I feel it would be better to only have one extra new channel, leaving the old one for the core cache, for example. Thoughts?
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.
Hmm, I think if any of these wild custom codes try to push events to the old channel, we won't know whether it is cache or core_cache entity they try to refresh. So maybe leaving the old channel for both is a better idea. How about I add a deprecation warning when the old channel receives events? And we can totally deprecate the old channel in next major
What do you think?
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.
If there is significant risk that removing the event handler for the older invalidations
channel will break existing custom plugins, then I think I could be in favor of keeping it.
Just to sanity check, though: doesn't this argument also apply to our removal of self.cluster_events:broadcast("invalidations", ...)
in favor of the newer channel name? If some custom plugin has registered an event handler for this channel, they will break, after all. Or is this a much less likely scenario?
A few thoughts...
Given this, things we could do for now (patch):
Stretch goals - (3.8?):
|
@windmgc - I see you pushed some changes, but there's still 2 channels being created; did you agree with this:
If not, let me know what your thoughts are. |
@gszr Yes! I agree with the patch plan, will update the PR accordingly |
…avoid useless invalidation
2a4bfd6
to
58c1473
Compare
5eb7e8d
to
fa8f18d
Compare
changelog/unreleased/kong/cluster_events_invalidation_channel_deprecation.yml
Outdated
Show resolved
Hide resolved
@windmgc does this need a cherry-pick to kong-ee? |
Successfully created cherry-pick PR for |
@flrgh Thank you! |
Summary
Currently, the kong_db_cache and kong_core_db_cache use the same invalidations channel named "invalidations" in the cluster event hook. In a traditional cluster(in which multiple Kong nodes use the same database and communicate with each other through cluster events), whenever an invalidation happens on a node A, any other single node X in the cluster will call
invalidate_local
on both kong_db_cache and kong_core_db_cache although the entity usually exists in only one cache, thus generates useless worker events. Not sure if this is an intentional design.The PR tries to separate every kong.cache instance to use its own invalidations channel to avoid generating useless "invalidations" worker events in a traditional cluster.
Checklist
changelog/unreleased/kong
orskip-changelog
label added on PR if changelog is unnecessary. README.mdIssue reference
Tries to alleviate FTI-5559