From c29d11efc1cc70e9a277a6cdc9553ba01f3fb35e Mon Sep 17 00:00:00 2001 From: amki Date: Tue, 2 Mar 2021 15:21:25 +0100 Subject: [PATCH] Improve performance and reduce memory consumption drastically --- ISPChk/Controllers/HostController.cs | 7 +++---- ISPChk/Models/PingItem.cs | 2 +- ISPChk/NetworkTest.cs | 6 +++--- ISPChk/wwwroot/index.html | 4 ---- ISPChk/wwwroot/ispchk.js | 4 ++-- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/ISPChk/Controllers/HostController.cs b/ISPChk/Controllers/HostController.cs index 01e3f32..c8013a0 100644 --- a/ISPChk/Controllers/HostController.cs +++ b/ISPChk/Controllers/HostController.cs @@ -56,11 +56,10 @@ namespace ISPChk.Controllers return NotFound(); } - var startTime = DateTimeOffset.FromUnixTimeMilliseconds(start); - var endTime = DateTimeOffset.FromUnixTimeMilliseconds(end); + var startTime = DateTimeOffset.FromUnixTimeMilliseconds(start).DateTime; + var endTime = DateTimeOffset.FromUnixTimeMilliseconds(end).DateTime; - _context.Entry(host).Collection(h => h.PingItems).Load(); - var pis = host.PingItems.Where(p => p.Date > startTime).ToList(); + var pis = _context.Entry(host).Collection(h => h.PingItems).Query().Where(p => p.Date > startTime).ToList(); return pis; } diff --git a/ISPChk/Models/PingItem.cs b/ISPChk/Models/PingItem.cs index 0265af4..e27acbd 100644 --- a/ISPChk/Models/PingItem.cs +++ b/ISPChk/Models/PingItem.cs @@ -10,7 +10,7 @@ namespace ISPChk.Models { [Key] public long PingId { get; set; } - public DateTimeOffset Date { get; set; } + public DateTime Date { get; set; } public float Min { get; set; } public float Max { get; set; } public float Avg { get; set; } diff --git a/ISPChk/NetworkTest.cs b/ISPChk/NetworkTest.cs index 69c2327..0d5d41a 100644 --- a/ISPChk/NetworkTest.cs +++ b/ISPChk/NetworkTest.cs @@ -23,7 +23,7 @@ namespace ISPChk public async void LoadHostsFromDatabase() { - List hosts = await _context.Hosts.Include(host => host.PingItems).ToListAsync(); + List hosts = await _context.Hosts.ToListAsync(); foreach (Host host in hosts) { AddHost(host); @@ -47,7 +47,7 @@ namespace ISPChk // Do not use the outer context, not threadsafe? var ctx = CreateDbContext(); var h = await ctx.Hosts.FindAsync(host.HostId); - ctx.Entry(h).Collection(hst => hst.PingItems).Load(); + ctx.Entry(h).Collection(hst => hst.PingItems).Query().FirstOrDefault(); IPAddress pingAddress; @@ -139,7 +139,7 @@ namespace ISPChk if (min > timeout) min = 0; System.Diagnostics.Debug.WriteLine(h.HostName+": "+"min:" + min + " max:" + max + " avg:" + avg); - PingItem pi = new PingItem { Date = DateTimeOffset.UtcNow, Min = min, Max = max, Avg = avg, Failures = failures }; + PingItem pi = new PingItem { Date = DateTimeOffset.UtcNow.DateTime, Min = min, Max = max, Avg = avg, Failures = failures }; h.PingItems.Add(pi); ctx.SaveChanges(); // Throttle if everything is ok diff --git a/ISPChk/wwwroot/index.html b/ISPChk/wwwroot/index.html index c095a0e..f38e9a5 100644 --- a/ISPChk/wwwroot/index.html +++ b/ISPChk/wwwroot/index.html @@ -67,14 +67,10 @@
-
-
-
-
diff --git a/ISPChk/wwwroot/ispchk.js b/ISPChk/wwwroot/ispchk.js index 1d82360..ad0cc62 100644 --- a/ISPChk/wwwroot/ispchk.js +++ b/ISPChk/wwwroot/ispchk.js @@ -128,8 +128,8 @@ async function updateGraphs() { }, { label: 'fail', - type: 'bar', - backgroundColor: 'rgba(0, 0, 0, 0.6)', + //type: 'bar', + backgroundColor: 'rgba(0, 0, 0, 0.3)', borderColor: 'rgb(0, 0, 0)', yAxisID: "y-loss", data: val.failures