打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

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



sun.rmi.dgc.checkInterval 

查询契约间隔时间 

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


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

java.rmi.dgc.leaseValue 
契约时长 

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

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


sun.rmi.dgc.server.gcInterval (1.2 andlater) 

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

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


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



sun.rmi.dgc.ackTimeout 

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

The value of this property represents the length of time (inmilliseconds) that the server-side Java RMI runtime will stronglyrefer to a remote object (or a reference to a remote object) thathas been returned from the current virtual machine as part of theresult of a remote method call, until it receives positiveacknowledgment from the client that the remote reference has beenfully received and processed. This timeout only applies to failuresituations (in which the client fails to send the acknowledgment).Setting the value too low can increase the risk of a remote objectbeing prematurely garbage collected when the only known referenceto the remote object is the one in transit as part of the remotemethod call result. The maximum value is Long.MAX_VALUE. Thedefault value is 300000 (fiveminutes). 

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


java.rmi.server.disableHttp 
禁用http 

If this value is true, HTTP tunneling is disabled, even whenhttp.proxyHost is set. The default value is false. If you know thatyour program will never need to use HTTP tunneling, then bydisabling HTTP tunneling, you should see shorter timeouts forfailed connections. 

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



sun.rmi.transport.tcp.maxConnectionThreads 

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

The value of this property controls the maximum size of the pool ofthreads used to handle incoming connections, and thus it places anupper bound on the number of incoming remote method invocationsthat can execute concurrently. Setting this property to a lowervalue may improve the throughput of a Java RMI server applicationunder heavy load, but setting it too low may (depending on thenature of the application's remote invocation patterns) lead todeadlock or starvation. The default value is the maximum,Integer.MAX_VALUE, which effectively means nolimit. 

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


sun.rmi.transport.tcp.threadKeepAliveTime (6 andlater) 

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

The value of this property controls the amount of time that athread in the pool of threads used to handle incoming connectionswill remain idle before terminating. The default value is 60000milliseconds (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 RMIruntime uses. The value is passed to java.net.Socket.setSoTimeout.This property is used only for cases where a client has not droppedan unused connection as it should (seesun.rmi.transport.connectionTimeout). The default value is2*3600*1000 milliseconds (twohours). 

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


sun.rmi.transport.tcp.responseTimeout 

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

The value of this property represents the length of time (inmilliseconds) that the client-side Java RMI runtime will use as asocket read timeout on an established JRMP connection when readingresponse data for a remote method invocation. Therefore, thisproperty can be used to impose a timeout on waiting for the resultsof remote invocations; if this timeout expires, the associatedinvocation will fail with a java.rmi.RemoteException. Setting thisproperty should be done with due consideration, however, because iteffectively places an upper bound on the allowed duration of anysuccessful outgoing remote invocation. The maximum value isInteger.MAX_VALUE, and a value of zero indicates an infinitetimeout. The default value is zero (notimeout). 

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


sun.rmi.transport.tcp.handshakeTimeout 

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

The value of this property represents the length of time (inmilliseconds) that the client-side Java RMI runtime will use as asocket read timeout when reading initial handshake data (protocolacknowledgment) when establishing a new JRMP connection. Thisproperty is used to configure how long the Java RMI runtime willwait before deciding that a TCP connection accepted by a remoteserver cannot actually be used, either because the entity listeningon the remote host's port is not actually a Java RMI server, orbecause the server is somehow not functioning correctly. Themaximum value is Integer.MAX_VALUE, and a value of zero indicatesan infinite timeout. The default value is 60000 (oneminute). 

优化: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 performancemonitor 

Note: 

All of sun.* only work for sunjdk 

What is DGC: 

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


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




总结: 

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

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

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


关于日志监测: 

通过google发现很多做RMI方面的应用都会通过设置一些log来监测rmi的网络,DGC来查看RMI的实际网络负载,DGC频率。 
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
intellij idea中使用maven创建web项目
java – Tomcat JMX连接 – 身份验证失败
jndi使用的一个问题
REST vs Web Service
用RMI开发基于Java的企业分布式应用 - GAULEN JAVA信息网 - info....
tomcat设置远程连接
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服