Improve performance and reduce memory consumption drastically
This commit is contained in:
		
							parent
							
								
									6d75e6a381
								
							
						
					
					
						commit
						c29d11efc1
					
				| @ -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; | ||||
|         } | ||||
|  | ||||
| @ -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; } | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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"> | ||||
|              | ||||
|  | ||||
| @ -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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user