3

I have some maps that contains cached data from db. Currently 5 instance of the same server is running on same machine in different JVM. How can I share maps between JVM? cache is write once and read many. Currently the problem is because of this cache JVM footprint is very big. So storing this map in all JVM is consuming lot of memory. I need some solution which may not consume much cpu time. Is there way to do this in the same way class sharing is done between JVM?

Thanks Nikesh PL

Nike
  • 312
  • 1
  • 2
  • 9
  • http://stackoverflow.com/q/1195633/684934 –  Sep 29 '11 at 02:25
  • Your best bet is probably with one of the key-value caching solutions. Like Memcache or what Terracotta does. Not exactly the same as an in-memory hashmap, but much more memory efficient. – Thilo Sep 29 '11 at 02:32

2 Answers2

1

Basically, you can't: those are two different address spaces.

You could serialize one and read it from the other, but that wouldn't be like sharing them.

How about a process to manage the cache, and a quick, low-bandwidth interface that your application programs can use to access the data?

Charlie Martin
  • 110,348
  • 25
  • 193
  • 263
  • The look up frequency to the map is very high almost 50million/hour/core. So every time I need to accessing from a different process. It will impact the performance right? – Nike Sep 29 '11 at 02:35
  • 1
    With that kind of workload -- that's 14K hits/s -- and assuming a relatively high proportion of writes, you should probably not be thinking of Java at all. Consider writing a shared memory module in C/C++ that can be accessed via JNI. You *might* be able to get that sort of performance with an in-memory database, but 28K context-switches a second could be trouble too. – Charlie Martin Oct 03 '11 at 05:18
1

Why dont you look at coherence a project from oracle. Its not free but you can download and test it for free on a development system. It does precisely what you are looking for. It is used as a cache for storing database data but is ultimately a map of keys and values. Its pretty simple to set up and use. Here's a link to get you started:

http://download.oracle.com/docs/cd/E13924_01/coh.340/e14135.pdf

sethu
  • 8,181
  • 7
  • 39
  • 65