3

I am running a web application that makes use of Ehcache 3.4.0. I have a cache configuration that defines a simple default of 1000 in-memory objects:

<cache-template name="default">
    <key-type>java.lang.Object</key-type>
    <value-type>java.lang.Object</value-type>
    <heap unit="entries">1000</heap>
</cache-template>

I then have some disk-based caches that use this default template, but override all values (generated programmatically, so that's why they even use the default template at all) like so:

<cache alias='runViewCache' uses-template='default'>
    <key-type>java.lang.String</key-type>
    <value-type>java.lang.String</value-type>
    <resources>
        <heap unit='entries'>1</heap>
        <disk unit='GB' persistent='true'>1</disk>
    </resources>
</cache>

As data is written into my disk-based cache, direct/off-heap memory is used by the JVM, and never freed. Even clearing the cache does not free the memory. The memory used is directly related (nearly byte-for-byte as far as I can tell) to the data written to the disk-based cache.

The authoritative tier for this cache is an instance of org.ehcache.impl.internal.store.disk.OffHeapDiskStore.

This appears to be a memory leak (memory is consumed and never freed) but I am by no means an expert at configuring ehcache. Can anyone suggest a configuration change that will cause my disk tier to NOT use off-heap memory? Or, is there something else that I am just completely misunderstanding that someone else can point out?

Thank you!

Daniel
  • 3,312
  • 1
  • 14
  • 31
  • A little further info: when testing, we greatly reduced the size of the disk (set to 20mb) and saw more off-heap memory used than that. We were hopeful that at worst, there was a 1 to 1 correlation between disk size and off heap memory consumption, but that does not seem to be the case. – Daniel Nov 01 '17 at 23:29
  • Can you please be very specific about the exact memory type you see increased? Ehcache 3 disk uses `java.nio.channels.FileChannel` to store data. While it is normal to see a slight heap increase as we need references to the data structures, there should not be an increased RAM consumption, unless you OS does caching. – Louis Jacomet Nov 14 '17 at 10:49

1 Answers1

2

How do you measure "used"?

TL;DR No, disk tier does not waste RAM.

As of v3.0.0 Ehcache uses memory mapped files for disk persistence:

Replacement of the port of Ehcache 2.x open source disk store by one that leverages the offheap library and memory mapped files.

This means, Ehcache uses in-memory address space to access files on disk. This does consume 0 bytes of your RAM. (At least directly. As @louis-jacomet already stated, the OS can decide to cache parts of the files in RAM.)

When you're running on Linux you should compare the VIRT and RES values of your process. VIRT is the amount of virtual bytes used by the process. RES is the amount of real RAM (RESident) bytes used by the process. VIRT should increase, while disk store cache is populated, but RES should remain pretty stable.

Eduard Wirch
  • 9,785
  • 9
  • 61
  • 73