Redis Cluster prep
This commit is contained in:
@@ -165,19 +165,22 @@ public class Startup
|
|||||||
|
|
||||||
var options = ConfigurationOptions.Parse(redisConnection);
|
var options = ConfigurationOptions.Parse(redisConnection);
|
||||||
|
|
||||||
var endpoint = options.EndPoints[0];
|
var hosts = options.EndPoints
|
||||||
string address = "";
|
.Select(ep =>
|
||||||
int port = 0;
|
{
|
||||||
if (endpoint is DnsEndPoint dnsEndPoint) { address = dnsEndPoint.Host; port = dnsEndPoint.Port; }
|
if (ep is DnsEndPoint dns) return (host: dns.Host, port: dns.Port);
|
||||||
if (endpoint is IPEndPoint ipEndPoint) { address = ipEndPoint.Address.ToString(); port = ipEndPoint.Port; }
|
if (ep is IPEndPoint ip) return (host: ip.Address.ToString(), port: ip.Port);
|
||||||
|
return (host: (string?)null, port: 0);
|
||||||
|
})
|
||||||
|
.Where(x => x.host != null)
|
||||||
|
.Distinct()
|
||||||
|
.Select(x => new RedisHost { Host = x.host!, Port = x.port })
|
||||||
|
.ToArray();
|
||||||
var redisConfiguration = new RedisConfiguration()
|
var redisConfiguration = new RedisConfiguration()
|
||||||
{
|
{
|
||||||
AbortOnConnectFail = true,
|
AbortOnConnectFail = false,
|
||||||
KeyPrefix = "",
|
KeyPrefix = "",
|
||||||
Hosts = new RedisHost[]
|
Hosts = hosts,
|
||||||
{
|
|
||||||
new RedisHost(){ Host = address, Port = port },
|
|
||||||
},
|
|
||||||
AllowAdmin = true,
|
AllowAdmin = true,
|
||||||
ConnectTimeout = options.ConnectTimeout,
|
ConnectTimeout = options.ConnectTimeout,
|
||||||
Database = 0,
|
Database = 0,
|
||||||
@@ -187,11 +190,11 @@ public class Startup
|
|||||||
{
|
{
|
||||||
Mode = ServerEnumerationStrategy.ModeOptions.All,
|
Mode = ServerEnumerationStrategy.ModeOptions.All,
|
||||||
TargetRole = ServerEnumerationStrategy.TargetRoleOptions.Any,
|
TargetRole = ServerEnumerationStrategy.TargetRoleOptions.Any,
|
||||||
UnreachableServerAction = ServerEnumerationStrategy.UnreachableServerActionOptions.Throw,
|
UnreachableServerAction = ServerEnumerationStrategy.UnreachableServerActionOptions.IgnoreIfOtherAvailable,
|
||||||
},
|
},
|
||||||
MaxValueLength = 1024,
|
MaxValueLength = 1024,
|
||||||
PoolSize = mareConfig.GetValue(nameof(ServerConfiguration.RedisPool), 50),
|
PoolSize = mareConfig.GetValue(nameof(ServerConfiguration.RedisPool), 50),
|
||||||
SyncTimeout = options.SyncTimeout,
|
SyncTimeout = Math.Max(options.SyncTimeout, 10000),
|
||||||
};
|
};
|
||||||
|
|
||||||
services.AddStackExchangeRedisExtensions<SystemTextJsonSerializer>(redisConfiguration);
|
services.AddStackExchangeRedisExtensions<SystemTextJsonSerializer>(redisConfiguration);
|
||||||
|
@@ -7,6 +7,7 @@ using MareSynchronosShared.Services;
|
|||||||
using MareSynchronosShared.Utils.Configuration;
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using StackExchange.Redis;
|
||||||
using StackExchange.Redis.Extensions.Core.Abstractions;
|
using StackExchange.Redis.Extensions.Core.Abstractions;
|
||||||
|
|
||||||
namespace MareSynchronosServer.Services;
|
namespace MareSynchronosServer.Services;
|
||||||
@@ -19,11 +20,12 @@ public class SystemInfoService : IHostedService, IDisposable
|
|||||||
private readonly ILogger<SystemInfoService> _logger;
|
private readonly ILogger<SystemInfoService> _logger;
|
||||||
private readonly IHubContext<MareHub, IMareHub> _hubContext;
|
private readonly IHubContext<MareHub, IMareHub> _hubContext;
|
||||||
private readonly IRedisDatabase _redis;
|
private readonly IRedisDatabase _redis;
|
||||||
|
private readonly IConnectionMultiplexer _connectionMultiplexer;
|
||||||
private Timer _timer;
|
private Timer _timer;
|
||||||
public SystemInfoDto SystemInfoDto { get; private set; } = new();
|
public SystemInfoDto SystemInfoDto { get; private set; } = new();
|
||||||
|
|
||||||
public SystemInfoService(MareMetrics mareMetrics, IConfigurationService<ServerConfiguration> configurationService, IServiceProvider services,
|
public SystemInfoService(MareMetrics mareMetrics, IConfigurationService<ServerConfiguration> configurationService, IServiceProvider services,
|
||||||
ILogger<SystemInfoService> logger, IHubContext<MareHub, IMareHub> hubContext, IRedisDatabase redisDb)
|
ILogger<SystemInfoService> logger, IHubContext<MareHub, IMareHub> hubContext, IRedisDatabase redisDb, IConnectionMultiplexer connectionMultiplexer)
|
||||||
{
|
{
|
||||||
_mareMetrics = mareMetrics;
|
_mareMetrics = mareMetrics;
|
||||||
_config = configurationService;
|
_config = configurationService;
|
||||||
@@ -31,6 +33,7 @@ public class SystemInfoService : IHostedService, IDisposable
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
_hubContext = hubContext;
|
_hubContext = hubContext;
|
||||||
_redis = redisDb;
|
_redis = redisDb;
|
||||||
|
_connectionMultiplexer = connectionMultiplexer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task StartAsync(CancellationToken cancellationToken)
|
public Task StartAsync(CancellationToken cancellationToken)
|
||||||
@@ -52,8 +55,9 @@ public class SystemInfoService : IHostedService, IDisposable
|
|||||||
|
|
||||||
_mareMetrics.SetGaugeTo(MetricsAPI.GaugeAvailableWorkerThreads, workerThreads);
|
_mareMetrics.SetGaugeTo(MetricsAPI.GaugeAvailableWorkerThreads, workerThreads);
|
||||||
_mareMetrics.SetGaugeTo(MetricsAPI.GaugeAvailableIOWorkerThreads, ioThreads);
|
_mareMetrics.SetGaugeTo(MetricsAPI.GaugeAvailableIOWorkerThreads, ioThreads);
|
||||||
|
var onlineUsers = _connectionMultiplexer.GetServers().Where(server => !server.IsReplica).SelectMany(server => server.Keys(0, "UID:*", pageSize:1000)).Count();
|
||||||
|
|
||||||
|
|
||||||
var onlineUsers = (_redis.SearchKeysAsync("UID:*").GetAwaiter().GetResult()).Count();
|
|
||||||
SystemInfoDto = new SystemInfoDto()
|
SystemInfoDto = new SystemInfoDto()
|
||||||
{
|
{
|
||||||
OnlineUsers = onlineUsers,
|
OnlineUsers = onlineUsers,
|
||||||
|
@@ -142,19 +142,22 @@ public class Startup
|
|||||||
|
|
||||||
var options = ConfigurationOptions.Parse(redisConnection);
|
var options = ConfigurationOptions.Parse(redisConnection);
|
||||||
|
|
||||||
var endpoint = options.EndPoints[0];
|
var hosts = options.EndPoints
|
||||||
string address = "";
|
.Select(ep =>
|
||||||
int port = 0;
|
{
|
||||||
if (endpoint is DnsEndPoint dnsEndPoint) { address = dnsEndPoint.Host; port = dnsEndPoint.Port; }
|
if (ep is DnsEndPoint dns) return (host: dns.Host, port: dns.Port);
|
||||||
if (endpoint is IPEndPoint ipEndPoint) { address = ipEndPoint.Address.ToString(); port = ipEndPoint.Port; }
|
if (ep is IPEndPoint ip) return (host: ip.Address.ToString(), port: ip.Port);
|
||||||
|
return (host: (string?)null, port: 0);
|
||||||
|
})
|
||||||
|
.Where(x => x.host != null)
|
||||||
|
.Distinct()
|
||||||
|
.Select(x => new RedisHost { Host = x.host!, Port = x.port })
|
||||||
|
.ToArray();
|
||||||
var redisConfiguration = new RedisConfiguration()
|
var redisConfiguration = new RedisConfiguration()
|
||||||
{
|
{
|
||||||
AbortOnConnectFail = true,
|
AbortOnConnectFail = false,
|
||||||
KeyPrefix = "",
|
KeyPrefix = "",
|
||||||
Hosts = new RedisHost[]
|
Hosts = hosts,
|
||||||
{
|
|
||||||
new RedisHost(){ Host = address, Port = port },
|
|
||||||
},
|
|
||||||
AllowAdmin = true,
|
AllowAdmin = true,
|
||||||
ConnectTimeout = options.ConnectTimeout,
|
ConnectTimeout = options.ConnectTimeout,
|
||||||
Database = 0,
|
Database = 0,
|
||||||
@@ -164,11 +167,11 @@ public class Startup
|
|||||||
{
|
{
|
||||||
Mode = ServerEnumerationStrategy.ModeOptions.All,
|
Mode = ServerEnumerationStrategy.ModeOptions.All,
|
||||||
TargetRole = ServerEnumerationStrategy.TargetRoleOptions.Any,
|
TargetRole = ServerEnumerationStrategy.TargetRoleOptions.Any,
|
||||||
UnreachableServerAction = ServerEnumerationStrategy.UnreachableServerActionOptions.Throw,
|
UnreachableServerAction = ServerEnumerationStrategy.UnreachableServerActionOptions.IgnoreIfOtherAvailable,
|
||||||
},
|
},
|
||||||
MaxValueLength = 1024,
|
MaxValueLength = 1024,
|
||||||
PoolSize = mareConfig.GetValue(nameof(ServerConfiguration.RedisPool), 50),
|
PoolSize = mareConfig.GetValue(nameof(ServerConfiguration.RedisPool), 50),
|
||||||
SyncTimeout = options.SyncTimeout,
|
SyncTimeout = Math.Max(options.SyncTimeout, 10000),
|
||||||
};
|
};
|
||||||
|
|
||||||
services.AddStackExchangeRedisExtensions<SystemTextJsonSerializer>(redisConfiguration);
|
services.AddStackExchangeRedisExtensions<SystemTextJsonSerializer>(redisConfiguration);
|
||||||
|
@@ -142,19 +142,22 @@ public class Startup
|
|||||||
|
|
||||||
var options = ConfigurationOptions.Parse(redisConnection);
|
var options = ConfigurationOptions.Parse(redisConnection);
|
||||||
|
|
||||||
var endpoint = options.EndPoints[0];
|
var hosts = options.EndPoints
|
||||||
string address = "";
|
.Select(ep =>
|
||||||
int port = 0;
|
{
|
||||||
if (endpoint is DnsEndPoint dnsEndPoint) { address = dnsEndPoint.Host; port = dnsEndPoint.Port; }
|
if (ep is DnsEndPoint dns) return (host: dns.Host, port: dns.Port);
|
||||||
if (endpoint is IPEndPoint ipEndPoint) { address = ipEndPoint.Address.ToString(); port = ipEndPoint.Port; }
|
if (ep is IPEndPoint ip) return (host: ip.Address.ToString(), port: ip.Port);
|
||||||
|
return (host: (string?)null, port: 0);
|
||||||
|
})
|
||||||
|
.Where(x => x.host != null)
|
||||||
|
.Distinct()
|
||||||
|
.Select(x => new RedisHost { Host = x.host!, Port = x.port })
|
||||||
|
.ToArray();
|
||||||
var redisConfiguration = new RedisConfiguration()
|
var redisConfiguration = new RedisConfiguration()
|
||||||
{
|
{
|
||||||
AbortOnConnectFail = true,
|
AbortOnConnectFail = false,
|
||||||
KeyPrefix = "",
|
KeyPrefix = "",
|
||||||
Hosts = new RedisHost[]
|
Hosts = hosts,
|
||||||
{
|
|
||||||
new RedisHost(){ Host = address, Port = port },
|
|
||||||
},
|
|
||||||
AllowAdmin = true,
|
AllowAdmin = true,
|
||||||
ConnectTimeout = options.ConnectTimeout,
|
ConnectTimeout = options.ConnectTimeout,
|
||||||
Database = 0,
|
Database = 0,
|
||||||
@@ -164,11 +167,11 @@ public class Startup
|
|||||||
{
|
{
|
||||||
Mode = ServerEnumerationStrategy.ModeOptions.All,
|
Mode = ServerEnumerationStrategy.ModeOptions.All,
|
||||||
TargetRole = ServerEnumerationStrategy.TargetRoleOptions.Any,
|
TargetRole = ServerEnumerationStrategy.TargetRoleOptions.Any,
|
||||||
UnreachableServerAction = ServerEnumerationStrategy.UnreachableServerActionOptions.Throw,
|
UnreachableServerAction = ServerEnumerationStrategy.UnreachableServerActionOptions.IgnoreIfOtherAvailable,
|
||||||
},
|
},
|
||||||
MaxValueLength = 1024,
|
MaxValueLength = 1024,
|
||||||
PoolSize = mareConfig.GetValue(nameof(ServerConfiguration.RedisPool), 50),
|
PoolSize = mareConfig.GetValue(nameof(ServerConfiguration.RedisPool), 50),
|
||||||
SyncTimeout = options.SyncTimeout,
|
SyncTimeout = Math.Max(options.SyncTimeout, 10000),
|
||||||
};
|
};
|
||||||
|
|
||||||
services.AddStackExchangeRedisExtensions<SystemTextJsonSerializer>(redisConfiguration);
|
services.AddStackExchangeRedisExtensions<SystemTextJsonSerializer>(redisConfiguration);
|
||||||
|
Reference in New Issue
Block a user