开发者

How could I quickly know if a server is online?

开发者 https://www.devze.com 2023-03-03 10:03 出处:网络
I\'m developing a Java client/server application in which there will be a great number of servers with which the clients are going to have to connect. The problem is that probably the vast majority of

I'm developing a Java client/server application in which there will be a great number of servers with which the clients are going to have to connect. The problem is that probably the vast majority of them will not be serving at the same time. The client needs to find at least one available in the list, so it will iterate it, looking for an available server (when it finds the first it stops, one is enough).

The problem is that the list will probably be long, tens of zousands, they could be even hundreds... and it may happen that only 1% of them are connected (i.e. executing the server). That's why I need a clever and a fast way to know if a server is connected, without waiting for time-outs or so. I accept all kinds of suggestions.

I have thought about ordering the server list statistically, so that the servers that are available more often are the first hosts attempted. But this is not enough.

Perhaps multicasting UDP datagrams? The connections between clients/servers are TCP, but perhaps to find a server it's better to do an UDP multicast first and wait for the answer, for example... what do you think?

:)

EDIT:

Both the server and client use thread pools.开发者_运维知识库

The server pool handles 200 threads concurrently, and when the pool is full, queues the rest until the queue is 200 runnables long. Then it blocks, and stop accepting connections until there is free room in the queue again.

The client has a cached thread pool, it can make all the request to the server you want concurrently (with common sense, obviously...).


This is just an initial thought and would add some over head, but you could have the servers periodically ping some centralized server which the clients would connect through. Then if the server doesn't ping for some set time it gets removed.


You might want to use a peer-to-peer network.

Have a look at JXTA/JXSE: http://jxse.kenai.com/index.html


If it is your own code which is running on each of these servers, could you send an alive to a central server (which is controlled by you and is guaranteed to be up at all times)? The central server can then maintain an updated list of all servers which are active. The client just needs a copy of this list from the central server and then start whatever communication it needs.


Sounds like a job for Threads. You cannot speed up the connection, it takes time to contact the server.

IMHO, the best way is to get few hundred Threads to march through the list of servers. The first one to find one server alive wins. Then signal other threads to die out.

Btw, did you really mean to order the server list "sadistically"? :)

0

精彩评论

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