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

fix bug in meter traversal logic #11

Merged
merged 1 commit into from
Nov 8, 2019
Merged

fix bug in meter traversal logic #11

merged 1 commit into from
Nov 8, 2019

Conversation

vyzo
Copy link
Contributor

@vyzo vyzo commented Nov 8, 2019

@vyzo vyzo requested a review from Stebalien November 8, 2019 13:13
if m != nil {
sw.meters[newLen] = m
newLen++
}
Copy link
Member

Choose a reason for hiding this comment

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

There's actually a trick to this:

newMeters := sw.meters[:0]
for _, m := range sw.meters {
    if m != nil {
        newMeters = append(newMeters, m)
    }
}
sw.meters = newMeters

Copy link
Contributor Author

Choose a reason for hiding this comment

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

neat, but it probably generates the same code underneath :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you want me to apply it? I am neutral either way and I usually prefer explicitness.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually, the trick might generate slower code because it has to do bounds checking.
Maybe the compiler is smart enough to elide it though, I wouldn't bet against it.

Copy link
Member

Choose a reason for hiding this comment

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

The trick will do less bounds checking, IIRC. But I'm fine with this as it is.

@Stebalien Stebalien merged commit c3ecce9 into master Nov 8, 2019
@Stebalien Stebalien deleted the fix/issue-65 branch November 8, 2019 17:22
@Stebalien
Copy link
Member

@vyzo could you write a test for this? We can probably do this by:

  1. Starting 3 meters in sequence.
  2. Making the first and last go idle.
  3. Re-activate the last meter.

The total for that last meter should see a massive spike.

@vyzo
Copy link
Contributor Author

vyzo commented Nov 8, 2019

well, not with the fix! But we can haz a test.

@vyzo
Copy link
Contributor Author

vyzo commented Nov 8, 2019

This is harder to trigger than it looks; we need to be actively putting stuff while the sweeper is running so that we avoid the short-circuit from the optimistic load to generate a race condition.

@vyzo
Copy link
Contributor Author

vyzo commented Nov 8, 2019

I managed to trigger it -- I made a small test that fails consistently before this patch, and passes after the patch.

@vyzo vyzo mentioned this pull request Nov 8, 2019
@albrow
Copy link

albrow commented Nov 12, 2019

@vyzo @Stebalien this does appear to fix the issue on our end. At the very least the issue is a lot less frequent. We're going to deploy this to all of our nodes and then keep an eye on things for a few days to know for sure.

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

Successfully merging this pull request may close these issues.

3 participants