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 for the slow updates of targets changes #4526
Conversation
/benchmark |
@krasi-georgiev: Welcome to Prometheus Benchmarking Tool. The two prometheus versions that will be compared are pr-4526 and master The logs can be viewed at the links provided in the GitHub check blocks at the end of this conversation After successfull deployment, the benchmarking metrics can be viewed at :
To stop the benchmark process comment /benchmark cancel . In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@grobie still polishing few details, but you can already test this version or wait few days to clear all small issues. The last major problem is with the http2 go client update in golang/net@1c05540 , as long at your k8s cluster doesn't use the default connection stream limit of 1000, you should be fine.
more details about the http2 client issue. |
the benchmark is looking good. When I scale up and down the targets the CPU and memory usage is higher, but this is to be expected as all processing is now done in parallel. |
Since the bug was slow targets updates this will be tested when we implement the e2e SD tests. |
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 also speeds up the prometheus's shutting down.
I don't see anything in this PR related to that. Am I missing something?
scrapeConfig, ok := m.scrapeConfigs[setName] | ||
if !ok { | ||
level.Error(m.logger).Log("msg", "error reloading target set", "err", fmt.Sprintf("invalid config id:%v", setName)) | ||
return |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
/benchmark cancel |
Hi @krasi-georgiev , I'm back at work and would like to canary all those SD changes. What's the state of this PR? Should this still be included? You said you wanted to rebase this before further checking. |
@beorn7 IIUC #4124 that you reported on targets not being updated should be fixed now on master by #4523 and #4556. This PR is more about optimizations that would speed up the recreation of the scrape loops. Also #3912 (which merges identical SD configurations into a single provider and thus avoids hammering the K8S API) has been merged. Finally Krasi has found a couple of issues with the K8S go client (#4518 and #4528) but not sure that they apply to your environment. In summary, you're more than welcome to test the current master on your clusters 😏 |
OK, I'll try current master first and leave this PR alone for now. |
15e9ec9
to
6b36538
Compare
I have rebased it. |
when reloading the targets and stopping old scrapes, Prometheus will shutdown only when the reloading is over and all old scrapes are stopped. processing these in parallel allows Prometheus to shutdown a lot quicker. |
review please 😝 |
LGTM but I think it would worth to have unit tests for this. |
@simonpasquier what unit tests did you have in mind? This PR fixes the time it takes to reload the scrape loops. |
I can run this on one of our servers at my next convenience. |
@beorn7 appreciated! |
I was thinking about something similar to #4582 although looking at the manager's code it would require some adjustments to be able to skip the effective launch of the scrapers. |
Running this now (with current state of master merged in). Disclaimer: I'm not using race detector (would not work on the heavily loaded test machine), but I recommend to do so before merging this. I guess this change should result in faster reloads of the config file. I sighup'd the test server and the 2.4.0 production server a few times and couldn't detect a significant improvement, mostly because reload times are vastly different from case to case, from 5s to 30s, more or less the same on both servers. Restart time is quite long on this server (around 12m (!)) and isn't significantly different with this PR merged in. (Perhaps the new WAL implementation is slower? I don't remember such long startup times from earlier 2.x versions. But perhaps our load has just increased so much in the meantime...) Altogether, the two servers seem to behave mostly the same. |
I tested this mainly with the k8s discovery. I think 100 jobs with 20-30 targets per jobs. Than randomly scaling up and down the number of targets between 1 and 20 . Before this pr it takes minutes to reflect the changes in the /targets web gui and it can never catch up in an environment of constantly changing targets. |
When I tested locally it also improved the shutdown time as now old scrape loops are stopped in parallel. |
@krasi-georgiev have you retried your tests with the latest master? I suspect that the various improvements to the SD manager may have change the situation. |
@krasi-georgiev I see. I guess our test server doesn't see quickly changing targets that often. I might be able to identify one of those, and then run the canary binary there. |
Looking around, with 2.4.0, all our practical uses of K8s SD seem to update fast enough so that any further improvements would not stick out of the noise. |
Maybe @brancz can also give it a try since it is very easy to replicate using his configs even using minikibe. @simonpasquier this change is in the scrape manager which is completely independent from the sd manger. |
Mostly #3912. It might be that optimizing the discovery part (basically much less requests to the K8S API) reduced the contention and made the problem less acute on the scrape side. |
aah yes that definitely helped, but processing the loops in parallel solves a completely different problem. |
After letting it run overnight, I can just say that it works at least as well as the 2.4.0 one. |
Scaling from 0 to 2000 targets back and forth, I definitely see an improvement when down-scaling. WDYT of adding a few tests? |
the only useful test that I can see is making sure the Scrape manager never blocks the Is this what you had in mind as well? |
Yes. Also making sure that data received on the channel triggers scrape updates and that everything is teared down properly on shutdown. I know that it wasn't tested before but it looks like a good opportunity to fix it. |
@simonpasquier yes good idea, I added some tests. Just not sure what you had in mind for:
|
9b0e803
to
fc7bf2b
Compare
scrape/manager.go
Outdated
} | ||
|
||
wg.Add(1) | ||
// Run the sync in paralel as these take a while and at high load can't catch up. |
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.
s/paralel/parallel/
👍 It would be even better to test the logic including
That calling |
Yeah I didn't want to take it that far as this would probably end being too high maintenance. |
The scrape manage receiver channel now just saves the target sets and another backgorund runner updates the scrape loops every 5 seconds. This is so that the scrape manager doesn't block the receiving channel when it does the long background reloading of the scrape loops. Active and dropped targets are now saved in each scrape pool instead of the scrape manager. This is mainly to avoid races when getting the targets via the web api. When reloading the scrape loops now happens in parallel to speed up the final disared state and this also speeds up the prometheus's shutting down. Also updated some funcs signatures in the web package for consistency. Signed-off-by: Krasi Georgiev <kgeorgie@redhat.com>
eb1ecf8
to
eda48a2
Compare
The scrape manage receiver channel now just saves the target sets
and another backgorund runner updates the scrape loops every 5 seconds.
This is so that the scrape manager doesn't block the receiving channel
when it does the long background reloading of the scrape loops.
Active and dropped targets are now saved in each scrape pool instead of
the scrape manager. This is mainly to avoid races when getting the
targets via the web api.
When reloading the scrape loops now happens in parallel to speed up the
final disared state and this also speeds up the prometheus's shutting
down.
Also updated some funcs signatures in the web package for consistency.
fixes: #4124
fixes: #4301
I will run a benchmark once the #4523 is merged and I rebase it to this PR as well.
Signed-off-by: Krasi Georgiev kgeorgie@redhat.com