remove locks around metrics for testing, add back dbcontext pooling

This commit is contained in:
Stanley Dimant
2022-08-18 01:17:49 +02:00
parent 077f6f3dc4
commit 54d625e729
5 changed files with 21 additions and 21 deletions

View File

@@ -13,10 +13,10 @@ namespace MareSynchronosServer.Metrics
public void Inc(double inc = 1d) public void Inc(double inc = 1d)
{ {
lock (_c) //lock (_c)
{ //{
_c.Inc(inc); _c.Inc(inc);
} //}
} }
} }
} }

View File

@@ -13,34 +13,34 @@ public class LockedProxyGauge
public void Inc(double inc = 1d) public void Inc(double inc = 1d)
{ {
lock (_g) //lock (_g)
{ //{
_g.Inc(inc); _g.Inc(inc);
} //}
} }
public void IncTo(double incTo) public void IncTo(double incTo)
{ {
lock (_g) //lock (_g)
{ //{
_g.IncTo(incTo); _g.IncTo(incTo);
} //}
} }
public void Dec(double decBy = 1d) public void Dec(double decBy = 1d)
{ {
lock (_g) //lock (_g)
{ //{
_g.Dec(decBy); _g.Dec(decBy);
} //}
} }
public void Set(double setTo) public void Set(double setTo)
{ {
lock (_g) //lock (_g)
{ //{
_g.Set(setTo); _g.Set(setTo);
} //}
} }
public double Value => _g.Value; public double Value => _g.Value;

View File

@@ -23,7 +23,7 @@ namespace MareSynchronosServer
using (var scope = host.Services.CreateScope()) using (var scope = host.Services.CreateScope())
{ {
var services = scope.ServiceProvider; var services = scope.ServiceProvider;
var context = services.GetRequiredService<MareDbContext>(); using var context = services.GetRequiredService<MareDbContext>();
context.Database.Migrate(); context.Database.Migrate();
context.SaveChanges(); context.SaveChanges();

View File

@@ -1,4 +1,3 @@
using System;
using MareSynchronos.API; using MareSynchronos.API;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
@@ -13,7 +12,6 @@ using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http.Connections; using Microsoft.AspNetCore.Http.Connections;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using Prometheus; using Prometheus;
using WebSocketOptions = Microsoft.AspNetCore.Builder.WebSocketOptions;
using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileProviders;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using MareSynchronosServer.Discord; using MareSynchronosServer.Discord;
@@ -48,13 +46,14 @@ namespace MareSynchronosServer
services.AddSingleton<IUserIdProvider, IdBasedUserIdProvider>(); services.AddSingleton<IUserIdProvider, IdBasedUserIdProvider>();
services.AddTransient(_ => Configuration); services.AddTransient(_ => Configuration);
services.AddDbContext<MareDbContext>(options => services.AddDbContextPool<MareDbContext>(options =>
{ {
options.EnableThreadSafetyChecks(false);
options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection"), builder => options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection"), builder =>
{ {
builder.MigrationsHistoryTable("_efmigrationshistory", "public"); builder.MigrationsHistoryTable("_efmigrationshistory", "public");
}).UseSnakeCaseNamingConvention(); }).UseSnakeCaseNamingConvention();
}); }, Configuration.GetValue("DbContextPoolSize", 1024));
services.AddHostedService<CleanupService>(); services.AddHostedService<CleanupService>();
services.AddHostedService(provider => provider.GetService<SystemInfoService>()); services.AddHostedService(provider => provider.GetService<SystemInfoService>());
@@ -64,7 +63,7 @@ namespace MareSynchronosServer
{ {
options.DefaultScheme = SecretKeyAuthenticationHandler.AuthScheme; options.DefaultScheme = SecretKeyAuthenticationHandler.AuthScheme;
}) })
.AddScheme<AuthenticationSchemeOptions, SecretKeyAuthenticationHandler>(SecretKeyAuthenticationHandler.AuthScheme, options => {}); .AddScheme<AuthenticationSchemeOptions, SecretKeyAuthenticationHandler>(SecretKeyAuthenticationHandler.AuthScheme, options => { });
services.AddAuthorization(options => options.FallbackPolicy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build()); services.AddAuthorization(options => options.FallbackPolicy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build());
services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>(); services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();

View File

@@ -23,6 +23,7 @@
] ]
} }
}, },
"DbContextPoolSize": 2000,
"CdnFullUrl": "https://<url or ip to your server>/cache/", "CdnFullUrl": "https://<url or ip to your server>/cache/",
"FailedAuthForTempBan": 5, "FailedAuthForTempBan": 5,
"TempBanDurationInMinutes": 30, "TempBanDurationInMinutes": 30,