3

I am developing a system, which can be in very simple terms described as below:

  1. There are multiple servers, each running the same Java App (for scalability).
  2. There is a common database server, which each application server talks to.
  3. Millions of clients, each connecting to one random server. Each client has one open socket with one server.

Now say, Client A is connected to Server A, and wants to send a message to Client B.

What is the best approach for this kind of problem? Whats the best way to keep track which client is connected to which server, and how to make the servers talk to each other.

This is a Java specific problem. If there was only one server, it could have been done through inter thread communication. But the problem is for multiple servers. Also, are there any open source libraries that make this task easier?

4
  • One approach could be to store in the common database, which client is connected to which server. And what process Id and Thread Id have the client socket, and then using RMI to send the message. But are there any more efficient solutions? Commented Feb 25, 2012 at 8:43
  • I was also interested in this question. Can I use ActiveMQ for this and send messages to all servers over the topic, and then on each server to check whether the message to him or not (by ID recipient)? Commented Feb 25, 2012 at 8:46
  • 4
    Instead of connecting your clients to a random server, why don't you make them connect to a specific server determined by a hash function over, for example, their IP address? Commented Feb 25, 2012 at 11:14
  • I haven't decided that policy yet, but in any case I'll still need to do inter-server communication. Commented Feb 25, 2012 at 15:26

2 Answers 2

3

Either your servers need to be able to look up the location of clients (perhaps via the database, perhaps by a dedicated address server) or you need to remove the randomness by using hashing approaches or some other non-random partitioning, as suggested by Kru in the comments. (Either way, you have issues if a server goes down, but perhaps that's outside the scope of your question).

Your servers then need to be able to forward messages to the appropriate other server. The simplest way is for them to maintain socket connections to each other.

Another approach is to use a message queuing system. You might consider using a high-performance brokerless system such as ZeroMQ, which provides a socket-like API, but higher throughput and failure tolerance, plus richer messaging patterns. Higher-level messaging products can probably implement most of the system you describe anyway (handling scalability, addressing etc).

You might be able to use an existing protocol like XMPP rather than inventing your own distributed messaging system.

Sign up to request clarification or add additional context in comments.

Comments

0

I believe you're looking for a Distributed Hash Table. You could use a Chord protocol, and you use the hash of the IP as the key. Using this key, the protocol will be able to route to the appropriate server that contains the key. (the server that maintains the connection with client B). You can also check out existing java implementations of a DHT such as http://tomp2p.net/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.