RMI 各参数意义及其优化方案

根据RMI参数意义,可以归结为以下几点,我们可以根据这几点通过优化GC, 网络等待,流传输协议(http/rmi special socket)等方面来优化RMI。
同时,根据RMI的若干log配置,可以做到实时监控RMI网络,GC信息,针对实时监控的情况,有效地优化RMI参数设置。



sun.rmi.dgc.checkInterval

查询契约间隔时间

The value of this property represents (in milliseconds) how often the Java RMI runtime checks for expired DGC leases. The default value is half the value of the java.rmi.dgc.leaseValue property.


优化:尽早的删除引用有利于管理内存,但leaseValue太短的话又会造成网络风险。这一点可根据本身的网络情况作优化。

java.rmi.dgc.leaseValue
契约时长

The value of this property represents the lease duration (in milliseconds) granted to other VMs that hold remote references to objects which have been exported by this VM. Clients usually renew a lease when it is 50% expired, so a very short value will increase network traffic and risk late renewals in exchange for reduced latency in calls to Unreferenced.unreferenced. The default value of this property is 600000 milliseconds (10 minutes).

优化:尽早的删除引用有利于管理内存,但leaseValue太短的话又会造成网络风险。这一点可根据本身的网络情况作优化。
Note that for optimal performance, the lease term should not be set toa very small value. An active RMI client automatically renews the lease when it is halfway expired, and a very small lease term would cause the client to consume precious network resources in repeatedly renewing the lease.


sun.rmi.dgc.server.gcInterval (1.2 and later)

暂时不太理解, 我把它理解成如果远端的Object 引用无法删除,则本地GC默认会在一小时后将它删除。

When it is necessary to ensure that unreachable remote objects are unexported and garbage collected in a timely fashion, the value of this property represents the maximum interval (in milliseconds) that the Java RMI runtime will allow between garbage collections of the local heap. The default value is 3600000 milliseconds (one hour).


优化: 尽早删除,但check 间隔同样不能太短



sun.rmi.dgc.ackTimeout

此参数意义在于,服务器端将结果返给客户端,并持续尝试设置一个引用指向返还结果。如果客户端返还失败,这个尝试过程会默认持续五分钟

The value of this property represents the length of time (in milliseconds) that the server-side Java RMI runtime will strongly refer to a remote object (or a reference to a remote object) that has been returned from the current virtual machine as part of the result of a remote method call, until it receives positive acknowledgment from the client that the remote reference has been fully received and processed. This timeout only applies to failure situations (in which the client fails to send the acknowledgment). Setting the value too low can increase the risk of a remote object being prematurely garbage collected when the only known reference to the remote object is the one in transit as part of the remote method call result. The maximum value is Long.MAX_VALUE. The default value is 300000 (five minutes).

优化:当Client 拿到结果后,应当立即告诉 Server 端结果已拿到,这一点也可根据网络情况作优化。


java.rmi.server.disableHttp
禁用http

If this value is true, HTTP tunneling is disabled, even when http.proxyHost is set. The default value is false. If you know that your program will never need to use HTTP tunneling, then by disabling HTTP tunneling, you should see shorter timeouts for failed connections.

优化:连接的建立可以是 rmi 自已专用的那一套,如果建立失败,则会尝试用http。若禁用了这一选项,你便可以在很短的时间内看到你是否连接成功。



sun.rmi.transport.tcp.maxConnectionThreads

连接池的大小,默认为无限制

The value of this property controls the maximum size of the pool of threads used to handle incoming connections, and thus it places an upper bound on the number of incoming remote method invocations that can execute concurrently. Setting this property to a lower value may improve the throughput of a Java RMI server application under heavy load, but setting it too low may (depending on the nature of the application's remote invocation patterns) lead to deadlock or starvation. The default value is the maximum, Integer.MAX_VALUE, which effectively means no limit.

优化:理想状态下连接池的大小应当确保应用可以快速的拿到连接,太多或太少都不太合理, 应根据系统环境作合理设置。


sun.rmi.transport.tcp.threadKeepAliveTime (6 and later)

回收到池里面的连接将在一分钟后关闭

The value of this property controls the amount of time that a thread in the pool of threads used to handle incoming connections will remain idle before terminating. The default value is 60000 milliseconds (one minute).

优化:1 minutes is ok.


sun.rmi.transport.tcp.readTimeout

等待即将到达的连接所消耗的时间, 默认等的最长时间为两小时

The value of this property represents the time (in milliseconds) used as an idle timeout for incoming TCP connections the Java RMI runtime uses. The value is passed to java.net.Socket.setSoTimeout. This property is used only for cases where a client has not dropped an unused connection as it should (see sun.rmi.transport.connectionTimeout). The default value is 2*3600*1000 milliseconds (two hours).

优化:这里通常不需要作优化,当一个大文件传输的时候,它所需要的时间或许真的有点长。


sun.rmi.transport.tcp.responseTimeout

此参数意义在于,当此参数不为0时,如果server端运算时间过长,则相关的调用就会失败,抛出java.rmi.RemoteException异常

The value of this property represents the length of time (in milliseconds) that the client-side Java RMI runtime will use as a socket read timeout on an established JRMP connection when reading response data for a remote method invocation. Therefore, this property can be used to impose a timeout on waiting for the results of remote invocations; if this timeout expires, the associated invocation will fail with a java.rmi.RemoteException. Setting this property should be done with due consideration, however, because it effectively places an upper bound on the allowed duration of any successful outgoing remote invocation. The maximum value is Integer.MAX_VALUE, and a value of zero indicates an infinite timeout. The default value is zero (no timeout).

优化:这个参数不应当设置为无限大,或者0, 这样如果远端执行一个超长时间的事务时,客户端的线程将一直被挂起。


sun.rmi.transport.tcp.handshakeTimeout

导致这个参数估计网络不太好或者连不通造成

The value of this property represents the length of time (in milliseconds) that the client-side Java RMI runtime will use as a socket read timeout when reading initial handshake data (protocol acknowledgment) when establishing a new JRMP connection. This property is used to configure how long the Java RMI runtime will wait before deciding that a TCP connection accepted by a remote server cannot actually be used, either because the entity listening on the remote host's port is not actually a Java RMI server, or because the server is somehow not functioning correctly. The maximum value is Integer.MAX_VALUE, and a value of zero indicates an infinite timeout. The default value is 60000 (one minute).

优化:handshakeTimeout时间我个人认为可以小点,几秒就好了。








sun.rmi.client.logCalls
sun.rmi.loader.logLevel
sun.rmi.server.logLevel
sun.rmi.transport.logLevel
sun.rmi.dgc.logLevel
sun.rmi.transport.logLevel
sun.rmi.transport.tcp.logLevel
sun.rmi.transport.proxy.logLevel
sun.rmi.transport.tcp.logLevel

log relevant properties, we should use them for performance monitor

Note:

All of sun.* only work for sun jdk

What is DGC:

RMI框架采用分布式垃圾收集机制(DGC,Distributed Garbage Collection)


启用线程池
java -Dsun.rmi.transport.tcp.connectionPool=true <classname>




总结:

关于DGC:
当客户端获得了一个服务器端的远程对象存根时,就会向服务器发送一条租约通知,告诉服务器自己持有这个远程对象的引用了。此租约有一个租约期限,租约期限可通过系统属性 java.rmi.dgc.leaseValue来设置,以毫秒为单位,其默认值为600 000毫秒。当到达了租约期限的一半时间,客户端如果还持有远程引用,就会再次向服务器发送租约通知。如果租约到期后服务器端没有继续收到客户端的新的租约通知,服务器端就会认为这个客户已经不再持有远程对象的引用。

有时,远程对象希望在不再受到任何远程引用时执行一些操作,如释放所占用的资源,以便安全的结束生命周期。这样的远程对象需要实现java.rmi.server.Unreferenced接口,该接口有一个 unreferenced()方法,远程对象可以在这个方法中执行释放占用的相关资源的操作。当RMI框架监测到一个远程对象不再受到任何远程引用时,就会调用的这个对象的unreferenced()方法。

关于网络:
当有了连接池的机制,连接池里面的连接则会在需要的时候被使用,如有一段时间未被使用,则连接会自动断来。这一参数需要连接池有个合理的配置,使得连接的创建和关闭不会太频繁,但又可以使得连接的可重用性得以提高。另一方面,DGC的机制也会再来网络开销,所以设置DGC参数也要照顾到网络因素。在大文件传输方面,RMI只有一个参数与之相关, sun.rmi.transport.tcp.readTimeout 所以很难在这方面有太好的优化方案。


关于日志监测:

通过google发现很多做RMI方面的应用都会通过设置一些log来监测rmi的网络,DGC来查看RMI的实际网络负载,DGC频率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值