简体   繁体   English

具有多个服务器的客户端-服务器体系结构

[英]Client-Server architecture with multiple servers

I'm developing an application where I have two multithreaded servers (Server1 and Server2). 我正在开发一个应用程序,其中有两个多线程服务器(Server1和Server2)。 I am saving data in this two servers in a Map. 我正在将数据保存在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? 1)如何将客户端随机连接到服务器? 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. 例如,当我启动一个客户端时,该客户端连接到Server1,而当我启动另一个客户端时,该客户端连接到Server2。

2) What technique can I use to do the load balance in the servers? 2)我可以使用什么技术在服务器中进行负载平衡?

Best regards. 最好的祝福。

A very easy solution to distribute the load among the two servers would be to use Round-robin DNS . 在两个服务器之间分配负载的一种非常简单的解决方案是使用轮询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). 这里的基本思想是,所有DNS请求(由您的客户端)将不仅解析为单个IP地址,而且将解析为它们的列表 (在您的情况下为两个)。 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). 这种方法的简单性(缺点)是,每个返回的IP地址的概率不是 100 / n (其中n是列表中的地址数)。 I just wanted to emphasize that it won't necessarily be 50% (in the case of two). 我只是想强调一点,不一定是50%(对于两个)。

Now if you wanted true load balancing, you can look into load balancing appliances that you would put in front of Server1 and Server2 . 现在,如果您想要真正的负载平衡,那么可以研究一下放在Server1Server2前面的负载平衡设备。 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. 对于最简单的解决方案,我将研究轮询DNS。

You are probably looking for a ReverseProxy . 您可能正在寻找ReverseProxy There are lots of solutions, depending on your project one may be more appropriate than another. 有很多解决方案,取决于您的项目,一个可能比另一个更合适。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM