-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
pool: add pool raciness tests, fix p.usedTotal house-keeping #1340
Conversation
I have noticed with these tests that the `p.usedTotal` value keeps jumping like this: 6 3 6 6 18446744073709551604 3 18446744073709551607 18446744073709551604 It could happen that the value of it would underflow as the tests show: ``` unexpected error: goroutine barbazbaz: pool exhausted ```
Tests work well on my laptop but fail on Circle CI. Need to investigate 😖 |
We still want to modify `p.usedTotal` if the slice's capacity is outside of any bucket.
I think this used to work because, previously return value was Since we did change to IMO atomic is more preferred way than mutex in this case as it's more efficient. So I would keep the old code, just update docs and modify tests. |
I agree that it would be more beneficial to us from performance's perspective to stay with the old code which uses |
👍 Basically |
Yes, is that's OK with you? |
yy SGTM 🥇 |
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.
Sad we are locking underlying sync.Pool as it is already go routine safe, but definitely we want to have solid limit on used - many races where possible here indeed.
Thanks! LGTM!
Why not? I can't see how that wouldn't work :D I mean a couple of gourotines would do |
Because we are putting that data into a separate variable and it can change from underneath us since there's no locking, right @povilasv? |
It won't necessarily converge into 0 since, for example, one goroutine will get that there's X bytes used and then set it to X-Y, but another one will already have X too in the temporary variable but it will set it to X-Z. So the first update is lost unless we will do this sequentially. Does that make sense? However, we could sprinkle more checks all over the code so that we wouldn't use a temporary variable but I am not sure that it would really be faster than holding a mutex. Sorry for being terse, writing on my phone. |
yeah it does. Then mutex makes sense. |
Sorry, wanted to add one last thing that came to my mind: I think the problem here is that what we need to do is to atomatically compare one number with another, and then make a decision based on that - should we allocate or not? And with |
👍 |
* master: Fix typos (thanos-io#1350) pool: add pool raciness tests, fix p.usedTotal house-keeping (thanos-io#1340) runutil: add Exhaust* fns, initial users (thanos-io#1302) Further docs rename to new org; Improved docker login. (thanos-io#1344) Moved CI to thanos-io org and docker image to quay.io/thanos/thanos (thanos-io#1342) thanos-io (thanos-io#1343) website: migrate to new Github Org (thanos-io#1341)
* master: Fix typos (thanos-io#1350) pool: add pool raciness tests, fix p.usedTotal house-keeping (thanos-io#1340) runutil: add Exhaust* fns, initial users (thanos-io#1302) Further docs rename to new org; Improved docker login. (thanos-io#1344) Moved CI to thanos-io org and docker image to quay.io/thanos/thanos (thanos-io#1342) thanos-io (thanos-io#1343) website: migrate to new Github Org (thanos-io#1341)
I have noticed with these tests that the
p.usedTotal
value keepsjumping like this:
It could happen that the value of it would underflow as the tests show:
This happens when a caller does like a
Get(3)
and then makes the slice larger by appending more items to it. Then, when returning a slice we subtract its capacity fromp.usedTotal
and that can underflow. Also, that can happen because there is no synchronization between different users.Furthermore, lets fix the house-keeping of the
p.usedTotal
completely by not subtracting thep.usedTotal
from itself wheneverPut
was called. I am not sure that it was ever working correctly.Also,
go test -race
reports without these changes:After these changes, the race detector doesn't complain anymore.