Search code examples
javahazelcastin-memory-databasesmartfoxserver

Implement Hazelcast with SmartFoxServer


I'm a game server developer. I'm using hazelcast for my game server (SmartfoxServer 2x) to avoid request db directly. But I wonder how to use hazelcast to get the best performance:

  1. Always create new hazelcast client instance when access cache and then shutdown it. Or
  2. Create a hazelcast client instance pool, and reuse. Never shutdown until application end. Or
  3. Create only one hazelcast client instance, never shutdown until application end. Or
  4. Make my realtime server as a hazelcast member.

What's the right way? My system serve for about 5000 CCU.

My game is a kind of card game - turn based. Each game occurs in about 2 minutes, with maximum 4 players. When It end, I have to log every transactions (money change), and new money value for user. With 5000 ccu, in worst case, at the same time there're (5000/4) * (4 + 4) = 10000 entries have to be logged. It cannot be done with mysql queries directly (slow), but with hazelcast, it's possible, right? But I'm a newbie in Hazelcast technique, so I don't know what is the right way to solve my issue.

Thank in advance,


Solution

  • The best answer is 3 or 4. While I was working at the gaming industry I used Hazelcast not as a cache but to distribute / cluster the gameservers itself. Therefor my gameservers itself were part of the cluster. If you want to have a dedicated db-cache cluster just use one client, start it together with the gameserver and keep it alive while the gameserver itself is alive. It is pooled internally and the client is smart enough to route requests to the correct cluster node in almost all cases. If you want to use it for more than just caching I would go for making the gameserver a node of the cluster itself. Remember that every node holds a part of the data, that might not be what you want for a gameserver to act as a db-cache.