-
Notifications
You must be signed in to change notification settings - Fork 2
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
Reduce mist client timeout for catabalancer stats sending #1400
Conversation
I saw occasional slowness from the mist GetState function. The mist client has a 1 minute timeout and we need a much shorter timeout here as the loop runs every 5 seconds
The diff is best viewed with whitespace hidden |
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.
Added a suggestion. Either way, LGTM
sysusage, err := GetSystemUsage() | ||
if err != nil { | ||
log.LogNoRequestID("catabalancer failed to get sys usage", "err", err) | ||
done := make(chan bool) |
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 think the more "golang way" of doing the same would be passing context with timeout into sendMetrics()
. So you could have something like this:
ctx, cancel := context.WithTimeout(context.Background(), timeout)
sendMetrics(ctx, nodeName, latitude, longitude, mist, nodeStatsDB)
And then inside sendMetrics()
to have
GetSystemUsage(ctx)
And so on. The good thing about this approach would be that in case of the timeout you cancel all system and network calls.
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.
Yeah.. I see what you mean, unfortunately I couldn't find any funcs within GetSystemUsage which take a context so it really is just the mist client we need to have the timeout for, and so you've made me realise the proper solution is really to reduce the timeout for the mist client
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.
@leszko I've pretty much re-done this PR, please could you take a look? thanks
91129cb
to
7c9b496
Compare
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.
Added one inline comment. Other than that, LGTM
main.go
Outdated
@@ -267,6 +267,7 @@ func main() { | |||
|
|||
if catabalancerEnabled && nodeStatsDB != nil { | |||
if cli.Tags["node"] == "media" { // don't announce load balancing availability for testing nodes | |||
mist := clients.NewMistAPIClient(cli.MistUser, cli.MistPassword, cli.MistHost, cli.MistPort, catabalancer.StatsUpdateInterval-time.Second) |
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.
Could you add a comment with the reasoning why it's catabalancer.StatsUpdateInterval-time.Second
? It's not clear to me.
I saw occasional slowness from the mist GetState function. The mist client has a 1 minute timeout and we need a much shorter timeout here as the loop runs every 5 seconds