JVM heap replication between two machines

前端 未结 4 748
终归单人心
终归单人心 2021-02-01 15:26

What are the basic principles of how two separable computers connected within the same network running the same Java application maintain the same state by syncing their heap be

相关标签:
4条回答
  • 2021-02-01 16:11

    Terracotta can indeed handle that if you tell it to - see the description of its DSO - Distributed Shared Objects.

    It sounds cool but I would prefer something like EHcache (can be backed by Terracotta again) which functions on a bit more high level.

    0 讨论(0)
  • 2021-02-01 16:14

    One emerging technology that somehow tackles this problem is Distributed Software Transactional Memory. You get strong data consistency guarantees (i.e. 1-copy serializability) and a powerful concurrency control mechanism: transactions.

    AFAIK, there is no mature solution out there, but it is promising.

    0 讨论(0)
  • 2021-02-01 16:19

    Terracotta DSO works by manipulating the byte code of your classes (and the JDK's classes etc). The instructions on how and when to do this are part of the Terracotta configuration file.

    The bytecode modification looks for certain byte codes such as a field read or write or a monitor enter or exit. Whenever those instructions occur, code is added around that location that does the appropriate action in the distributed store. For example when a monitor is obtained due to synchronization, a distributed lock is obtained as well (whether it is a read or write lock is dependent on the configuration). If a field in a shared object is written, the distributed system must verify that a write lock is being held and then send the data value is sent to the clustered server, which stores it on disk or shares it over the network as appropriate.

    Note that Terracotta does not share the entire heap, only the graph of objects indicated by the configuration. In general, there would be little point in sharing an entire heap. It is better instead for the application to describe the domain objects needed across the distributed application.

    There are many optimizations employed to make the operations above efficient: only field deltas are sent over the wire and in a form much more efficient than Java serialization, many deltas can be bundled and sent in batches, locks are actually "checked out" to a particular client so that if the application data is partitioned across clients, most distributed locks are actually a local operation not involving a network call, etc.

    0 讨论(0)
  • 2021-02-01 16:22

    I would recommend that you investigate http://www.jboss.org/infinispan and see if it will fulfill your needs.

    0 讨论(0)
提交回复
热议问题