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

ConcurrentHashMapV8's simple 'spread' function causes eviction performance issues for certain key types. #693

Closed
chrisdennis opened this issue Dec 3, 2015 · 0 comments
Assignees
Milestone

Comments

@chrisdennis
Copy link
Member

ConcurrentHashMapV8 hash spreading function is very simple:

static final int spread(int h) {
    return (h ^ (h >>> 16)) & HASH_BITS;
}

For Long and Integer keys (and anything similar) this means low values map 1:1 to hashcodes. This means a table of integer keys {1..8192} will end up occupying the low half of a 16384 slot table, while leaving the high half empty. This interacts badly with our sampling logic used in eviction since it means samples drawn from the later half of the map have to run through the a large number of entries before being able to return a sample. We should fix this by using a spreading function that better distributes the keys through the map.

Graph below shows time taken to select 8 random entries from maps of various size, and shows the issues at large map sizes for the current method (black) and the improvements after adopting the original JDK6 spreader (red).

randomsamplechm

@chrisdennis chrisdennis added this to the Milestone 5 milestone Dec 3, 2015
@chrisdennis chrisdennis self-assigned this Dec 3, 2015
chrisdennis added a commit to chrisdennis/ehcache3 that referenced this issue Dec 7, 2015
…hrough the map. This incurs a slight performance penalty on single-key operations, but improves random sample selection perf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant