Search code examples
javacachingherokufilesystemsehcache

Using the Heroku ephemeral filesystem as Ehcache disk storage


As the Heroku Dyno ephemeral filesystem documentation explains the file system will be discarded when the dyno is stopped or restarted. This means it cannot be used as persistent (disk) storage.

My use case is that I would like to cache some reference data using Ehcache. I was thinking to use some (limited) heap memory for the best performance, and if it is not sufficient fallback to disk storage. With Ehcache, this can be nicely configured on a per cache basis to e.g. store max 1000 entries in the heap memory, and e.g. 25MB on disk.

As per the Heroku documentation, it seems the ephemeral filesystem will stay intact while the dyno is running. When it is discarded when the app is stopped or restarted does not matter in my case. In my use case, it also does not matter when I run 3 dyno's that they all have their own cache in heap and disk.

  1. Is my assumption correct that the ephemeral filesystem will not be discarded during the requests while the dyno(s) is running? Only when a dyno is stopped or restarted?
  2. Can something be said about the performance of the ephemeral filesystem? Especially in my use case to use it as cache disk store.
  3. What is the size of the ephemeral filesystem? I cannot seem to find that in the documentation.

Solution

  • Overall, your plan to write Ehcache to disk seems fine. You will of course pay some overhead after each dyno restart, but that's expected with most caching systems.

    1. Is my assumption correct that the ephemeral filesystem will not be discarded during the requests while the dyno(s) is running? Only when a dyno is stopped or restarted?

    Yes, you are correct.

    1. Can something be said about the performance of the ephemeral filesystem? Especially in my use case to use it as cache disk store.

    You can expect performance similar to writing to the filesystem in an AWS EC2 instance. So pretty good.

    1. What is the size of the ephemeral filesystem? I cannot seem to find that in the documentation.

    I don't think there is a published limit. It also depends on your dyno (i.e. is it multi-tenant like hobby dynos or dedicated like a performance-m). I would guess that as long as you are writing less than 1GB you should have no trouble.