两台机器之间的JVM堆复制 [英] JVM heap replication between two machines

查看:125
本文介绍了两台机器之间的JVM堆复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行相同Java应用程序的同一网络中连接的两台可分离计算机如何通过在彼此之间同步堆来维持相同状态的基本原理是什么?



我相信 Terracotta 可以完成这项任务,但我有不知道一些伪代码会如何描述它的核心功能。



我只是在寻找对这项技术的理解。

解决方案

Terracotta DSO通过操纵类的字节代码(以及JDK的类等)来工作。有关如何以及何时执行此操作的说明是Terracotta配置文件的一部分。



字节码修改查找某些字节代码,例如字段读取或写入或监视器进入或退出。每当发生这些指令时,都会在分布式存储中执行相应操作的位置周围添加代码。例如,当由于同步而获得监视器时,也获得分布式锁定(无论是读取还是写入锁定取决于配置)。如果写入共享对象中的字段,则分布式系统必须验证是否正在保持写锁定,然后将数据值发送到群集服务器,群集服务器将其存储在磁盘上或根据需要通过网络共享。 / p>

请注意,Terracotta不会共享整个堆,只会共享配置指示的对象图。通常,共享整个堆没有什么意义。最好是应用程序来描述分布式应用程序所需的域对象。



有许多优化可以使操作高效:只有字段增量通过线路发送,并且形式比Java序列化更有效,许多增量可以是捆绑和批量发送,锁实际上检出到特定客户端,以便如果应用程序数据跨客户端分区,大多数分布式锁实际上是不涉及网络调用等的本地操作。


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 between each other?

I believe Terracotta does this task but I have no idea how would some pseudo code look like that would describe its core functions.

I'm just looking for understanding of this technology.

解决方案

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.

这篇关于两台机器之间的JVM堆复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆