The difference between on-heap and off-heap

Ehcache talks about in the heap and in the heap of memory. What is the difference? What JVM arguments are used to configure them?

+85
java heap memory ehcache
May 22 '11 at 23:56
source share
6 answers

Storage on the heap refers to objects that will be present on the Java heap (as well as under the GC condition). On the other hand, heap storage refers to (serialized) objects that are managed by EHCache but are stored outside the heap (and also not subject to GC). As storage with heap continues to be managed in memory, it is slightly slower than storage on the heap, but still faster than disk storage.

The internal details related to managing and using the storage outside the heap are not very visible in the link provided in the question, so it would be wise to check the details of the Terracotta BigMemory , which is used to manage the storage outside the disk. BigMemory (heap storage) should be used to avoid the overhead of GC on the heap, which is several megabytes or gigabytes. BigMemory uses the JVM process memory address space through direct ByteBuffers , which are not GC- specific , unlike other native Java objects.

+103
May 23 '11 at a.m.
source share

from http://code.google.com/p/fast-serialization/wiki/QuickStartHeapOff

What is a dump heap?

Usually all non-temporary objects that you assign are managed by the java garbage collector. Although the VM does a decent job of collecting garbage, at some point the VM should do the so-called “Full GC”. A full GC includes scanning the entire allocated heap, which means that the GC pauses / slows are proportional to the size of the application heap. Therefore, do not trust anyone telling you that "Memory is cheap." In java memory, consumption degrades performance. In addition, you can get noticeable pauses using heap sizes> 1 GB. This can be frustrating if you have things in almost real time, in a cluster or grid, the java process may not respond and be dropped from the cluster.

However, today's server applications (often built on thieves frameworks ;-)) easily require heaps far beyond 4Gb.

One solution to these memory requirements is to "unload" parts of objects into a non-java heap (directly allocated from the OS). Fortunately, java.nio provides classes for directly allocating / reading and writing "unmanaged" pieces of memory (even with memory mapping).

Thus, you can allocate large amounts of "uncontrolled" memory and use it to save objects. To store arbitrary objects in unmanaged memory, the most viable solution is to use serialization. This means that the application serializes the objects into offheap memory, later the object can be read using deserialization.

The heap size controlled by the Java virtual machine may be small, so GC pauses are in milliseconds, everyone is happy with the work.

It is clear that the performance of such a heap buffer depends mainly on the performance of serialization implementation. Good news: for some reason, serializing FST is pretty fast :-).

Examples of use cases:

  • Session cache in the server application. Use a memory mapped file to store gigabytes of (inactive) user sessions. Once a user enters your application, you can quickly access data related to the user, without having to deal with a database.
  • Caching of computational results (queries, html-pages, ..) (applicable only if the calculation is slower than deserializing the result object from c).
  • very simple and quick save using memory mapped files

Edit: For some scenarios, you can choose more sophisticated garbage collection algorithms such as ConcurrentMarkAndSweep or G1 to support large heaps (but it also has its limits beyond 16 GB). There is also a commercial JVM with improved "inconclusive" GC (Azul).

+58
Dec 15 '12 at 17:31
source share

A heap is a place in memory where your dynamically distributed objects live. If you used new , then this is on the heap. This is in contrast to the stack space in which the functional stack lives. If you have a local variable, then this link is on the stack. The Java heap needs to be garbage collected, and objects can be used directly.

EHCache cumulative storage takes your regular object from the heap, serializes it, and stores it as bytes in the memory block that controls EHCache. It is like saving it to disk, but it is still in RAM. In this state, objects are not directly used; they must first be deserialized. Also not subject to garbage collection.

+21
May 23 '11 at a.m.
source share

In short

Enable / disable Java on the heap

pic credits




Detailed image

Java On / Off Heap storage in details

pic credits

+3
Jul 23 '17 at 16:35
source share

Not 100%; however, it sounds like this: a heap is an object or a set of allocated space (in RAM), built into the functionality of the code of either Java itself, or more likely functionality from ehcache itself, and a sink without a heap has its own system like Well; however, it seems that it is one size slower because it is not so organized, that is, it cannot use the heap (referring to one long set of RAM space) and instead uses different address spaces, which makes it somewhat less efficient.

Then, of course, the next level below is the hard disk space.

I do not use ehcache, so you may not want to trust me, but this is what I compiled from my documentation.

+2
May 23 '11 at
source share

The JVM knows nothing about memory outside the heap. Ehcache implements a cache disk on disk, as well as a cache in memory.

0
May 23 '11 at
source share



All Articles