Browse Source

Improve performance and reduce memory consumption drastically

master
amki 4 years ago
parent
commit
c29d11efc1
  1. 7
      ISPChk/Controllers/HostController.cs
  2. 2
      ISPChk/Models/PingItem.cs
  3. 6
      ISPChk/NetworkTest.cs
  4. 4
      ISPChk/wwwroot/index.html
  5. 4
      ISPChk/wwwroot/ispchk.js

7
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;
}

2
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; }

6
ISPChk/NetworkTest.cs

@ -23,7 +23,7 @@ namespace ISPChk
public async void LoadHostsFromDatabase()
{
List<Host> hosts = await _context.Hosts.Include(host => host.PingItems).ToListAsync();
List<Host> 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

4
ISPChk/wwwroot/index.html

@ -67,14 +67,10 @@
</div>
</div>
<div class="row">
<div class="col-sm">
</div>
<div class="col-sm">
<div id="chartContainerButtons">
</div>
</div>
<div class="col-sm">
</div>
</div>
<div id="chartContainer" class="row">

4
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

Loading…
Cancel
Save