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

Batch metrics and flush periodically #2957

Merged
merged 1 commit into from
Aug 18, 2018
Merged

Batch metrics and flush periodically #2957

merged 1 commit into from
Aug 18, 2018

Conversation

ElvinEfendi
Copy link
Member

@ElvinEfendi ElvinEfendi commented Aug 18, 2018

What this PR does / why we need it:
Currently Lua code sends metrics to the controller for every request right after Nginx finishes responding. This means the load on controller increases linearly with the number of requests. That results in high CPU usage and dropped metrics ("Resource unavailable - when the controller can not process the metrics)".
This PR changes the logic in Lua side to batch the metrics and send the batches periodically to the controller. I've configured the period to 1s for now. Since we are batching the metrics in Nginx worker's memory to avoid potential unbounded memory increase I've also added limit on the number of metrics that can be batched during that 1s. That number is 10000 right now - which is a really high number. With this change Nginx would be dropping metrics only if an Nginx worker is handling more than 10000 RPS.

I've tested this change locally under heavy load and did not see any example of metric being dropped or "Resource unavailable" error. Note however this change means metrics will be delayed for a second.

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #

Special notes for your reviewer:

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 18, 2018
@ElvinEfendi ElvinEfendi changed the title [WIP] Batch metrics Batch metrics and flush periodically Aug 18, 2018
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 18, 2018
@ElvinEfendi
Copy link
Member Author

/assign @aledbf
/assign @antoineco

@codecov-io
Copy link

codecov-io commented Aug 18, 2018

Codecov Report

Merging #2957 into master will increase coverage by 0.01%.
The diff coverage is 68.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2957      +/-   ##
==========================================
+ Coverage   47.55%   47.57%   +0.01%     
==========================================
  Files          77       77              
  Lines        5633     5633              
==========================================
+ Hits         2679     2680       +1     
+ Misses       2602     2600       -2     
- Partials      352      353       +1
Impacted Files Coverage Δ
internal/ingress/metric/collectors/socket.go 79.27% <68.33%> (ø) ⬆️
internal/watch/file_watcher.go 84.61% <0%> (+3.84%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b78bb25...2207d76. Read the comment docs.

@aledbf
Copy link
Member

aledbf commented Aug 18, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 18, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aledbf, ElvinEfendi

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@aledbf
Copy link
Member

aledbf commented Aug 18, 2018

@ElvinEfendi this looks great. Thank you for working on this!

@k8s-ci-robot k8s-ci-robot merged commit a982713 into kubernetes:master Aug 18, 2018
@ElvinEfendi ElvinEfendi deleted the batch-metrics branch August 18, 2018 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants