Browse Source

refine HA

tags/2.5
clowwindy 10 years ago
parent
commit
008e3544f2
2 changed files with 7 additions and 2 deletions
  1. +1
    -1
      shadowsocks-csharp/Controller/Service/TCPRelay.cs
  2. +6
    -1
      shadowsocks-csharp/Controller/Strategy/HighAvailabilityStrategy.cs

+ 1
- 1
shadowsocks-csharp/Controller/Service/TCPRelay.cs View File

@@ -383,7 +383,7 @@ namespace Shadowsocks.Controller
{ {
if (retryCount < 4) if (retryCount < 4)
{ {
Console.WriteLine("Connection failed, retrying");
Logging.Debug("Connection failed, retrying");
StartConnect(); StartConnect();
retryCount++; retryCount++;
} }


+ 6
- 1
shadowsocks-csharp/Controller/Strategy/HighAvailabilityStrategy.cs View File

@@ -90,6 +90,7 @@ namespace Shadowsocks.Controller.Strategy
*/ */
public void ChooseNewServer() public void ChooseNewServer()
{ {
Server oldServer = _currentServer;
List<ServerStatus> servers = new List<ServerStatus>(_serverStatus.Values); List<ServerStatus> servers = new List<ServerStatus>(_serverStatus.Values);
DateTime now = DateTime.Now; DateTime now = DateTime.Now;
foreach (var status in servers) foreach (var status in servers)
@@ -98,7 +99,7 @@ namespace Shadowsocks.Controller.Strategy
// 100 * failure - 2 * latency - 0.5 * (lastread - lastwrite) // 100 * failure - 2 * latency - 0.5 * (lastread - lastwrite)
status.score = status.score =
100 * 1000 * Math.Min(5 * 60, (now - status.lastFailure).TotalSeconds) 100 * 1000 * Math.Min(5 * 60, (now - status.lastFailure).TotalSeconds)
-2 * 5 * (Math.Min(2000, status.latency.TotalMilliseconds) / (1 + (now - status.lastTimeDetectLatency).TotalSeconds / 30 / 2) +
-2 * 5 * (Math.Min(2000, status.latency.TotalMilliseconds) / (1 + (now - status.lastTimeDetectLatency).TotalSeconds / 30 / 10) +
-0.5 * 200 * Math.Min(5, (status.lastRead - status.lastWrite).TotalSeconds)); -0.5 * 200 * Math.Min(5, (status.lastRead - status.lastWrite).TotalSeconds));
Logging.Debug(String.Format("server: {0} latency:{1} score: {2}", status.server.FriendlyName(), status.latency, status.score)); Logging.Debug(String.Format("server: {0} latency:{1} score: {2}", status.server.FriendlyName(), status.latency, status.score));
} }
@@ -120,6 +121,10 @@ namespace Shadowsocks.Controller.Strategy
if (max != null) if (max != null)
{ {
_currentServer = max.server; _currentServer = max.server;
if (_currentServer != oldServer)
{
Console.WriteLine("HA switching to server: {0}", _currentServer.FriendlyName());
}
Logging.Debug(String.Format("choosing server: {0}", _currentServer.FriendlyName())); Logging.Debug(String.Format("choosing server: {0}", _currentServer.FriendlyName()));
} }
} }


Loading…
Cancel
Save