Reputation: 1042
I'm developing an application where I have two multithreaded servers (Server1 and Server2). I am saving data in this two servers in a Map. What I want to do is sort of do a load balance between this to servers (have the same amount of data on both servers). So I have two questions:
1) How can I connect a client random to a server? For instance when I start a client this client connects for example to Server1 and when I start another client, this one connects to Server2.
2) What technique can I use to do the load balance in the servers?
Best regards.
Upvotes: 2
Views: 1180
Reputation: 31038
A very easy solution to distribute the load among the two servers would be to use Round-robin DNS. The basic idea here is that all DNS requests (by your clients) will not just resolve to a single IP address, but a list of them (in your case two). Which in turn means that they will effectively connect to either server.
The simplicity (and downside) of this is that the probability each IP address returned is not 100 / n
(where n
is the number of addresses in the list). I just wanted to emphasize that it won't necessarily be 50% (in the case of two).
Now if you wanted true load balancing, you can look into load balancing appliances that you would put in front of Server1
and Server2
. Something like this would be a lot more reliable, but then your cost/complexity also increases.
For the simplest solution, I would look into round-robin DNS.
Upvotes: 1
Reputation: 1142
You are probably looking for a ReverseProxy. There are lots of solutions, depending on your project one may be more appropriate than another.
Upvotes: 0