0

I have a message driven bean running on Glassfish. It receives hundreds of messages per second. After receiving a message, it needs to read the values in the JDBC database and process.

However, the values in database will only be updated one time a day or less. So what the MDB will read is consistent most of the time. So, is it there a good way to cache the content into the memory in order to increase the performance?

Update: is it posible to configure a in-memory database JDBC Connection Pool in Glassfish for the MDB?

zhushp
  • 1
  • 2
  • 2
    do you know when the value is updated (is it at a fixed time?). does it matter if you don't use the updated data for some time? how long? what database are you using? what fraction of the database is used (all the database, or just a "random" fraction)? do many messages all want to read the same value from the database, or do they scatter evenly across the database? – andrew cooke May 31 '12 at 04:01
  • @andrewcooke Yes, the update is done at a fixed time, let's say 00:00, is it OK that it uses outdated data for some time after that period since the usage volume will be closed to 0 then. I am using Java DB and the some fixed tables in the database will be used. And all the msg will want to ready the same value from the database. Any suggestion how to implement this? Thanks. – zhushp May 31 '12 at 04:14
  • is it posible to configure a in-memory database in Glassfish for JavaDB? – zhushp May 31 '12 at 09:32

3 Answers3

1

You may get inspired by the identity map pattern and implement your own cache mechanism (with your own expiration policy), if you think that using a third party solution (like memcached) would be overkill.

Renato Gama
  • 16,431
  • 12
  • 58
  • 92
0

The most obvious answer is to define the table as a MEMORY table type. If the underlying hardware is not prone to crashing and the OS is stable and there's a UPS attached, you might want to think about this. It also depends on the consequences of losing a number of transactions since the last backup whenever this fails. But performance-wise, this is lightning fast. More information can be found here for MySQL. (YMMV)

I've implemented multiple tables that way, and it worked great for me.

0xCAFEBABE
  • 5,576
  • 5
  • 34
  • 59
0

You can use a simple SoftReference HashMap based cache. Here is the complete implementation example SoftReference Cache In addition you can clear the complete Map periodically to bring in fresh data.
Or in case you can use 3rd party library, you might use ReferenceMap provided as part of Apache Collections.

Sumit
  • 706
  • 1
  • 8
  • 16