|
@@ -6,6 +6,7 @@ using System.Collections.Concurrent;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Diagnostics;
|
|
|
using System.IO;
|
|
|
+using System.Net.NetworkInformation;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using Vinno.IUS.Common.Log;
|
|
@@ -42,7 +43,8 @@ namespace Vinno.vCloud.Common.FIS
|
|
|
ServerInfo fasterServer = null;
|
|
|
var speedResults = new ConcurrentDictionary<ServerInfo, int>();
|
|
|
var serverFilePath = Path.Combine(settingFilePath, "FISServerSettingsV2.conf");
|
|
|
- var serverSettings = GetFasterServerList(true);
|
|
|
+ DefaultServerSettings serverSettings = null;
|
|
|
+ //serverSettings = GetFasterServerList(true);
|
|
|
if (serverSettings == null)
|
|
|
{
|
|
|
if (File.Exists(serverFilePath))
|
|
@@ -56,18 +58,18 @@ namespace Vinno.vCloud.Common.FIS
|
|
|
{
|
|
|
Servers = new List<ServerInfo>
|
|
|
{
|
|
|
- new ServerInfo { Host = "bj.flyinsono.com", Port = 80 },
|
|
|
- new ServerInfo { Host = "hk.flyinsono.com", Port = 80 },
|
|
|
- new ServerInfo { Host = "fra.flyinsono.com", Port = 80 },
|
|
|
- new ServerInfo { Host = "bom.flyinsono.com", Port = 80 },
|
|
|
+ new ServerInfo { Host = "bj.flyinsono.com", Port = 443 },
|
|
|
+ new ServerInfo { Host = "hk.flyinsono.com", Port = 443 },
|
|
|
+ new ServerInfo { Host = "fra.flyinsono.com", Port = 443 },
|
|
|
+ new ServerInfo { Host = "bom.flyinsono.com", Port = 443 },
|
|
|
},
|
|
|
- MasterServer = new ServerInfo { Host = "hk.flyinsono.com", Port = 80 }
|
|
|
+ MasterServer = new ServerInfo { Host = "hk.flyinsono.com", Port = 443 }
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
Parallel.ForEach(serverSettings.Servers, serverInfo =>
|
|
|
{
|
|
|
- var speed = GetConnectServerSpeed(serverInfo.ToString());
|
|
|
+ var speed = GetConnectServerSpeed(serverInfo.Host);
|
|
|
if (speed != -1)
|
|
|
{
|
|
|
speedResults.TryAdd(serverInfo, speed);
|
|
@@ -102,7 +104,7 @@ namespace Vinno.vCloud.Common.FIS
|
|
|
Logger.WriteLineError($"Get faster server error: {ex}");
|
|
|
}
|
|
|
|
|
|
- return new ServerInfo { Host = "hk.flyinsono.com", Port = 80 };
|
|
|
+ return new ServerInfo { Host = "hk.flyinsono.com", Port = 443 };
|
|
|
}
|
|
|
|
|
|
private static DefaultServerSettings GetFasterServerList(bool isUseHttps = true)
|
|
@@ -120,7 +122,7 @@ namespace Vinno.vCloud.Common.FIS
|
|
|
}
|
|
|
using (var client = new JsonRpcClient())
|
|
|
{
|
|
|
- var clientEngine = new JsonRpcHttpClientEngine($"{prefix}hk.flyinsono.com:80");
|
|
|
+ var clientEngine = new JsonRpcHttpClientEngine($"{prefix}hk.flyinsono.com:443");
|
|
|
client.UseEngine(clientEngine);
|
|
|
var vinnoServerService = client.CreateProxy<IVinnoServerService>();
|
|
|
var queryServerInfoRequest = new QueryServerInfoRequest();
|
|
@@ -130,7 +132,7 @@ namespace Vinno.vCloud.Common.FIS
|
|
|
return null;
|
|
|
}
|
|
|
string host;
|
|
|
- int port = 80;
|
|
|
+ int port = 443;
|
|
|
var serverSetting = new DefaultServerSettings() { Servers = new List<ServerInfo>() };
|
|
|
foreach (var server in result)
|
|
|
{
|
|
@@ -205,7 +207,59 @@ namespace Vinno.vCloud.Common.FIS
|
|
|
/// </summary>
|
|
|
/// <param name="serverUrl"></param>
|
|
|
/// <returns></returns>
|
|
|
- private static int GetConnectServerSpeed(string serverUrl, bool isUseHttps = true)
|
|
|
+ private static int GetConnectServerSpeed(string serverUrl)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (var ping = new Ping())
|
|
|
+ {
|
|
|
+ var successTimes = 0;
|
|
|
+ var totalTime = 0;
|
|
|
+ for (var i = 0; i < 4; i++)//第一次为预热
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var reply = ping.Send(serverUrl, 3000);
|
|
|
+ if (reply.Status == IPStatus.Success && i > 0)
|
|
|
+ {
|
|
|
+ Logger.WriteLineInfo($"Connect serverUrl:{serverUrl}, spend time:{reply.RoundtripTime}ms");
|
|
|
+ totalTime += (int)reply.RoundtripTime;
|
|
|
+ successTimes++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Logger.WriteLineError($"Connect serverUrl:{serverUrl} error, Exception:{ex}");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (successTimes == 0)
|
|
|
+ {
|
|
|
+ Logger.WriteLineInfo($"Connect serverUrl:{serverUrl} fail, the success times is 0");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var averageValue = totalTime / successTimes;
|
|
|
+ Logger.WriteLineInfo($"Connect serverUrl:{serverUrl},successTimes:{successTimes},spend time averageValue:{averageValue}ms");
|
|
|
+ return averageValue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ Logger.WriteLineError($"Connect Server:{serverUrl}, SpeedTest exception:{e}");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 多个服务器会报错同时用Jsonrpc会报错
|
|
|
+ /// <summary>
|
|
|
+ /// test connet server speed
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="serverUrl"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private static int OldGetConnectServerSpeed(string serverUrl, bool isUseHttps = true)
|
|
|
{
|
|
|
try
|
|
|
{
|