From e68d1c48d2c9545a1d542c88ef2f5d7b854616dd Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 4 Jun 2020 19:24:49 +0000 Subject: [PATCH] --- .vscode/launch.json | 2 +- devdocs/tools.txt | 12 ++++++- .../Controllers/ServerMetricsController.cs | 20 +++++++++++ server/AyaNova/Startup.cs | 33 ++++++++++--------- .../AyaNova/util/ServiceProviderProvider.cs | 6 +++- 5 files changed, 54 insertions(+), 19 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index f994e0f9..379d2046 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -49,7 +49,7 @@ "AYANOVA_USE_URLS": "http://*:7575;", "AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles", "AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles", - "AYANOVA_SERVER_TEST_MODE":"true", + "AYANOVA_SERVER_TEST_MODE":"false", "AYANOVA_SERVER_TEST_MODE_SEEDLEVEL":"small", "AYANOVA_SERVER_TEST_MODE_TZ_OFFSET":"-7", "AYANOVA_BACKUP_PG_DUMP_PATH":"C:\\data\\code\\PostgreSQLPortable_12.0\\App\\PgSQL\\bin\\" diff --git a/devdocs/tools.txt b/devdocs/tools.txt index e6775261..ab3a3517 100644 --- a/devdocs/tools.txt +++ b/devdocs/tools.txt @@ -728,4 +728,14 @@ JAVASCRIPT DOWNSAMPLING TOOL // if(ministats.Count>0){ // var v=ministats.Count; // } - // } \ No newline at end of file + // } + +MEMORY LEAK DIAGNOSIS URLS +https://docs.microsoft.com/en-us/dotnet/core/diagnostics/debug-memory-leak +https://docs.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-counters +https://docs.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-dump +https://docs.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-trace + +Might be doing GC Counts incorrectly, they don't sync up with the dotnet-counters tool which shows them drop back to zero regularly when I stop burn test +https://michaelscodingspot.com/ways-to-cause-memory-leaks-in-dotnet/ +https://bennettadelson.wordpress.com/2013/04/11/using-perfview-to-diagnose-a-net-memory-leak-2/ diff --git a/server/AyaNova/Controllers/ServerMetricsController.cs b/server/AyaNova/Controllers/ServerMetricsController.cs index ba2cba0c..c2401b7a 100644 --- a/server/AyaNova/Controllers/ServerMetricsController.cs +++ b/server/AyaNova/Controllers/ServerMetricsController.cs @@ -51,6 +51,7 @@ namespace AyaNova.Api.Controllers #if (DEBUG) [HttpGet("collect")] + [AllowAnonymous] public ActionResult GetCollect() { GC.Collect(); @@ -59,6 +60,25 @@ namespace AyaNova.Api.Controllers return Ok(); } + + + [HttpGet("hammer")] + [AllowAnonymous] + public async Task GetHammer() + { + //test allocation and cleanup + for (int x = 0; x < 100000; x++) + { + AyContext ct = AyaNova.Util.ServiceProviderProvider.DBContext; + var v=await ct.Widget.Where(z=>z.Serial<100).ToListAsync(); + // int i = await ct.Database.ExecuteSqlRawAsync($"select * from aglobalbizsettings"); + } + + return Ok(); + } + + + #endif /// diff --git a/server/AyaNova/Startup.cs b/server/AyaNova/Startup.cs index 63c80126..e01f4a7b 100644 --- a/server/AyaNova/Startup.cs +++ b/server/AyaNova/Startup.cs @@ -49,21 +49,22 @@ namespace AyaNova { _newLog.LogDebug("Initializing services..."); - _newLog.LogDebug("Profiler"); - //https://dotnetthoughts.net/using-miniprofiler-in-aspnetcore-webapi/ - services.AddMemoryCache(); - services.AddMiniProfiler(options => - { - options.RouteBasePath = "/profiler"; - //in testing only ignorepaths was reliable and worked and docs say it prevents any profiling at all - options.IgnorePath("/auth").IgnorePath("/user").IgnorePath("/docs"); - options.ResultsAuthorize = request => - { - if (request.HttpContext.Items["AY_PROFILER_ALLOWED"] != null) - return true; - return false; - }; - }).AddEntityFramework(); + // _newLog.LogDebug("Profiler"); + // //https://dotnetthoughts.net/using-miniprofiler-in-aspnetcore-webapi/ + // services.AddMemoryCache(); + // services.AddMiniProfiler(options => + // { + // options.RouteBasePath = "/profiler"; + // //in testing only ignorepaths was reliable and worked and docs say it prevents any profiling at all + // options.IgnorePath("/auth").IgnorePath("/user").IgnorePath("/docs"); + // options.ResultsAuthorize = request => + // { + // if (request.HttpContext.Items["AY_PROFILER_ALLOWED"] != null) + // return true; + // return false; + // }; + // //options.ShouldProfile = request => false; + // }).AddEntityFramework(); //Server state service for shutting people out of api @@ -473,7 +474,7 @@ namespace AyaNova _newLog.LogDebug("Profiler"); - app.UseMiniProfiler(); + // app.UseMiniProfiler(); diff --git a/server/AyaNova/util/ServiceProviderProvider.cs b/server/AyaNova/util/ServiceProviderProvider.cs index 81b36767..6691cc00 100644 --- a/server/AyaNova/util/ServiceProviderProvider.cs +++ b/server/AyaNova/util/ServiceProviderProvider.cs @@ -28,6 +28,10 @@ namespace AyaNova.Util { get { + // System.Diagnostics.Debug.WriteLine((new System.Diagnostics.StackTrace()).GetFrame(1).GetMethod().Name); + + // System.Diagnostics.Debug.WriteLine((new System.Diagnostics.StackTrace()).ToString().Substring(56,80)); + return Scope.ServiceProvider.GetRequiredService(); } } @@ -39,7 +43,7 @@ namespace AyaNova.Util return Scope.ServiceProvider.GetRequiredService(); } } - + // https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-3.1 internal static System.Net.Http.IHttpClientFactory HttpClientFactory {