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

perf(plugins): use batch queue in datadog & statsd plugin to reduce timer usage #9521

Merged
merged 13 commits into from
Nov 22, 2022

Conversation

windmgc
Copy link
Member

@windmgc windmgc commented Oct 10, 2022

Summary

This PR adds batch queue into the Datadog plugin and the StatsD plugin, to reduce the number of timers used by these two plugins.

Whenever a request is processed, during the log phase a new instantly running timer will be created. This may cause a shortage of timers under heavy traffic and lead to unpredictable consequences (internal timers are killed randomly and some of them cannot recover automatically).

Adding batch queues in these two logging plugins will mitigate this problem to some extent.

Full changelog

  • Add batch queue into the Datadog and StatsD plugin to reduce timer usage

Issue reference

Mitigate FTI-4367 FTI-4269

@windmgc
Copy link
Member Author

windmgc commented Oct 10, 2022

It seems hard to add test cases to this fix, but exists test cases should get passed without any problem.

@hbagdi
Copy link
Member

hbagdi commented Oct 10, 2022

The right commit type for this change is 'perf' as per our contribution policy: https://github.com/Kong/kong/blob/master/CONTRIBUTING.md#type.
Please update your PR and commit accordingly.

@windmgc windmgc force-pushed the batch-queue-in-plugins branch from cb53478 to 4b8bc6b Compare October 11, 2022 01:40
@windmgc windmgc changed the title fix(plugins): use batch queue in datadog & statsd plugin to reduce timer usage perf(plugins): use batch queue in datadog & statsd plugin to reduce timer usage Oct 11, 2022
@windmgc
Copy link
Member Author

windmgc commented Oct 11, 2022

PR type changed to perf

kong/plugins/datadog/handler.lua Show resolved Hide resolved
kong/plugins/datadog/handler.lua Outdated Show resolved Hide resolved
kong/plugins/datadog/handler.lua Outdated Show resolved Hide resolved
@windmgc windmgc force-pushed the batch-queue-in-plugins branch 2 times, most recently from 8b85c98 to 341189b Compare October 11, 2022 07:11
@windmgc
Copy link
Member Author

windmgc commented Oct 11, 2022

@chronolaw please review again, thanks!

Also @bungle could you please take a look at this PR?

@dndx dndx requested a review from bungle October 17, 2022 02:42
@@ -79,6 +79,9 @@ return {
{ service_name_tag = { type = "string", default = "name" }, },
{ status_tag = { type = "string", default = "status" }, },
{ consumer_tag = { type = "string", default = "consumer" }, },
{ retry_count = { type = "integer", default = 10 }, },
Copy link
Contributor

Choose a reason for hiding this comment

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

I was about to ask where the default values come from, but I found them here:

{ retry_count = { type = "integer", default = 10 }, },
{ queue_size = { type = "integer", default = 1 }, },
{ flush_timeout = { type = "number", default = 2 }, },

: )

@dndx
Copy link
Member

dndx commented Oct 27, 2022

Ping @bungle for a review as well.

@dndx dndx force-pushed the batch-queue-in-plugins branch from 6b2e00d to df2c12c Compare October 27, 2022 17:30
@windmgc
Copy link
Member Author

windmgc commented Oct 28, 2022

Hi, @bungle do you need the performance test job running? It seems that it requires some cloud provider credentials to be properly configured, and in my fork repo, these configs do not exist. Maybe I need to push this branch to kong:kong and open a new PR so that we can get the job running

@dndx dndx force-pushed the batch-queue-in-plugins branch from f9ce1c4 to a1005ce Compare November 3, 2022 16:55
@@ -79,6 +79,9 @@ return {
{ service_name_tag = { type = "string", default = "name" }, },
{ status_tag = { type = "string", default = "status" }, },
{ consumer_tag = { type = "string", default = "consumer" }, },
{ retry_count = { type = "integer", default = 10 }, },
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to update kong/clustering/compat/removed_fields.lua.

Copy link
Member Author

Choose a reason for hiding this comment

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

removed_fields added.

Copy link
Contributor

@ADD-SP ADD-SP left a comment

Choose a reason for hiding this comment

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

If a field is not required, it can be set to ngx.null or cjson.null by set it to null in Admin API.

end

local opts = {
retry_count = conf.retry_count or 10,
Copy link
Contributor

Choose a reason for hiding this comment

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

retry_count maybe ngx.null, because this field is not required, as well as queue_size, flush_timeout.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for reminding this! I tested it and it is true that a field that is not mandatory can be set to null without any error.
So I made these fields required = true now, although I feel it is more like a nitpick because many of these fields in the OSS plugin do not have this limitation...

@ADD-SP ADD-SP added the pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. label Nov 15, 2022
@windmgc windmgc force-pushed the batch-queue-in-plugins branch from a1005ce to 56371b1 Compare November 15, 2022 08:16
Copy link
Contributor

@ADD-SP ADD-SP left a comment

Choose a reason for hiding this comment

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

LGTM

@hanshuebner
Copy link
Contributor

@windmgc can you rebase so that we can merge this, please?

@windmgc windmgc force-pushed the batch-queue-in-plugins branch from aee6967 to ff725ab Compare November 22, 2022 14:29
@windmgc
Copy link
Member Author

windmgc commented Nov 22, 2022

@windmgc can you rebase so that we can merge this, please?

Rebase done.

@gszr gszr merged commit e2df4e6 into Kong:master Nov 22, 2022
@gszr
Copy link
Member

gszr commented Nov 22, 2022

@windmgc please add a changelog entry for this. Nice work!

windmgc added a commit to windmgc/kong that referenced this pull request Nov 22, 2022
@windmgc
Copy link
Member Author

windmgc commented Nov 22, 2022

The missing changelog is added in #9804

fffonion pushed a commit that referenced this pull request Nov 23, 2022
outsinre added a commit that referenced this pull request Jun 26, 2024
When a tag is created, this workflow would automatically
create a PR on 'kong/kong-pongo' to add that version.
bungle pushed a commit that referenced this pull request Jun 26, 2024
When a tag is created, this workflow would automatically
create a PR on 'kong/kong-pongo' to add that version.
github-actions bot pushed a commit that referenced this pull request Jun 27, 2024
When a tag is created, this workflow would automatically
create a PR on 'kong/kong-pongo' to add that version.

(cherry picked from commit b5baf94)
hanshuebner pushed a commit that referenced this pull request Jun 27, 2024
When a tag is created, this workflow would automatically
create a PR on 'kong/kong-pongo' to add that version.

(cherry picked from commit b5baf94)
oowl pushed a commit that referenced this pull request Jul 15, 2024
When a tag is created, this workflow would automatically
create a PR on 'kong/kong-pongo' to add that version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core/clustering plugins/datadog plugins/statsd pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants