-
Notifications
You must be signed in to change notification settings - Fork 605
Changed locking strategy #37
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
Conversation
Signed-off-by: Mike Lloyd <mlloyd@pivotal.io>
Signed-off-by: Mike Lloyd <kevin.michael.lloyd@gmail.com>
Tests hangs on Travis. Any idea why? |
No, it was hanging on my computer too. I didn't make any changes to the
tests, just the locking statements. Might be a deadlock, I can look into
it.
On Fri, Apr 14, 2017 at 10:55 PM janisz ***@***.***> wrote:
Tests hangs on Travis. Any idea why?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#37 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AHMEsRD7xsl07IqeKnCYo28KuquMrcksks5rwFvQgaJpZM4M-MRu>
.
--
Thanks!
Mike Lloyd
USMC
808-633-8998
|
In get method not all paths unlock mutex. Can you refactor code to have only one return statement followed by unlock? This will make it easier to see the flow, lock at the beginning and unlock just after return. |
@@ -82,6 +81,7 @@ func (c *BigCache) Get(key string) ([]byte, error) { | |||
if c.config.Verbose { | |||
log.Printf("Collision detected. Both %q and %q have the same hash %x", key, entryKey, hashedKey) | |||
} | |||
shard.lock.RUnlock() |
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.
Not all returns are followed by unlock.
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.
Fixed!
Signed-off-by: Mike Lloyd <kevin.michael.lloyd@gmail.com>
@janisz we've been talking about it a couple of weeks ago :) |
@mxplusb Thanks! |
Awesome, glad to help! |
There is a known issue in Go with deferred operations being much slower than explicit operations, both directly and indirectly impacting locking. Generally, on OS X and Windows, the change gives between 10-15% performance gain. Relates: golang/go#14939
There is a known issue in Go with deferred operations being much slower than explicit operations, both directly and indirectly impacting locking.
Here are the performance comparisons (from benchstat) over 1000 iterations:
I did this over 1000 iterations because benchmarking nanosecond operations is hard to get consistent, so that gives a good view of the larger performance gain.
Generally, on OS X and Windows, the change gives between 10-15% performance gain.
Signed-off-by: Mike Lloyd mlloyd@pivotal.io