简体   繁体   English

如何在现有的Java应用程序(不暴露给GC)或我使用的第三方工具上使用我的盒子的额外RAM?

[英]How to use extra RAM of my box on existing java app ( not exposing it to GC ) or to a third party tool I use?

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. 这些天我们有很多廉价的RAM可用但我们不能使用它,因为它导致巨大的垃圾收集和停止应用程序,这是不可取的。 When I was reading Terracotta; 当我读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 ? 是不是在我的应用程序中我可以创建一些分布式hashmap,我放在这个hashmap上的数据不会计入我的java堆大小? But that will mean code changes. 但这意味着代码的变化。 And this looks same like MemCached. 这看起来像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 ? 所以,如果不对我现有的应用程序进行任何代码更改(或者如果我使用像jmeter这样的第三方),我可以使用这个额外的RAM吗?

If it is not possible with terracotta; 如果赤土陶器不可能; is it possible in any other way ? 是否有可能以任何其他方式?

Take a look at ByteBuffer#allocateDirect(int) . 看看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). 它在堆外部(因此在感兴趣的CG区域之外)分配一个字节缓冲区(您可以读取和写入)。

What it does in the background is delegating calls to com.sun.Unsafe with some additional checking of -XX:MaxDirectMemorySize JVM option. 它在后台执行的操作是通过对-XX:MaxDirectMemorySize JVM选项的一些额外检查来委托对com.sun.Unsafe调用。 The -XX:MaxDirectMemorySize says how much of direct memory one can use for direct allocation. -XX:MaxDirectMemorySize表示可以使用多少直接内存进行直接分配。 (by default it's 64MB IIRC). (默认情况下,它是64MB IIRC)。

This is what Ehcache and Terracota do to avoid extensive GC. 这就是Ehcache和Terracota为避免广泛的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. 因此,要通过Map接口访问它,您必须自己实现此映射。

Terracotta has nice feature called BigMemory . Terracotta有很棒的功能叫做BigMemory Its allows to store data outside JVM heap accessing extra memory on your computer. 它允许在JVM堆外部存储数据,从而访问计算机上的额外内存。 It can use tens/hundreds of gigabytes outside of your JVM. 它可以在JVM之外使用数十/几百GB。

It will be no code changes to your existing ehcache calls. 您现有的ehcache调用不会更改代码。 Its only configuration change in your ehcache.xml and JVM startup parameters (-XX:MaxDirectMemorySize). 它在ehcache.xml和JVM启动参数(-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". 要将堆外使用作为数据层,缓存必须将overflowToOffHeap设置为“true”。 If a CacheManager has a pool configured for using off-heap, the overflowToOffHeap attribute is automatically set to "true" for all caches. 如果CacheManager具有配置为使用堆外的池,则对于所有高速缓存,overflowToOffHeap属性将自动设置为“true”。 In this case, you can prevent a specific cache from overflowing to off-heap by explicitly setting its overflowToOffHeap attribute to "false". 在这种情况下,您可以通过将overflowToOffHeap属性显式设置为“false”来防止特定缓存溢出到堆外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM