• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ConcurrentHashMap vs EHCache vs Coherence

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, sorry general question about caching here. My understanding is that they are all just name-value pairs. I know EHCache is a popular cache of choice, and so is Oracle Coherence, amongst others such as JBoss's Infinispan, Java Caching System, or Cache2K, etc.

What I don't understand is why would I use these alternatives than what's available from out of the JDK box such as the following.


My use case is to have a server-client system, with the following characteristics:
1) Server holds multiple tables of arbitrary number of rows and columns in memory. The tables can store data such as interger, double, and string in the the table cells.
2) Multiple clients can connect to the server and browse through the tables at any time after the connection, and the server needs to serve the requested tables to the clients.

Not sure if the NVP caches would actually work, or there are table based caches? Any general pointers is appreciated. Thanks.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Cheung wrote:Hi, sorry general question about caching here. My understanding is that they are all just name-value pairs. I know EHCache is a popular cache of choice, and so is Oracle Coherence, amongst others such as JBoss's Infinispan, Java Caching System, or Cache2K, etc.

What I don't understand is why would I use these alternatives than what's available from out of the JDK box such as the following.




Many of these caching systems have cool features. For example...

1. Many of them can be visible to multiple applications -- meaning that they can be shared.

2. Many of them can be backed by a database. This means that the application can be restarted and it will have the data from the previous runs.

3. Even without a persistence store, some can back each other up -- meaning that a group of applications share the same cache. They can see each other changes. And when an application restarts, it can get all the data (as long as it is not the only member left).

4. Some support partitioning the data. This means that lots of applications, on different hosts with only a small amount of memory, can have a huge cache that is larger than the amount of memory available.

Of course, if none of the features are needed, it may be an overkill to use them.

Henry
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Cheung wrote:
My use case is to have a server-client system, with the following characteristics:
1) Server holds multiple tables of arbitrary number of rows and columns in memory. The tables can store data such as interger, double, and string in the the table cells.
2) Multiple clients can connect to the server and browse through the tables at any time after the connection, and the server needs to serve the requested tables to the clients.



If you want to code the clients to request the data, and code the server to service the data, then a concurrent hashmap should be fine. However, if you just want to share the cache, and let the caching library deal with the requesting and servicing, then it may be easier to use a cache.

Keep in mind though, with many of these caching systems, the changes made by any client will also be reflected back on the server (and on other clients), so it may *not* be what you want.

Henry
 
Mike Cheung
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:
If you want to code the clients to request the data, and code the server to service the data, then a concurrent hashmap should be fine. However, if you just want to share the cache, and let the caching library deal with the requesting and servicing, then it may be easier to use a cache.

Keep in mind though, with many of these caching systems, the changes made by any client will also be reflected back on the server (and on other clients), so it may *not* be what you want.

Henry


Henry, thanks for the reply. I think there are merits with using a cache so in the future if there are any additional features to be added requiring these features, we don't have to re-code which can be painful. Do you know of any tutorials of how I can implement a table like representation via any one of the caching framworks? I browsed through EhCache's site but they only have one for acting as a 2nd level cache on top of Hibernate and the example doesn't show how the update, retrieval will be done in code but rather appears to be done via declarative method in the Hibernate configs. And my use case isn't going to be retrieving things from a dB.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Cheung wrote:What I don't understand is why would I use these alternatives than what's available from out of the JDK box such as the following...


Well, off the top of my head, the example you gave doesn't appear to have any way of limiting the cache size, which is normally advisable in high-volume situations; but just FYI, a very simple size-limited LRU cache can be built on top of a LinkedHashMap.

Sounds like you're probably past the "roll your own" stage though...

Winston
 
Mike Cheung
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:Well, off the top of my head, the example you gave doesn't appear to have any way of limiting the cache size, which is normally advisable in high-volume situations; but just FYI, a very simple size-limited LRU cache can be built on top of a LinkedHashMap.

Sounds like you're probably past the "roll your own" stage though...

Winston


Um.. I need to represent tables in memory so there can't be any LRU do discard data. The use case is actually listed on this post but I'll paste it here for convenience. Still not sure if I should use off the shelf in memory dBs or roll my own map of maps. I need something fast like TimesTen but can't find an existing open source solution that offers speed like that. So am looking at things like EhCache and map of maps. Any pointers?

1) Multiple tables to be held in memory.
2) Each table's structure (ie name and number of columns, number of rows, content of the cells) are to be determined at run time.
3) Ability to insert / remove columns anywhere after table is created.
4) Ability to insert / remove rows anywhere after table is created.
5) Ability to populate / update cells anywhere after table is created.
6) Ability to inject call back methods to be well ... call backed, upon changes to the table.
This I think I can do easily by creating an array of funciton pointers, and iterate them through whenever the methods that are used to update the table are called upon.
7) Ability to allow incoming request for the current view of the table, to get the table without being corrupted by incoming requests to make changes to the table (ie insert / remove columns / rows, populate / update cells).
8) Ability to do simple joins across different tables.

 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Cheung wrote:Um.. I need to represent tables in memory so there can't be any LRU do discard data.


OK, but the rest of your requirements sound like a database, not a cache, so I'd look at a database solution - perhaps a NoSQL one, because it doesn't sound like you need all the ACID properties.

I'm afraid I can't really advise on which are the best, because I've been an RDBMS guy all my life; but this definitely sounds beyond the sort of thing I would try to roll by myself.

Winston
 
Mike Cheung
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

Mike Cheung wrote:Um.. I need to represent tables in memory so there can't be any LRU do discard data.


OK, but the rest of your requirements sound like a database, not a cache, so I'd look at a database solution - perhaps a NoSQL one, because it doesn't sound like you need all the ACID properties.

I'm afraid I can't really advise on which are the best, because I've been an RDBMS guy all my life; but this definitely sounds beyond the sort of thing I would try to roll by myself.

Winston


Um... any recommendations for these NoSQL in memory dB? Am guessing you recommending them because NoSQL ones are faster than traditional embedded in memory approaches that support ACID? Was researching the faster ones that support ACID such as Oracle Times Ten (update is about 1.7 micro second), eXtremeDB, HyperXtremeSQL (a million rows per second), and ObjectDB but they are non open source and have vendor lock in. Also not sure if product can be distributed with the dB as part of the solution (for example Oracle charges per server).

This also means I can't use the JavaFX databinding feature which automagically syncs the front end GUI to any changes to the TableView as shown in this example here. Although there are still further questions I need to find out even using the JavaFX TableView approach such as: 1) How to have multiple GUIs working with the same table; 2) How to change the table structure at run time (note how they use a POJO class that has a fixed structure before compilation); 3) How to access a specific column or cell quickly via the use of col name and row name, etc.

So yes the more I think about it the more it makes sense to use a proper off the shelf in memory dB solution. But then I have to find out how to code the system such that I can have a number of front end GUIs that are in sync of the in memory table representation. I guess this can be done by connecting the GUIs via MQs. What would you recommend? Any alternatives?
 
Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic