Skip to content
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

feat(queue): added a new configuration concurrency_limit(integer, default to 1) for Queue to specify the number of delivery timers #13332

Merged
merged 25 commits into from
Aug 19, 2024

Conversation

vm-001
Copy link
Contributor

@vm-001 vm-001 commented Jul 4, 2024

Summary

Added a new configuration concurrency_limit(integer, default to 1) for Queue to specify the number of delivery timers.

Note that setting concurrency_limit to -1 means no limit, and each HTTP Log will create a individual timer to send.

Checklist

Issue reference

FTI-6022

@vm-001 vm-001 requested a review from hanshuebner July 4, 2024 05:39
@github-actions github-actions bot added plugins/http-log cherry-pick kong-ee schedule this PR for cherry-picking to kong/kong-ee labels Jul 4, 2024
@vm-001 vm-001 marked this pull request as draft July 4, 2024 05:40
kong/plugins/http-log/handler.lua Outdated Show resolved Hide resolved
kong/plugins/http-log/handler.lua Outdated Show resolved Hide resolved
kong/plugins/http-log/handler.lua Outdated Show resolved Hide resolved
kong/plugins/http-log/handler.lua Outdated Show resolved Hide resolved
changelog/unreleased/kong/http-log-Improvement.yml Outdated Show resolved Hide resolved
@hanshuebner
Copy link
Contributor

I think the new behavior should be enabled by an explicit configuration parameter (no_queue) rather than implicit by a certain queue length. This would make it easier to understand.

@vm-001 vm-001 marked this pull request as ready for review July 4, 2024 07:30
@vm-001 vm-001 requested a review from hanshuebner July 4, 2024 08:18
spec/01-unit/27-queue_spec.lua Outdated Show resolved Hide resolved
kong/plugins/http-log/handler.lua Outdated Show resolved Hide resolved
spec/03-plugins/03-http-log/01-log_spec.lua Outdated Show resolved Hide resolved
spec/03-plugins/03-http-log/01-log_spec.lua Outdated Show resolved Hide resolved
changelog/unreleased/kong/http-log-concurrent-optimize.yml Outdated Show resolved Hide resolved
kong/plugins/http-log/handler.lua Outdated Show resolved Hide resolved
local entry = cjson.encode(kong.log.serialize())

if queue_conf.max_batch_size == 1 then
local ok ,err = timer_at(0, function()
Copy link
Contributor

@outsinre outsinre Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the TPS is very high, the number of timers would soar. Would that be a problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose all the timers would be managed by timer-ng since 3.0. In that case, there will be warning logs from the timer-ng.

@pull-request-size pull-request-size bot added size/L and removed size/M labels Jul 17, 2024
kong/plugins/http-log/handler.lua Outdated Show resolved Hide resolved
kong/plugins/http-log/handler.lua Outdated Show resolved Hide resolved
kong/plugins/http-log/handler.lua Outdated Show resolved Hide resolved
kong/plugins/http-log/handler.lua Outdated Show resolved Hide resolved
@vm-001 vm-001 force-pushed the fix/http-log-parallel branch 2 times, most recently from 39645d8 to 3acafc9 Compare August 9, 2024 07:43
@vm-001 vm-001 marked this pull request as ready for review August 9, 2024 09:34
@@ -0,0 +1,3 @@
message: "**HTTP-Log**: Added a new configuration `queue.concurrency`"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's also explain what this is for

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. It May require a second review.

kong/tools/queue_schema.lua Outdated Show resolved Hide resolved
kong/tools/queue_schema.lua Outdated Show resolved Hide resolved
kong/tools/queue_schema.lua Outdated Show resolved Hide resolved
kong/tools/queue.lua Outdated Show resolved Hide resolved
@@ -210,5 +211,17 @@ return {
acl = {
"always_use_authenticated_groups",
},
http_log = {
"queue.concurrency",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a feature. Can we catch up 3.8.0.0? If not, we should put it under 3.9.0.0.

kong/tools/queue.lua Show resolved Hide resolved
kong/tools/queue.lua Show resolved Hide resolved

if (now() - start_time) > self.max_retry_time then
self:log_err(
"could not send entries due to max_retry_time exceeded. %d queue entries were lost",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"could not send entries due to max_retry_time exceeded. %d queue entries were lost",
"failed to send %d entries due to maximum timeout reached.",

kong/tools/queue.lua Show resolved Hide resolved
@vm-001 vm-001 changed the title fix(plugins/http-log): improve concurrency when max_batch_size is set to 1 feat(queue): added a new configuration concurrency_limit(integer, default to 1) for Queue to specify the number of delivery timers Aug 12, 2024
kong/tools/queue.lua Show resolved Hide resolved
@@ -506,6 +514,21 @@ local function enqueue(self, entry)
return nil, "entry must be a non-nil Lua value"
end

if self.concurrency_limit == -1 then -- unlimited concurrency
-- do not enqueue when concurrency_limit is unlimited
local ok, err = timer_at(0, function(premature)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found some places use kong.timer, so we do not need to declare ngx.timer.at spearately.

kong/tools/queue_schema.lua Show resolved Hide resolved
@vm-001 vm-001 requested a review from samugi August 12, 2024 07:49
@samugi
Copy link
Member

samugi commented Aug 12, 2024

it would be good to perf-test the final solution and compare results with the initial "fix" to ensure we get similar performance

Copy link
Contributor

@outsinre outsinre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except a minor changelog syntax.

changelog/unreleased/kong/feat-queue-concurrency-limit.yml Outdated Show resolved Hide resolved
Co-authored-by: Zachary Hu <6426329+outsinre@users.noreply.github.com>
@team-eng-enablement team-eng-enablement added author/community PRs from the open-source community (not Kong Inc) and removed author/community PRs from the open-source community (not Kong Inc) labels Aug 13, 2024
@vm-001 vm-001 added this to the 3.8.0 milestone Aug 16, 2024
@windmgc windmgc merged commit c5566bb into master Aug 19, 2024
33 of 35 checks passed
@windmgc windmgc deleted the fix/http-log-parallel branch August 19, 2024 03:28
@team-gateway-bot
Copy link
Collaborator

Cherry-pick failed for master, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally.

git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-13332-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-13332-to-master-to-upstream
git checkout -b cherry-pick-13332-to-master-to-upstream
ancref=$(git merge-base b6315737104d65c670f9c48001b2ee4b7d470ee4 ff1a7e17e1cfe222e45fcf58b099f3305893f3ae)
git cherry-pick -x $ancref..ff1a7e17e1cfe222e45fcf58b099f3305893f3ae

@github-actions github-actions bot added the incomplete-cherry-pick A cherry-pick was incomplete and needs manual intervention label Aug 19, 2024
@locao
Copy link
Contributor

locao commented Aug 27, 2024

Cherry-picked in Kong/kong-ee#9996

@locao locao removed the incomplete-cherry-pick A cherry-pick was incomplete and needs manual intervention label Aug 27, 2024
curiositycasualty pushed a commit that referenced this pull request Oct 15, 2024
…efault to 1) for Queue to specify the number of delivery timers (#13332)

Added a new configuration concurrency_limit(integer, default to 1) for Queue to specify the number of delivery timers.

Note that setting concurrency_limit to -1 means no limit, and each HTTP Log will create a individual timer to send.

FTI-6022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants