开发者

Long delay in remote RMI (redundancy intended)

I have this rather simple RMI communication.

Server:

LocateRegistry.createRegistry(settings.rmiPort).bind("server", UnicastRemoteObject.exportObject(remoteMe, 0));

private final class RemoteLobbyServerImpl implements RemoteLobbyServer {
    @Override public void registerRobotServer(RemoteRobotServer robotServer, int seq) throws RemoteException {
        System.out.println(String.valueOf(seq));
//          robotManager.setServer(robotServer);
    }
}

Client:

        final Registry registry = LocateRegistry.getRegistry(lobbyHost, lobbyRmiPort);

        log.info("Looking up lobbyserver...");
        remoteLobbyServer = (RemoteLobbyServer) registry.lookup("server");
        log.info(remoteLobbyServer.toString());

        remoteMe = new RemoteRobotServerImpl();
        final int seq = (int)(Math.random() * 10);
        log.info("Registering myself "+seq+" ...");
        Future<?> registerTask = ThreadPool.submit(new Runnable(开发者_如何学JAVA) { @Override public void run() {
            try {
                remoteLobbyServer.registerRobotServer((RemoteRobotServer) UnicastRemoteObject.exportObject(remoteMe, 0), seq);
            } catch (RemoteException e) {
                throw new RuntimeException(e);
            }
            log.info("Registered");
        }});
        try {
            registerTask.get(30, TimeUnit.SECONDS);
        } catch (TimeoutException e) {
            registerTask.cancel(true);
            throw new RuntimeException("Registration timed out");
        }

This works fine when I run it on the same machine. However, it falls apart when there is some distance between the client and the server. Then it takes about 2 minutes for the server to respond.

Linux' ping says the latency is 20 ms. Strangely though, it does take a while before it shows that, while e.g. ping google.com (also 20 ms) has results rather quickly.

What could be up? How can I analyze this?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜