문제

These days we have lots of cheap RAM available but we cant use it as it causes huge garbage collection and halting the application which is not desirable. When I was reading Terracotta; I felt that this is solving my problem because I will use my extra memory on terracotta and that memory will not be exposed to garbage collection.

Is it that in my application I can create some distributed hashmap and the data I put on this hashmap will not be counted on my java heap size ? But that will mean code changes. And this looks same like MemCached.

Is there any way possible; so that without making any code changes to my existing app ( or if I am using a third party like jmeter ) I can use this extra RAM ?

If it is not possible with terracotta; is it possible in any other way ?

도움이 되었습니까?

해결책

Take a look at ByteBuffer#allocateDirect(int). It allocates a byte buffer (to which you can read and write) outside the heap (and thus outside the CG area of interest).

What it does in the background is delegating calls to com.sun.Unsafe with some additional checking of -XX:MaxDirectMemorySize JVM option. The -XX:MaxDirectMemorySize says how much of direct memory one can use for direct allocation. (by default it's 64MB IIRC).

This is what Ehcache and Terracota do to avoid extensive GC.

However, this does not mean, you do not have to change your application to use it. Notice, the allocated byte buffer is just a contignous area in the memory, with no interface other than read/write value at position. So to make it accessible via, say, a Map interface, you would have to implement this map yourself.

다른 팁

Terracotta has nice feature called BigMemory. Its allows to store data outside JVM heap accessing extra memory on your computer. It can use tens/hundreds of gigabytes outside of your JVM.

It will be no code changes to your existing ehcache calls. Its only configuration change in your ehcache.xml and JVM startup parameters (-XX:MaxDirectMemorySize).

In configuration then you can specify explicitly off-heap size for your caches:

<cache name="MyCache" ...
       maxBytesLocalOffHeap="5G"
       ...
</cache>

From terracotta doc:

To use off-heap as a data tier, a cache must have overflowToOffHeap set to "true". If a CacheManager has a pool configured for using off-heap, the overflowToOffHeap attribute is automatically set to "true" for all caches. In this case, you can prevent a specific cache from overflowing to off-heap by explicitly setting its overflowToOffHeap attribute to "false".

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top