Vik K
Vik K

Reputation: 33

Optimizing events processing

I'm using Oracle' Coherence cache in my java server component. I'm subscribing and listening to cache change events using following event handlers:

public void entryUpdated(MapEvent mapEvent) 
        { 
         processUpdateEvent(mapEvent);
        }

public void entryDeleted(MapEvent mapEvent) 
        {
        //processDeleteEvent(mapEvent);
        } 
    public void entryInserted(MapEvent mapEvent) 
        {
             processInsertEvent(mapEvent);
        } 

Sometimes, we get a stream of huge number of "update" events on the cache("delete" or "insert" events are very small in number)...and it seems that our current java code is not scalable enough to handle this scenario. So, as a result, it lags behind in events processing.

I'm trying to re-design and optimize this code.

One thing that came to my mind is using the following approach. But i think it does not make sense as it will launch new thread for every new event which will again slow down the overall performance on the server. Is there any other way I can optimize this code please?

Thread thread = new Thread(new Runnable() {
                    public void run() {
processUpdateEvent();
                       }
                    });
                thread.start();

Thanks.

Upvotes: 0

Views: 86

Answers (1)

Simone Casamassa
Simone Casamassa

Reputation: 344

A coherence listener works with a single thread so the only possible solution is to delegate the event process to another thread and leaving free as soon as possible the listener thread.

A possible solution to optimize your event-driven architecture ask you an architectural change: you could register interceptor on data storage nodes and write the event on a topic kafka. In this way every interceptor will work only a part of the events (only the events created in the same data storage node) and your pool of Kafka consumer could be configurated for high performance and high availability.

An other risk of coherence listener approch is that you can't obtain a clustered client and an high available client.

Upvotes: 0

Related Questions