Best setup for huge amount of transactions

#1

Hi, let's say I have:

one Manager object
and
100-10,000 Connection objects
with the Connection objects receiving a message every ten seconds. Meaning in total receiving between 10 and 1,000 messages per second. On each message there is some data added to the database. All messages from the same connection are writing to the same entity (Device).

How can I improve the performance?

Currently I have a single EntityManager open on the Manager object level. However, I wonder if I should have an EntityManager per Connection (but this would be up to 10,000 open EntityManagers). Then I use transactions for each edit of the entity:

try {
    DefaultConnectionManager.this.entityManager.getTransaction().begin();
    this.device = DefaultConnectionManager.this.entityManager.merge(this.device);
    this.device.getStates().add(state);
    this.device.setUpdate(this.hasUpdate(state));
    this.device.setUpgrade(this.hasUpgrade(state));
    DefaultConnectionManager.this.entityManager.getTransaction().commit();
} catch(OperationFailedException | InvalidEntityException e) {
    DefaultConnectionManager.this.entityManager.getTransaction().rollback();
}

I already get some errors from time to time (and here we are at around 100 Connection objects):

com.objectdb.o._PersistenceException: Attempt to begin a new transaction when a transaction is active [PMImpl]
at com.objectdb.o._PersistenceException.a(_PersistenceException.java:47)
at com.objectdb.o.JPE.d(JPE.java:147)
at com.objectdb.o.ERR.h(ERR.java:56)

Thanks,

Martin

#2

Each transaction takes around 30-100ms at the moment (I changed to refresh instead of merge because the entity manager remains open all the time).

#3

As always, the only way to know which way is faster is to try both in a benchmark.

If you can live with one EntityManager and transaction isolation is not an issue, you may want to try merging transactions, i.e. by calling begin and commit less frequently with updates from several different connections. This may boost performance. Note, however, that an EntityManager is mainly for single thread execution, so maybe do some work in multiple threads but queue the update requests to a single thread that will operate the EntityManager.

ObjectDB Support

Reply