diff --git a/src/SlimFaas/HistorySynchronizationWorker.cs b/src/SlimFaas/HistorySynchronizationWorker.cs index 9680881b..0012296d 100644 --- a/src/SlimFaas/HistorySynchronizationWorker.cs +++ b/src/SlimFaas/HistorySynchronizationWorker.cs @@ -29,12 +29,12 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) long ticksMemory = historyHttpMemoryService.GetTicksLastCall(function.Deployment); if (ticksInDatabase > ticksMemory) { - logger.LogInformation("HistorySynchronizationWorker: Synchronizing history for {Function} to {Ticks} from Database", function.Deployment, ticksInDatabase); + logger.LogDebug("HistorySynchronizationWorker: Synchronizing history for {Function} to {Ticks} from Database", function.Deployment, ticksInDatabase); historyHttpMemoryService.SetTickLastCall(function.Deployment, ticksInDatabase); } else if (ticksInDatabase < ticksMemory) { - logger.LogInformation("HistorySynchronizationWorker: Synchronizing history for {Function} to {Ticks} from Memory", function.Deployment, ticksMemory); + logger.LogDebug("HistorySynchronizationWorker: Synchronizing history for {Function} to {Ticks} from Memory", function.Deployment, ticksMemory); await historyHttpDatabaseService.SetTickLastCallAsync(function.Deployment, ticksMemory); } } diff --git a/src/SlimFaas/ReplicasService.cs b/src/SlimFaas/ReplicasService.cs index 8ce4562e..306df9e8 100644 --- a/src/SlimFaas/ReplicasService.cs +++ b/src/SlimFaas/ReplicasService.cs @@ -111,7 +111,7 @@ public async Task CheckScaleAsync(string kubeNamespace) } var lastTicksFromSchedule = GetLastTicksFromSchedule(deploymentInformation, DateTime.UtcNow); - if (lastTicksFromSchedule > tickLastCall) + if (lastTicksFromSchedule.HasValue && lastTicksFromSchedule > tickLastCall) { tickLastCall = lastTicksFromSchedule.Value; } @@ -126,9 +126,19 @@ public async Task CheckScaleAsync(string kubeNamespace) tickLastCall = ticksLastCall[information.Deployment]; } - bool timeElapsedWithoutRequest = TimeSpan.FromTicks(tickLastCall) + - TimeSpan.FromSeconds(GetTimeoutSecondBeforeSetReplicasMin(deploymentInformation, DateTime.UtcNow)) < - TimeSpan.FromTicks(DateTime.UtcNow.Ticks); + var timeToWaitSeconds = TimeSpan.FromSeconds(GetTimeoutSecondBeforeSetReplicasMin(deploymentInformation, DateTime.UtcNow)); + bool timeElapsedWithoutRequest = (TimeSpan.FromTicks(tickLastCall) + + timeToWaitSeconds) < TimeSpan.FromTicks(DateTime.UtcNow.Ticks); + + if (logger.IsEnabled(LogLevel.Debug)) + { + var time = (TimeSpan.FromTicks(tickLastCall) + + timeToWaitSeconds) - + TimeSpan.FromTicks(DateTime.UtcNow.Ticks); + logger.LogDebug( + "Time left without request for scale down {Deployment} is {TimeElapsedWithoutRequest}", + deploymentInformation.Deployment, time); + } int currentScale = deploymentInformation.Replicas; if (timeElapsedWithoutRequest) {