具有多个服务器的客户端-服务器架构
我正在开发一个应用程序,其中有两个多线程服务器(Server1 和 Server2)。我将这两个服务器中的数据保存在地图中。我想要做的是在服务器之间进行负载平衡(两台服务器上的数据量相同)。所以我有两个问题:
1)如何将客户端随机连接到服务器?例如,当我启动一个客户端时,该客户端会连接到 Server1,而当我启动另一个客户端时,该客户端会连接到 Server2。
2)我可以使用什么技术来实现服务器中的负载平衡?
此致。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在两台服务器之间分配负载的非常简单解决方案是使用循环 DNS。这里的基本思想是,所有 DNS 请求(由您的客户端发出)不仅会解析为单个 IP 地址,还会解析为它们的列表(在您的情况下为两个)。这反过来意味着他们将有效地连接到任一服务器。
这样做的简单性(也是缺点)是每个返回的 IP 地址不是
100 / n
的概率(其中n
是地址数量在列表中)。我只是想强调,不一定是 50%(两个的情况下)。现在,如果您想要真正负载平衡,您可以查看放置在
Server1
和Server2
前面的负载平衡设备。像这样的东西会更可靠,但你的成本/复杂性也会增加。对于最简单的解决方案,我会研究循环 DNS。
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
(wheren
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
andServer2
. 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.
您可能正在寻找ReverseProxy。有很多解决方案,根据您的项目,其中一种可能比另一种更合适。
You are probably looking for a ReverseProxy. There are lots of solutions, depending on your project one may be more appropriate than another.