From 413a4e05e2c70667f9bc787b9a19fc59ec26a2aa Mon Sep 17 00:00:00 2001 From: abishek Date: Sat, 20 Sep 2025 15:09:12 +0530 Subject: [PATCH 1/2] max probe has been set to 20 --- .../Services/Monitoring/MonitoringBackgroundService.cs | 2 +- ThingConnect.Pulse.Server/appsettings.Development.json | 2 +- ThingConnect.Pulse.Server/appsettings.json | 4 ++-- ThingConnect.Pulse/probes-spec.md | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ThingConnect.Pulse.Server/Services/Monitoring/MonitoringBackgroundService.cs b/ThingConnect.Pulse.Server/Services/Monitoring/MonitoringBackgroundService.cs index bced0e8..90f62d3 100644 --- a/ThingConnect.Pulse.Server/Services/Monitoring/MonitoringBackgroundService.cs +++ b/ThingConnect.Pulse.Server/Services/Monitoring/MonitoringBackgroundService.cs @@ -25,7 +25,7 @@ public MonitoringBackgroundService(IServiceProvider serviceProvider, _logger = logger; // Read concurrency limit from configuration - _maxConcurrentProbes = configuration.GetValue("Monitoring:MaxConcurrentProbes", 100); + _maxConcurrentProbes = configuration.GetValue("Monitoring:MaxConcurrentProbes", 20); _concurrencySemaphore = new SemaphoreSlim(_maxConcurrentProbes, _maxConcurrentProbes); _logger.LogInformation("Monitoring service initialized with max concurrent probes: {MaxConcurrentProbes}", diff --git a/ThingConnect.Pulse.Server/appsettings.Development.json b/ThingConnect.Pulse.Server/appsettings.Development.json index e65f9d4..8b802b3 100644 --- a/ThingConnect.Pulse.Server/appsettings.Development.json +++ b/ThingConnect.Pulse.Server/appsettings.Development.json @@ -54,7 +54,7 @@ "ConfigPath": "C:\\ProgramData\\ThingConnect.Pulse\\config\\config.yaml", "DataRetentionDays": 60, "ProbeSettings": { - "MaxConcurrentProbes": 100, + "MaxConcurrentProbes": 20, "TimeoutMs": 5000, "RetryCount": 2, "FlapDamping": { diff --git a/ThingConnect.Pulse.Server/appsettings.json b/ThingConnect.Pulse.Server/appsettings.json index 1913b32..b7bc784 100644 --- a/ThingConnect.Pulse.Server/appsettings.json +++ b/ThingConnect.Pulse.Server/appsettings.json @@ -68,7 +68,7 @@ "ConfigPath": "C:\\ProgramData\\ThingConnect.Pulse\\config\\config.yaml", "DataRetentionDays": 60, "ProbeSettings": { - "MaxConcurrentProbes": 100, + "MaxConcurrentProbes": 20, "TimeoutMs": 5000, "RetryCount": 2, "FlapDamping": { @@ -78,6 +78,6 @@ } }, "Monitoring": { - "MaxConcurrentProbes": 100 + "MaxConcurrentProbes": 20 } } diff --git a/ThingConnect.Pulse/probes-spec.md b/ThingConnect.Pulse/probes-spec.md index e441966..36edfc6 100644 --- a/ThingConnect.Pulse/probes-spec.md +++ b/ThingConnect.Pulse/probes-spec.md @@ -214,7 +214,7 @@ public sealed class Outage ```json { "Monitoring": { - "MaxConcurrentProbes": 100 + "MaxConcurrentProbes": 20 } } ``` From 7eeaa0426949a6029d9711cce3b17468fa9ffd2d Mon Sep 17 00:00:00 2001 From: abishek Date: Sat, 20 Sep 2025 15:13:50 +0530 Subject: [PATCH 2/2] perf: optimize endpoint serivce query by applying windowStart filter in DB --- .../Services/EndpointService.cs | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/ThingConnect.Pulse.Server/Services/EndpointService.cs b/ThingConnect.Pulse.Server/Services/EndpointService.cs index 48bdd71..0a5ecc1 100644 --- a/ThingConnect.Pulse.Server/Services/EndpointService.cs +++ b/ThingConnect.Pulse.Server/Services/EndpointService.cs @@ -30,10 +30,11 @@ public EndpointService(PulseDbContext context) if (endpoint == null) return null; var windowStart = DateTimeOffset.UtcNow.AddMinutes(-windowMinutes); + var windowStartUnix = windowStart.ToUnixTimeSeconds(); // --- Fetch recent raw checks --- var rawChecks = await _context.CheckResultsRaw - .Where(c => c.EndpointId == id) + .Where(c => c.EndpointId == id && c.Ts >= windowStartUnix) .OrderByDescending(c => c.Ts) .Take(RecentFetchLimit) .ToListAsync(); @@ -46,23 +47,13 @@ public EndpointService(PulseDbContext context) RttMs = c.RttMs, Error = c.Error }) - .Where(r => r.Ts >= windowStart) - .OrderByDescending(r => r.Ts) .ToList(); - // --- Fetch outages within window --- - var outageRaw = await _context.Outages - .Where(o => o.EndpointId == id) - .ToListAsync(); - - var outages = outageRaw - .Where(o => - { - var started = ConvertToDateTimeOffset(o.StartedTs); - var ended = o.EndedTs != null ? ConvertToDateTimeOffset(o.EndedTs) : (DateTimeOffset?)null; - return started <= DateTimeOffset.UtcNow && (ended == null || ended >= windowStart); - }) - .OrderByDescending(o => ConvertToDateTimeOffset(o.StartedTs)) + var outages = await _context.Outages + .Where(o => o.EndpointId == id && + o.StartedTs <= DateTimeOffset.UtcNow.ToUnixTimeSeconds() && + (o.EndedTs == null || o.EndedTs >= windowStartUnix)) + .OrderByDescending(o => o.StartedTs) .Select(o => new OutageDto { StartedTs = ConvertToDateTimeOffset(o.StartedTs), @@ -70,7 +61,7 @@ public EndpointService(PulseDbContext context) DurationS = NormalizeDurationToInt(o.DurationSeconds), LastError = o.LastError }) - .ToList(); + .ToListAsync(); // --- Map endpoint DTO --- var endpointDto = MapToEndpointDto(endpoint);