Search code examples
hazelcasthazelcast-imapdata-partitioning

Hazelcast : Difference in data distribution across partition in IMap and ISemaphore


My doubt is from link https://hazelcast.org/mastering-hazelcast/#controlled-partitioning

It says:

Hazelcast has two types of distributed objects.

One type is the truly partitioned data structure, like the IMap, where each partition will store a section of the Map.

The other type is a non-partitioned data structure, like the IAtomicLong or the ISemaphore, where only a single partition is responsible for storing the main instance.

Let's say, I have put 500 records in IMap, what I understand is, each record may go in different partition. Now I have put 500 records in ISemaphore, then from above quoted paragraph from the link does it mean, that all the 500 records will go in single partition? Please help me to understand IAtomicLong or the ISemaphore, where only a single partition is responsible for storing the main instance.

Also would like to understand, how Semaphore and IMap differ when it comes to data distribution across parttion in hazelcast?


Solution

  • With an IMap, it makes sense to partition the data structure because it will usually hold lots of items (500 in your example) and concurrent access to items anywhere in the map is frequently needed.

    But data structures like ISemaphore and IAtomicLong are simple objects, not collections of objects - you can't add 500 records to an ISemaphore. The semaphore state consists of just a few fields (count, current owner, name, maybe a few others) and it doesn't make sense to break those apart and store them in separate partitions.

    A queue is more interesting because it does hold multiple items, but is not a partitioned data structure. You could add 500 items to a queue, but access is always going to be to the front of the queue (for reading) or back of the queue (for writing), so distributing the data structure across partitions doesn't really offer improved concurrency as it does with Map, Set, List, and similar collections that are accessed randomly.