Free In-Memory Data Grid

Here’s the architecture of the OCI Arcade extended with Coherence-CE

I was talking to Tim Middleton who works in the Coherence Development team the other day about different scenarios that we can work on some areas that demonstrate the scale out – two scenarios were obvious (to me) – Apache Spark was one and the other was Coherence – an In-Memory Data Grid.

And with that I built out the OCI Arcade to bring Coherence-CE (Community Edition) into the mix. There’s some lots of cool stuff that you can do with Coherence-CE and the bulk of the content is (here).

To get access to the OCI Arcade with Coherence – you can find these on a git branch in the repositories.

The simple use-case that we used Coherence-CE for was a simple identity key for the instance id (ie each game plays has a unique identifier). The nice thing was that it was all in Javascript. This following fragment was the only thing that I needed to do to integrate Coherence-CE into the app itself.

const opts = new Options()
opts.address = 'oci-cache:1408'

app.get('/id', (req, res) => {
  var game_id = req.query.game_id;
  var session = new Session(opts)
  var map = session.getMap('oci-id')
  setImmediate(async () => {
    console.log('Map size is ' + (await map.size))
    if ((await map.has(game_id)) == false) {
      await map.set(game_id, { id : 1 })
      res.send('{ "id" : 1 }');
    } else {
      res.send('{ "id" : '+(await map.invoke(game_id,Processors.increment('id',1)))+' }')
    }
    await session.close()
  })
});

From the Coherence-CE cluster perspective – there’s docker images from docker hub already (here) that I could use for it. So replacing what I did previously with Kafka in the deployment architecture and putting Coherence-CE in its place was simple. (NB: There were some changes in terms of stopping events being fired to Kafka and also creating the instance id from this method instead of a Date.now() method. Simple things).

There’s plenty of different directions that we can go from here – session-based cache scenarios, high-availability scenarios, in-memory data processing scenarios. There are plenty to extend and learn from.

If you want to try this out yourselves, you can get an Always Free Tier environment – head to the following link and sign-up. https://www.oracle.com/au/cloud/free/.

To get the whole thing up and running, then head to this previous blog to see how to get the OCI Arcade up and running (and playing) – https://redthunder.blog/2021/02/12/automating-with-oci-oracle-resource-manager/. Remember – use the coherence-ce branch.

I acknowledge Mason Borda for their contribution in building this game.

Have fun learning, experimenting and if you want to contribute to any of these things – reach out. #CommunityMatters #ItTakesAVillage

Advertisement
%d bloggers like this: