Is there a parallel HashMap processing for Java? Is it possible?

Search for the magic class ParallelHashMap

In short, can you use multiple threads to speed up your HashMap search? Are there any implementations that do this already?

In my project, we need to save a large map of objects in memory. We never modify a map after its creation, therefore the map is strictly read-only. However, reading and searching performance on this map is absolutely critical to the success of the application. The systems in which the application will be installed typically have many hardware threads. However, our search engines use only one thread to retrieve values ​​from the HashMap. Can a split and conquer approach use multiple threads (possibly in a pool) to help improve search speed?

Most of my Google searches turned out to be fruitless - returning a lot of results about concurrency problems, not solutions. Any advice would be appreciated, but if you know about getting out of the box, you're amazing.

It should also be noted that all keys and values ​​are immutable. The hash values ​​are pre-computed and stored in the objects themselves when the instance is created.

As for implementation details, the Map contains about 35,000 elements. Both keys and values ​​are objects. Keys are a custom search key, and values ​​are strings. Currently, we can handle about 5,000 search queries per second (this includes a bit of overhead by some other logic, but the main bottleneck is the implementation of the map itself). However, in order to keep up with our future performance needs, I want this number to be around 10,000 searches per second. By most normal standards, our current implementation is fast - we just need it faster.

35 000 , , - .

+3
7

, - , - - .

, , - ?

, - - , . , -, , ?

- , , - , -, . Java, C/++ gperf

+7

, . . loadFactor HashMap - .

, - , get() , equals(). equals() ?

+3

: , . , .

, . , ?

++ - Google sparsehash.

Java, , Trove Colt.

, -: n - n (/ n ), . , , , , .

, , .

+2

HashMap ( ):

, . , , .

HashMap , . . ( , , , )

, Collections.unmodifiableMap , .

+1

:

5

, - 5 . HashMap int. HashMap:

(get and put), , - .

, , -. hashCode() , ( prime number, , XOR , ):

return this.a.hashCode() ^ (31 * (this.b.hashCode() ^ (31 * this.c.hashCode())));

bad hashCode:

return (this.a + this.b + this.c);
+1

HashMaps . , , , .

0

I think you need evidence that the get () method on the HashMap is where you linger. I think this is unlikely. Place a loop around the get () method so that it repeats 1000 times and your application probably won't slow things down at all. Then you will find out that the delay is in another place.

0
source

Source: https://habr.com/ru/post/1716949/


All Articles