8000 Changed locking strategy by siennathesane · Pull Request #37 · allegro/bigcache · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

8000
Merged
merged 3 commits into from
Apr 18, 2017
Merged

Changed locking strategy #37

merged 3 commits into from
Apr 18, 2017

Conversation

siennathesane
Copy link
Collaborator
@siennathesane siennathesane commented Apr 15, 2017

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:

name                   old time/op    new time/op    delta
BigCacheSet-8             569ns ± 6%     511ns ± 5%  -10.24%  (p=0.000 n=860+949)
BigCacheGet-8             525ns ± 3%     454ns ± 5%  -13.45%  (p=0.000 n=922+930)
BigCacheSetParallel-8     178ns ± 2%     164ns ±20%   -7.61%  (p=0.000 n=961+804)

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

Signed-off-by: Mike Lloyd <mlloyd@pivotal.io>
@coveralls
8000
Copy link
coveralls commented Apr 15, 2017

Coverage Status

Coverage decreased (-0.7%) to 98.438% when pulling 3936435 on mxplusb:perf-changes into dedad99 on allegro:master.

Signed-off-by: Mike Lloyd <kevin.michael.lloyd@gmail.com>
@coveralls
Copy link
coveralls commented Apr 15, 2017

Coverage Status

Coverage decreased (-0.7%) to 98.438% when pulling d40b172 on mxplusb:perf-changes into dedad99 on allegro:master.

@janisz
Copy link
Collaborator
janisz commented Apr 15, 2017

Tests hangs on Travis. Any idea why?

@siennathesane
Copy link
Collaborator Author
siennathesane commented Apr 15, 2017 via email

@janisz
Copy link
Collaborator
janisz commented Apr 15, 2017

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()
Copy link
Collaborator

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.

Copy link
Collaborator Author

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>
@coveralls
Copy link
coveralls commented Apr 16, 2017

Coverage Status

Coverage decreased (-0.2%) to 98.874% when pulling 6eb72a5 on mxplusb:perf-changes into dedad99 on allegro:master.

@wendigo
Copy link
Contributor
wendigo commented Apr 18, 2017

@janisz we've been talking about it a couple of weeks ago :)

@janisz janisz merged commit b6bd76a into allegro:master Apr 18, 2017
@janisz
Copy link
Collaborator
janisz commented Apr 18, 2017

@mxplusb Thanks!

@siennathesane
Copy link
Collaborator Author

Awesome, glad to help!

@Leviathan1995 Leviathan1995 mentioned this pull request Sep 17, 2017
@siennathesane siennathesane deleted the perf-changes branch October 11, 2017 04:58
flisky pushed a commit to flisky/bigcache that referenced this pull request May 7, 2020
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
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.

4 participants
0