负载均衡算法(四)IP Hash负载均衡算法

2023-06-09,,

    /// <summary>
/// IP Hash负载均衡算法
/// </summary>
public static class IpHash
{
static Dictionary<string, int> dic = new Dictionary<string, int>
{
{ "192.168.1.12", },
{"192.168.1.13", },
{ "192.168.1.14", },
{ "192.168.1.15", },
{"192.168.1.16", },
{"192.168.1.17", },
{ "192.168.1.18", },
{ "192.168.1.19", }
}; public static string ipHash(string remoteIp)
{
List<string> keys = dic.Keys.ToList(); int hashCode = Math.Abs(remoteIp.GetHashCode());
int serverListSize = keys.Count;
int serverPos = hashCode % serverListSize; return keys[serverPos];
} }

负载均衡算法(四)IP Hash负载均衡算法的相关教程结束。

《负载均衡算法(四)IP Hash负载均衡算法.doc》

下载本文的Word格式文档,以方便收藏与打印。