using Sog; namespace Account { public static class HttpProxySelect { public static int HttpProxyCount = 1; private static uint HttpProxySelectSeq = 0; private static uint HttpProxyID = 0; public static void Init(ServerApp app) { // 主备模式下cluster有独立的2套服务器, 每套服务器根据instId连接自己的DBServer int instId = (int)ServerIDUtils.GetInstanceID(app.ServerID); HttpProxyID = ServerIDUtils.GetLevel0ServerIDByType((int)ServerType.HttpProxy, instId); TraceLog.Debug("HttpProxySelect.Init HttpProxyID {0}", ServerIDUtils.IDToString(HttpProxyID)); //HttpProxyCount = app.GetCluster().GetChannelCount((int)ServerType.HttpProxy); //TraceLog.Debug("HttpProxySelect.Init HttpProxyCount is {0}", HttpProxyCount); } /// /// httpproxy帐号登录验证本身是多线程的,线程数量是HttpProxyLoginWorkThreadCount个,分线程的逻辑是根据hash尾数来算的, /// 我们要保证的是某个帐号只会由固定的某个线程处理,这样可以规避多线程锁的问题 /// /// /// /// public static uint GetHttpProxyID(int accountType,string accountID) { return HttpProxyID; ////根据accounttype,id hash //string strHash = AccountUtils.CalcAccountKey(accountType, accountID); //int hash = AccountUtils.HashStringForIndex(strHash); ////先去掉线程尾数的影响 //int muskThreadCount = hash / AccountUtils.HttpProxyLoginWorkThreadCount; ////根据进程数量计算 //int dbIndex = muskThreadCount % HttpProxyCount; //return ServerIDUtils.GetLevel0ServerIDByType((int)ServerType.HttpProxy, (int)dbIndex + 1); } /// /// 轮流选择 /// /// public static uint GetHttpProxyIDTurns() { return HttpProxyID; //int dbIndex = (int)(HttpProxySelectSeq % HttpProxyCount); //HttpProxySelectSeq++; //return ServerIDUtils.GetLevel0ServerIDByType((int)ServerType.HttpProxy, (int)dbIndex + 1); } } }