update conf route x calcolo min/max statistiche

This commit is contained in:
Samuele Locatelli
2026-04-07 11:26:32 +02:00
parent 45cb6b9f59
commit 0c6e2f5c99
3 changed files with 22 additions and 10 deletions
+10 -9
View File
@@ -72,21 +72,22 @@ namespace MP.IOC.Services
var taskZAddHour = batch.SortedSetAddAsync(hoursIndex, hourKey, hourScore);
var taskZAddDay = batch.SortedSetAddAsync(daysIndex, dayKey, dayScore);
// Optionally set TTL on bucket hashes (e.g., keep daily buckets 400 days)
var taskExpireHour = batch.KeyExpireAsync(hourKey, TimeSpan.FromDays(11)); // keep ~11 days for hourly
var taskExpireDay = batch.KeyExpireAsync(dayKey, TimeSpan.FromDays(400)); // keep ~400 days for daily
//// Optionally set TTL on bucket hashes (e.g., keep daily buckets 400 days)
//var taskExpireHour = batch.KeyExpireAsync(hourKey, TimeSpan.FromDays(11)); // keep ~11 days for hourly
//var taskExpireDay = batch.KeyExpireAsync(dayKey, TimeSpan.FromDays(400)); // keep ~400 days for daily
// Execute batch
batch.Execute();
// Await tasks to ensure completion
await Task.WhenAll(taskHourCount, taskHourTotal, taskDayCount, taskDayTotal,
taskZAddHour, taskZAddDay, taskExpireHour, taskExpireDay);
await Task.WhenAll(taskHourCount, taskHourTotal, taskDayCount, taskDayTotal, taskZAddHour, taskZAddDay);
//await Task.WhenAll(taskHourCount, taskHourTotal, taskDayCount, taskDayTotal,
// taskZAddHour, taskZAddDay, taskExpireHour, taskExpireDay);
// Trim indices to keep only last N entries (use ZREMRANGEBYRANK)
// Note: trimming is separate calls (not in batch) to ensure ordering; can be batched too.
await _db.SortedSetRemoveRangeByRankAsync(hoursIndex, 0, -MaxHourlyBuckets - 1); // keep last MaxHourlyBuckets
await _db.SortedSetRemoveRangeByRankAsync(daysIndex, 0, -MaxDailyBuckets - 1);
//// Trim indices to keep only last N entries (use ZREMRANGEBYRANK)
//// Note: trimming is separate calls (not in batch) to ensure ordering; can be batched too.
//await _db.SortedSetRemoveRangeByRankAsync(hoursIndex, 0, -MaxHourlyBuckets - 1); // keep last MaxHourlyBuckets
//await _db.SortedSetRemoveRangeByRankAsync(daysIndex, 0, -MaxDailyBuckets - 1);
}
_stats.Clear();
+1 -1
View File
@@ -81,7 +81,7 @@ namespace MP.IOC.Services
var (oldW, newW) = _weightProvider.GetWeightsFor(metodo);
var pickNew = DecideByWeights(oldW, newW);
var target = pickNew ? "new" : "old";
var target = pickNew ? "IOC" : "IO";
// Costruisci destination base in base al target
var destBase = pickNew
+11
View File
@@ -8,6 +8,8 @@ namespace MP.IOC.Services
{
public long Count;
public TimeSpan TotalDuration = TimeSpan.Zero;
public TimeSpan MaxDuration = TimeSpan.Zero;
public TimeSpan MinDuration = TimeSpan.MaxValue;
public ConcurrentDictionary<string, long> Destinations = new();
public ConcurrentDictionary<int, long> StatusCodes = new();
}
@@ -30,6 +32,15 @@ namespace MP.IOC.Services
lock (stat)
{
stat.TotalDuration += duration;
// aggiorno valori min/max se necessario
if (stat.MaxDuration < duration)
{
stat.MaxDuration = duration;
}
if (stat.MinDuration > duration)
{
stat.MinDuration = duration;
}
}
}
}