user3590975
user3590975

Reputation: 21

Apache Ignite Cache set affinity to current machine

I have a cache of Bucket4J instances, used for the rate limiting of requests coming across a web socket. I would like to have access to the state of these buckets be shared across our cluster, but have each bucket be stored on the machine where it was created, so that there doesn't need to be a network request for every message coming through the socket.

I don't see any implementations of AffinityFunction or AffinityKeyMapper that would provide this capability.

Does anyone know a way to achieve this functionality?

Upvotes: 2

Views: 247

Answers (2)

Adam
Adam

Reputation: 2279

It seems like I am missing some details about your use case, but I will try and give more detail as to why a REPLICATED cache, or not using Ignite at all, makes sense.

Affinity functions look at the key of an object in order to calculate a partition. A partition is then mapped to a particular node in a cache. So in order to achieve what you want, you need to modify objects to include information about the node it was created on to be included in the key. Then when you put the object into the cache, you can have a custom affinity function parse out the information and return a partition on the current node.

I think this is a bad idea for a few reasons.

1) You are losing a lot of Ignite features (auto balancing and such) by dancing around the affinity balance using your own balancer.

2) You mention you don't want to go across network for every socket message. This means your data has to be local for each socket message. Why even use Ignite at all then? Sounds like a local cache is actually what you want.

3) If you only want the creation to be on the same node, I don't think that actually saves you much.

If you really want the data available on all nodes, I would use a REPLICATED cache as suggested by alamar. Otherwise, I wouldn't use Ignite at all and just have a local cache on each node.

Upvotes: 0

alamar
alamar

Reputation: 19343

I think you should just use a REPLICATED cache.

Upvotes: 1

Related Questions