janusgraph icon indicating copy to clipboard operation
janusgraph copied to clipboard

Clarification on InMemory Storage Backend Documentation

Open li-boxuan opened this issue 7 years ago • 3 comments

https://docs.janusgraph.org/storage-backend/inmemorybackend/ has a brief introduction to the inMemory Storage Backend. I would expect it to be more detailed.

For example, I guess there is no data inconsistency issue for in-memory storage backend, and 'cache.db-cache' configurations don't work if storage.backend=inmemory.

li-boxuan avatar Oct 09 '19 14:10 li-boxuan

Hi @li-boxuan, the documentation mentions that the current implementation of the in-memory backend is for testing only, and is not recommended for any production use. This might be the reason why it doesn't provide too much detail.

There is an open issue and PR which intend to improve the implementation and make it fit for certain production usage scenarios where persistence is not required, or achieved via application-level snapshots. See #1482 - once it is merged, the documentation will be updated and more details will be provided about potential uses and caveats.

As for your guesses that there is no data inconsistency and that second level caches are not used when using in-memory backend - they are actually incorrect.

  1. A JanusGraph "graph level" transaction collects all modifications it makes to the graph in the transaction level cache, and only writes it out to the underlying backend stores on commit.
  2. It usually needs to modify multiple underlying stores when committing a single graph-level transaction (e.g. vertex store and index store), and it usually relies on backend implementation to provide atomicity of this multi-store backend-level transaction.

In-memory backend does not support rewinding commits which failed half-way, and does not provide locking/transactionality across multiple backend stores modified - which means that if your graph transaction commit fails half way, you might be left with an inconsistent storage. Of course a situation where a commit to an in-memory store fails is pretty rare, But it can still happen e.g. if your program stored enough data to fill up the JVM heap to the point where it has to run a "full GC", and if your heap is very large then this GC pause can be longer than the configured backend transaction timeout.

Another possible way your storage can be left in inconsistent state due to relaxed consistency in the inmemory backend implementation is when you execute massive numbers of parallel transactions which modify the same parts of your graph. As mentioned, the in-memory backend does not provide ACID guarantees, and so if you are adding, deleting and modifying the same vertex at the same time in parallel, the result is not deterministic.

None of the above means that you cannot use the backend in a meaningful way. In fact, most backends are only "eventually consistent" and prefer to relax consistency guarantees in order to provide better performance.

You just need to be careful about the way you do the modifications on your graph, that's all.

Hope this helps.

dk-github avatar Oct 24 '19 23:10 dk-github

Thank you @dk-github ! I'll close this issue then. Hope your PR gets merged soon.

li-boxuan avatar Oct 25 '19 01:10 li-boxuan

@li-boxuan in case you are still interested - the improvements to in-memory backend are merged, here is the PR to update the documentation about in-memory backend usage and limitations - feel free to comment:

https://github.com/JanusGraph/janusgraph/pull/1934

dk-github avatar Jan 20 '20 20:01 dk-github