RMI响应非常慢 [英] RMI responding very slow

查看:162
本文介绍了RMI响应非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java远程方法调用(RMI)测试Web应用程序.当我通过加密狗,宽带连接到Internet时; RMI需要很长时间才能响应该请求.完成方法调用大约需要10秒钟.我还可以看到,一旦进行方法调用,互联网连接中的数据传输速率就会提高.因此,显然,它似乎正在通过外部网络在两个内部进程之间建立RMI连接.

I am testing a web application using Java Remote Method Invocation (RMI). When I am connected to internet through dongle, broadband; it takes very long time for the RMI to respond to the request. It takes around 10 seconds in completing the method call. I can also see the data transfer rate rising in the internet connection as soon as I make a method call. So definitely it seems to be making an RMI connection between two internal processes through the external network.

与互联网断开连接后,其响应速度变化很快,例如几毫秒之内.我的/etc/hosts文件具有127.0.0.1 localhost的条目.我始终在naming.lookup的方法调用URL中使用127.0.0.1.但是无法弄清楚当我连接到Internet时如何使计算机快速响应RMI呼叫.有什么建议?

While disconnected from internet it responds vary fast, like in few milliseconds. My /etc/hosts file have entry for 127.0.0.1 localhost. I always use 127.0.0.1 in the method invocation url for naming.lookup. But can't figure out how to make machine respond quickly to RMI calls while I am connected to the internet. Any suggestions?

推荐答案

问题不是您用于RMI注册表的查找调用的地址,而是URL中地址的结果.调用查找.该默认值是系统上第一个接口的IP地址,因此我的猜测是,当您连接到Internet时,它就是您的外部连接.

You problem is not the the address that you use for the lookup call to the RMI Registry, but rather it's the address in the URL that is the result of the call to lookup. This defaults to the IP address of the first interface on the system so my guess is that when you're connected to the Internet it's your external connection.

我认为正在发生的事情是您在127.0.0.1上调用了RMI注册表,这将使Internet地址返回您想要的服务的位置,因此RMI调用将通过加密狗接口路由出去.

What I think is happening is that you make a call to the RMI Registry on 127.0.0.1 and this returns your Internet address the location of the service you want, and so your RMI call gets routed out over the dongle interface.

您需要设置 java.rmi.server.hostname属性告诉RMI注册中心要在其RMI URL中返回哪个主机名或IP地址.

You need to set the java.rmi.server.hostname property to tell the RMI Registry which hostname or IP Adress to return in its RMI URLs.

因此,您将需要以下内容:

So you'll need something like:

String ipAddress = "10.1.2.3"; //Local IP address 
System.setProperty("java.rmi.server.hostname",ipAddress);

String hostname = "myserver"; //hostname that resolves for a local address
System.setProperty("java.rmi.server.hostname",hostname);

这篇关于RMI响应非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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