diff --git a/Resources/ChangeLog.html b/Resources/ChangeLog.html
index 80d693e..d261092 100644
--- a/Resources/ChangeLog.html
+++ b/Resources/ChangeLog.html
@@ -1,6 +1,6 @@
WebDoorCreator - Egalware
- Version: 0.9.2402.1608
+ Version: 0.9.2402.1614
Release note:
-
diff --git a/Resources/VersNum.txt b/Resources/VersNum.txt
index ba310ea..952da24 100644
--- a/Resources/VersNum.txt
+++ b/Resources/VersNum.txt
@@ -1 +1 @@
-0.9.2402.1608
+0.9.2402.1614
diff --git a/Resources/manifest.xml b/Resources/manifest.xml
index 084df61..95a5db5 100644
--- a/Resources/manifest.xml
+++ b/Resources/manifest.xml
@@ -1,7 +1,7 @@
-
- 0.9.2402.1608
- http://nexus.steamware.net/repository/SWS/WDC/stable/WDC.UI.zip
+ 0.9.2402.1614
+ http://nexus.steamware.net/repository/SWS/WDC/stable/WDC.API.zip
http://nexus.steamware.net/repository/SWS/WDC/stable/ChangeLog.html
false
diff --git a/WebDoorCreator.API/Controllers/QueueController.cs b/WebDoorCreator.API/Controllers/QueueController.cs
index b134baa..f2436f7 100644
--- a/WebDoorCreator.API/Controllers/QueueController.cs
+++ b/WebDoorCreator.API/Controllers/QueueController.cs
@@ -1,5 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using NLog;
+using System.Diagnostics;
+using WebDoorCreator.Core;
using WebDoorCreator.Data.DTO;
using WebDoorCreator.Data.Services;
@@ -13,11 +15,12 @@ namespace WebDoorCreator.API.Controllers
public QueueController(IConfiguration configuration, QueueDataService DataService, WebDoorCreatorService _WDService)
{
- Log.Info("Starting QueueController");
+ Log.Trace("Starting QueueController");
_configuration = configuration;
+ logTimingEnable = configuration.GetValue("RuntimeOpt:LogTimingEnable");
QDataServ = DataService;
WDService = _WDService;
- Log.Info("Avviato QueueController");
+ Log.Trace("Avviato QueueController");
}
#endregion Public Constructors
@@ -133,6 +136,7 @@ namespace WebDoorCreator.API.Controllers
string answ = "NA";
bool fatto = await QDataServ.SaveProcessingResult(calcResults);
answ = fatto ? "OK" : "NO";
+ Log.Debug("Eseguito SaveProcResult");
return answ;
}
@@ -143,6 +147,11 @@ namespace WebDoorCreator.API.Controllers
[HttpGet("StatusList")]
public async Task>> StatusList()
{
+ Stopwatch sw = new Stopwatch();
+ if (logTimingEnable)
+ {
+ sw.Start();
+ }
Dictionary> answ = new Dictionary>();
var actPend = await QDataServ.RequestPending();
answ.Add("pending", actPend);
@@ -155,6 +164,20 @@ namespace WebDoorCreator.API.Controllers
var actDone = await QDataServ.RequestDone();
answ.Add("done", actDone);
+ if (logTimingEnable)
+ {
+ sw.Stop();
+ // aggiungo..
+ string statName = "StatusList";
+ bool doWrite = await QDataServ.StatUpsert(statName, sw.Elapsed);
+ // se campione "pieno"...
+ if (doWrite)
+ {
+ // recupero e resetto
+ ExecStats statRec = await QDataServ.StatReset(statName);
+ Log.Info($"Eseguito {statName} | call: {statRec.NumCall} | {statRec.AvgTime.TotalMilliseconds:N3}ms");
+ }
+ }
return answ;
}
@@ -168,6 +191,7 @@ namespace WebDoorCreator.API.Controllers
public async Task> TakeProcessingItems(int numItems = 10)
{
var actQueue = await QDataServ.TakeProcessingItems(numItems);
+ Log.Debug($"Eseguito TakeProcessingItems per {numItems} items");
return actQueue;
}
@@ -175,9 +199,10 @@ namespace WebDoorCreator.API.Controllers
#region Private Fields
- private static IConfiguration _configuration = null!;
-
private static Logger Log = LogManager.GetCurrentClassLogger();
+ private IConfiguration _configuration = null!;
+
+ private bool logTimingEnable = false;
#endregion Private Fields
diff --git a/WebDoorCreator.API/appsettings.json b/WebDoorCreator.API/appsettings.json
index c8c6b84..36b1131 100644
--- a/WebDoorCreator.API/appsettings.json
+++ b/WebDoorCreator.API/appsettings.json
@@ -28,6 +28,8 @@
"TimbCheck": "samuele.locatelli@egalware.com"
},
"RuntimeOpt": {
- "VetoRemoveProcessing": 5
+ "VetoRemoveProcessing": 5,
+ "StatSampleSize": 30,
+ "LogTimingEnable": true
}
}
diff --git a/WebDoorCreator.Core/Constants.cs b/WebDoorCreator.Core/Constants.cs
index 1474f4a..2bf93d3 100644
--- a/WebDoorCreator.Core/Constants.cs
+++ b/WebDoorCreator.Core/Constants.cs
@@ -27,7 +27,9 @@ namespace WebDoorCreator.Core
public static readonly string CALC_REQ_DDF_CACHE = $"{BASE_HASH}:CalcRequests:CacheDDF";
public static readonly string CALC_REQ_SVG_CACHE = $"{BASE_HASH}:CalcRequests:CacheSVG";
public static readonly string DOOR_TPL_LIST = $"{BASE_HASH}:Template:DoorList";
-
+
+ // REDIS KEY dati x registrazione statistiche esecuzione
+ public static readonly string STATS_DATA = $"{BASE_HASH}:CallStats";
// REDIS Channels messaggi x QueueMan (verso UI/srv)
public static readonly string CALC_REQ_QUEUE = $"CalcRequest";
diff --git a/WebDoorCreator.Core/ExecStats.cs b/WebDoorCreator.Core/ExecStats.cs
new file mode 100644
index 0000000..3f8b961
--- /dev/null
+++ b/WebDoorCreator.Core/ExecStats.cs
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WebDoorCreator.Core
+{
+ public class ExecStats
+ {
+
+ ///
+ /// Numero chiamate registrate
+ ///
+ public int NumCall { get; set; } = 0;
+
+ ///
+ /// Durata totale chiamate
+ ///
+ public TimeSpan TotalTime { get; set; } = new TimeSpan(0, 0, 0);
+
+ ///
+ /// Tempo medio (calcolato)
+ ///
+ [NotMapped]
+ public TimeSpan AvgTime
+ {
+ get
+ {
+ TimeSpan answ = TotalTime;
+ if (NumCall > 1)
+ {
+ answ = TotalTime / NumCall;
+ }
+ return answ;
+ }
+ }
+ ///
+ /// Init classe
+ ///
+ ///
+ ///
+ public ExecStats(int numCall, TimeSpan duration)
+ {
+ this.NumCall = numCall;
+ this.TotalTime = duration;
+ }
+ }
+}
diff --git a/WebDoorCreator.Data/Services/QueueDataService.cs b/WebDoorCreator.Data/Services/QueueDataService.cs
index d8d586f..10348a3 100644
--- a/WebDoorCreator.Data/Services/QueueDataService.cs
+++ b/WebDoorCreator.Data/Services/QueueDataService.cs
@@ -2,6 +2,7 @@
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using NLog;
+using NLog.LayoutRenderers.Wrappers;
using StackExchange.Redis;
using System.Diagnostics;
using WebDoorCreator.Core;
@@ -45,6 +46,8 @@ namespace WebDoorCreator.Data.Services
};
// leggo conf speciali
vetoRemoveProcSec = _configuration.GetValue("RuntimeOpt:VetoRemoveProcessing");
+ logTimingEnable = configuration.GetValue("RuntimeOpt:LogTimingEnable");
+ statSampleSize = configuration.GetValue("RuntimeOpt:StatSampleSize");
Log.Info("QueueDataService started!");
}
@@ -182,7 +185,8 @@ namespace WebDoorCreator.Data.Services
// se non trovata --> missing!
if (string.IsNullOrEmpty(answ))
{
- // 2024.02.15: se mancasse, provo a richiedere ricalcolo porta... se poi arriva, la pagina in ascolto l'avrà aggiornata
+ // 2024.02.15: se mancasse, provo a richiedere ricalcolo porta... se poi arriva, la
+ // pagina in ascolto l'avrà aggiornata
// leggo missing standard...
string missingFilePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images", "MissingOrange.svg");
@@ -211,13 +215,15 @@ namespace WebDoorCreator.Data.Services
/// Dictionary of DoorId, saveVersNumb
public async Task> DoorRefreshStatus()
{
- string source = "REDIS";
long numReq = 0;
Dictionary dictResult = new Dictionary();
// cerco da cache
RedisKey currKey = new RedisKey(Constants.LAST_DOOR_REFR_KEY);
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
+ Stopwatch sw = new Stopwatch();
+ if (logTimingEnable)
+ {
+ sw.Start();
+ }
numReq = redisDb.HashLength(currKey);
if (numReq > 0)
{
@@ -227,9 +233,12 @@ namespace WebDoorCreator.Data.Services
dictResult.Add($"{item.Name}", $"{item.Value}");
}
}
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"DoorRefreshStatus | {source} in: {ts.TotalMilliseconds} ms");
+ if (logTimingEnable)
+ {
+ sw.Stop();
+ // gestione statistiche
+ await ProcStatLog("DoorRefreshStatus", sw.Elapsed, 1);
+ }
return dictResult;
}
@@ -306,12 +315,18 @@ namespace WebDoorCreator.Data.Services
Dictionary dictResult = new Dictionary();
// cerco da cache
RedisKey currKey = new RedisKey(Constants.CALC_REQ_DONE);
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
+ Stopwatch sw = new Stopwatch();
+ if (logTimingEnable)
+ {
+ sw.Start();
+ }
numReq = await redisDb.HashLengthAsync(currKey);
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"NumRequestDone | {source} in: {ts.TotalMilliseconds} ms");
+ if (logTimingEnable)
+ {
+ sw.Stop();
+ // gestione statistiche
+ await ProcStatLog("NumRequestDone", sw.Elapsed, 1);
+ }
return numReq;
}
@@ -325,12 +340,18 @@ namespace WebDoorCreator.Data.Services
Dictionary dictResult = new Dictionary();
// cerco da cache
RedisKey currKey = new RedisKey(Constants.CALC_REQ_ERRS);
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
+ Stopwatch sw = new Stopwatch();
+ if (logTimingEnable)
+ {
+ sw.Start();
+ }
numReq = await redisDb.HashLengthAsync(currKey);
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"NumRequestErrors | {source} in: {ts.TotalMilliseconds} ms");
+ if (logTimingEnable)
+ {
+ sw.Stop();
+ // gestione statistiche
+ await ProcStatLog("NumRequestErrors", sw.Elapsed, 1);
+ }
return numReq;
}
@@ -344,12 +365,18 @@ namespace WebDoorCreator.Data.Services
Dictionary dictResult = new Dictionary();
// cerco da cache
RedisKey currKey = new RedisKey(Constants.CALC_REQ_PEND);
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
+ Stopwatch sw = new Stopwatch();
+ if (logTimingEnable)
+ {
+ sw.Start();
+ }
numReq = await redisDb.HashLengthAsync(currKey);
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"NumRequestPending | {source} in: {ts.TotalMilliseconds} ms");
+ if (logTimingEnable)
+ {
+ sw.Stop();
+ // gestione statistiche
+ await ProcStatLog("NumRequestPending", sw.Elapsed, 1);
+ }
return numReq;
}
@@ -363,12 +390,18 @@ namespace WebDoorCreator.Data.Services
Dictionary dictResult = new Dictionary();
// cerco da cache
RedisKey currKey = new RedisKey(Constants.CALC_REQ_PROC);
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
+ Stopwatch sw = new Stopwatch();
+ if (logTimingEnable)
+ {
+ sw.Start();
+ }
numReq = await redisDb.HashLengthAsync(currKey);
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"NumRequestProcessing | {source} in: {ts.TotalMilliseconds} ms");
+ if (logTimingEnable)
+ {
+ sw.Stop();
+ // gestione statistiche
+ await ProcStatLog("NumRequestProcessing", sw.Elapsed, 1);
+ }
return numReq;
}
@@ -381,8 +414,11 @@ namespace WebDoorCreator.Data.Services
public async Task RedHashGetInt(RedisKey currKey, string chiave)
{
int result = 0;
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
+ Stopwatch sw = new Stopwatch();
+ if (logTimingEnable)
+ {
+ sw.Start();
+ }
var hasVal = await redisDb.HashExistsAsync(currKey, chiave);
if (hasVal)
{
@@ -392,9 +428,12 @@ namespace WebDoorCreator.Data.Services
int.TryParse($"{rawRes}", out result);
}
}
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Trace($"RedHashGetInt | {currKey} | in: {ts.TotalMilliseconds} ms");
+ if (logTimingEnable)
+ {
+ sw.Stop();
+ // gestione statistiche
+ await ProcStatLog("RedHashGetInt", sw.Elapsed, 0);
+ }
return result;
}
@@ -407,8 +446,11 @@ namespace WebDoorCreator.Data.Services
public async Task RedHashGetString(RedisKey currKey, string chiave)
{
string result = "";
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
+ Stopwatch sw = new Stopwatch();
+ if (logTimingEnable)
+ {
+ sw.Start();
+ }
var hasVal = await redisDb.HashExistsAsync(currKey, chiave);
if (hasVal)
{
@@ -418,9 +460,12 @@ namespace WebDoorCreator.Data.Services
result = $"{rawRes}";
}
}
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Trace($"RedHashGetString | {currKey} | in: {ts.TotalMilliseconds} ms");
+ if (logTimingEnable)
+ {
+ sw.Stop();
+ // gestione statistiche
+ await ProcStatLog("RedHashGetString", sw.Elapsed, 0);
+ }
return result;
}
@@ -433,12 +478,18 @@ namespace WebDoorCreator.Data.Services
public async Task RedHashRemove(RedisKey currKey, string chiave)
{
bool fatto = false;
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
+ Stopwatch sw = new Stopwatch();
+ if (logTimingEnable)
+ {
+ sw.Start();
+ }
fatto = await redisDb.HashDeleteAsync(currKey, chiave);
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Trace($"RedHashRemove | {currKey} | in: {ts.TotalMilliseconds} ms");
+ if (logTimingEnable)
+ {
+ sw.Stop();
+ // gestione statistiche
+ await ProcStatLog("RedHashRemove", sw.Elapsed, 0);
+ }
return fatto;
}
@@ -464,13 +515,15 @@ namespace WebDoorCreator.Data.Services
/// Dictionary of DoorId, saveVersNumb
public async Task> RequestDone()
{
- string source = "REDIS";
long numReq = 0;
Dictionary dictResult = new Dictionary();
// cerco da cache
RedisKey currKey = new RedisKey(Constants.CALC_REQ_DONE);
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
+ Stopwatch sw = new Stopwatch();
+ if (logTimingEnable)
+ {
+ sw.Start();
+ }
numReq = redisDb.HashLength(currKey);
if (numReq > 0)
{
@@ -480,9 +533,12 @@ namespace WebDoorCreator.Data.Services
dictResult.Add($"{item.Name}", $"{item.Value}");
}
}
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"RequestDone | {source} in: {ts.TotalMilliseconds} ms");
+ if (logTimingEnable)
+ {
+ sw.Stop();
+ // gestione statistiche
+ await ProcStatLog("RequestDone", sw.Elapsed, 1);
+ }
return dictResult;
}
@@ -493,13 +549,15 @@ namespace WebDoorCreator.Data.Services
///
public async Task> RequestDoneGetSingle(int DoorId)
{
- string source = "REDIS";
long numReq = 0;
Dictionary dictResult = new Dictionary();
// cerco da cache
RedisKey currKey = new RedisKey(Constants.CALC_REQ_DONE);
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
+ Stopwatch sw = new Stopwatch();
+ if (logTimingEnable)
+ {
+ sw.Start();
+ }
numReq = redisDb.HashLength(currKey);
if (numReq > 0)
{
@@ -509,9 +567,12 @@ namespace WebDoorCreator.Data.Services
dictResult.Add($"{DoorId}", $"{rawData}");
}
}
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"RequestDoneGetSingle | {source} in: {ts.TotalMilliseconds} ms");
+ if (logTimingEnable)
+ {
+ sw.Stop();
+ // gestione statistiche
+ await ProcStatLog("RequestDoneGetSingle", sw.Elapsed, 1);
+ }
return dictResult;
}
@@ -543,13 +604,15 @@ namespace WebDoorCreator.Data.Services
/// Dictionary of DoorId, saveVersNumb
public async Task> RequestErr()
{
- string source = "REDIS";
long numReq = 0;
Dictionary dictResult = new Dictionary();
// cerco da cache
RedisKey currKey = new RedisKey(Constants.CALC_REQ_ERRS);
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
+ Stopwatch sw = new Stopwatch();
+ if (logTimingEnable)
+ {
+ sw.Start();
+ }
numReq = redisDb.HashLength(currKey);
if (numReq > 0)
{
@@ -559,9 +622,12 @@ namespace WebDoorCreator.Data.Services
dictResult.Add($"{item.Name}", $"{item.Value}");
}
}
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"RequestErr | {source} in: {ts.TotalMilliseconds} ms");
+ if (logTimingEnable)
+ {
+ sw.Stop();
+ // gestione statistiche
+ await ProcStatLog("RequestErr", sw.Elapsed, 1);
+ }
return dictResult;
}
@@ -593,13 +659,15 @@ namespace WebDoorCreator.Data.Services
/// Dictionary of DoorId, saveVersNumb
public async Task> RequestPending()
{
- string source = "REDIS";
long numReq = 0;
Dictionary dictResult = new Dictionary();
// cerco da cache
RedisKey currKey = new RedisKey(Constants.CALC_REQ_PEND);
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
+ Stopwatch sw = new Stopwatch();
+ if (logTimingEnable)
+ {
+ sw.Start();
+ }
numReq = redisDb.HashLength(currKey);
if (numReq > 0)
{
@@ -609,9 +677,12 @@ namespace WebDoorCreator.Data.Services
dictResult.Add($"{item.Name}", $"{item.Value}");
}
}
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"RequestPending | {source} in: {ts.TotalMilliseconds} ms");
+ if (logTimingEnable)
+ {
+ sw.Stop();
+ // gestione statistiche
+ await ProcStatLog("RequestPending", sw.Elapsed, 1);
+ }
return dictResult;
}
@@ -643,13 +714,15 @@ namespace WebDoorCreator.Data.Services
/// Dictionary of DoorId, saveVersNumb
public async Task> RequestProcessing()
{
- string source = "REDIS";
long numReq = 0;
Dictionary dictResult = new Dictionary();
// cerco da cache
RedisKey currKey = new RedisKey(Constants.CALC_REQ_PROC);
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
+ Stopwatch sw = new Stopwatch();
+ if (logTimingEnable)
+ {
+ sw.Start();
+ }
numReq = redisDb.HashLength(currKey);
if (numReq > 0)
{
@@ -659,9 +732,12 @@ namespace WebDoorCreator.Data.Services
dictResult.Add($"{item.Name}", $"{item.Value}");
}
}
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"RequestProcessing | {source} in: {ts.TotalMilliseconds} ms");
+ if (logTimingEnable)
+ {
+ sw.Stop();
+ // gestione statistiche
+ await ProcStatLog("RequestProcessing", sw.Elapsed, 1);
+ }
return dictResult;
}
@@ -697,9 +773,11 @@ namespace WebDoorCreator.Data.Services
public async Task ResetQueue()
{
bool fatto = false;
- await Task.Delay(1);
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
+ Stopwatch sw = new Stopwatch();
+ if (logTimingEnable)
+ {
+ sw.Start();
+ }
// cerco le richieste processing
RedisKey currKey = new RedisKey(Constants.CALC_REQ_PROC);
var rawData = await redisDb.HashGetAllAsync(currKey);
@@ -727,9 +805,12 @@ namespace WebDoorCreator.Data.Services
await RequestDoneRemove(item.Name!);
fatto = true;
}
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"ResetQueue | REDIS EXEC in: {ts.TotalMilliseconds} ms");
+ if (logTimingEnable)
+ {
+ sw.Stop();
+ // gestione statistiche
+ await ProcStatLog("ResetQueue", sw.Elapsed, 1);
+ }
return fatto;
}
@@ -741,8 +822,11 @@ namespace WebDoorCreator.Data.Services
{
int num2proc = DoorIdList.Count;
List listDone = new List();
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
+ Stopwatch sw = new Stopwatch();
+ if (logTimingEnable)
+ {
+ sw.Start();
+ }
// cerco le richieste processing
RedisKey currKey = new RedisKey(Constants.CALC_REQ_PROC);
var rawData = await redisDb.HashGetAllAsync(currKey);
@@ -789,9 +873,11 @@ namespace WebDoorCreator.Data.Services
DoorIdList.Remove(item);
}
#endif
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"ResetQueueByDoorList | doors #: {num2proc} --> {DoorIdList.Count} | EXEC in: {ts.TotalMilliseconds} ms");
+ if (logTimingEnable)
+ {
+ sw.Stop();
+ Log.Debug($"ResetQueueByDoorList | doors #: {num2proc} --> {DoorIdList.Count} | EXEC in: {sw.Elapsed.TotalMilliseconds} ms");
+ }
return DoorIdList;
}
@@ -803,8 +889,11 @@ namespace WebDoorCreator.Data.Services
{
bool fatto = false;
await Task.Delay(1);
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
+ Stopwatch sw = new Stopwatch();
+ if (logTimingEnable)
+ {
+ sw.Start();
+ }
// cerco le richieste processing
RedisKey currKey = new RedisKey(Constants.CALC_REQ_PROC);
RedisKey currVetoKey = new RedisKey($"{Constants.CALC_REQ_PROC}:0");
@@ -821,9 +910,12 @@ namespace WebDoorCreator.Data.Services
fatto = true;
}
}
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"ResetQueueProcessing | REDIS EXEC in: {ts.TotalMilliseconds} ms");
+ if (logTimingEnable)
+ {
+ sw.Stop();
+ // gestione statistiche
+ await ProcStatLog("ResetQueueProcessing", sw.Elapsed, 1);
+ }
return fatto;
}
@@ -907,8 +999,11 @@ namespace WebDoorCreator.Data.Services
/// indice/versione del calcolo DDF
public async Task SendCalcReq(int DoorId, string FullDDF)
{
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
+ Stopwatch sw = new Stopwatch();
+ if (logTimingEnable)
+ {
+ sw.Start();
+ }
string sDoorId = $"{DoorId}";
int currVers = await DoorCalcRev(sDoorId);
string sCurrVers = $"{currVers}";
@@ -924,12 +1019,84 @@ namespace WebDoorCreator.Data.Services
long numPending = await NumRequestPending();
bool answ = CalcReqPipe.saveAndSendMessage(Constants.LAST_CALC_REQ_KEY, $"{numPending}");
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"SendCalcReq | DoorId: {DoorId} enqueued in: {ts.TotalMilliseconds} ms");
+ if (logTimingEnable)
+ {
+ sw.Stop();
+ Log.Debug($"SendCalcReq | DoorId: {DoorId} enqueued in: {sw.Elapsed.TotalMilliseconds} ms");
+ }
return currVers;
}
+ ///
+ /// Restituisce dati statistica richiesta
+ ///
+ /// Nome statistica
+ ///
+ public async Task StatGetAsync(string statName)
+ {
+ ExecStats answ = new ExecStats(0, new TimeSpan());
+ RedisKey currKey = new RedisKey(Constants.STATS_DATA);
+ // cerco nella hashTable...
+ var rawData = await RedHashGetString(currKey, statName);
+ // se c'è rileggo ed aggiorno
+ if (!string.IsNullOrEmpty(rawData))
+ {
+ var currStat = JsonConvert.DeserializeObject(rawData);
+ if (currStat != null)
+ {
+ answ = currStat;
+ }
+ }
+ return answ;
+ }
+
+ ///
+ /// Resetta dati statistica esecuzione x log restituendo i valori precedentemente contenuti
+ ///
+ /// Nome statistica
+ ///
+ public async Task StatReset(string statName)
+ {
+ RedisKey currKey = new RedisKey(Constants.STATS_DATA);
+ ExecStats answ = await StatGetAsync(statName);
+ // ora rimuovo valore
+ await RedHashRemove(currKey, statName);
+ return answ;
+ }
+
+ ///
+ /// Effettua upsert dati statistica esecuzione x log
+ ///
+ /// Nome statistica
+ /// Durata esecuzione come timespan
+ ///
+ public async Task StatUpsert(string statName, TimeSpan duration)
+ {
+ bool answ = false;
+ RedisKey currKey = new RedisKey(Constants.STATS_DATA);
+ // cerco nella hashTable...
+ var rawData = await RedHashGetString(currKey, statName);
+ // di default inizializzo a null...
+ ExecStats newStat = new ExecStats(1, duration);
+ // se c'è rileggo ed aggiorno
+ if (!string.IsNullOrEmpty(rawData))
+ {
+ var currStat = JsonConvert.DeserializeObject(rawData);
+ if (currStat != null)
+ {
+ currStat.NumCall++;
+ currStat.TotalTime += duration;
+ newStat = currStat;
+ }
+ }
+ // ora aggiorno su redis
+ rawData = JsonConvert.SerializeObject(newStat);
+ var numRec = await RedHashUpsert(currKey, statName, rawData);
+ // verifico se da considerare superato limite sample
+ answ = newStat.NumCall >= statSampleSize;
+ return answ;
+ }
+
///
/// Get Queue request pending, removing from queue and putting on processing queue
///
@@ -941,8 +1108,11 @@ namespace WebDoorCreator.Data.Services
Dictionary dictResult = new Dictionary();
// cerco da cache
RedisKey currKey = new RedisKey(Constants.CALC_REQ_PEND);
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
+ Stopwatch sw = new Stopwatch();
+ if (logTimingEnable)
+ {
+ sw.Start();
+ }
// calcolo il totale delle richieste pending
numReq = redisDb.HashLength(currKey);
if (numReq > 0)
@@ -974,9 +1144,12 @@ namespace WebDoorCreator.Data.Services
// sblocco
queueLock = false;
}
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"TakeProcessingItems | REDIS in: {ts.TotalMilliseconds} ms");
+ if (logTimingEnable)
+ {
+ sw.Stop();
+ // gestione statistiche
+ await ProcStatLog("TakeProcessingItems", sw.Elapsed, 1);
+ }
return dictResult;
}
@@ -985,7 +1158,9 @@ namespace WebDoorCreator.Data.Services
#region Protected Fields
protected const string rKeyCalcOreFase = "Check:OreFasi";
+
protected const string rKeyFasiAct = "Check:FasiAct";
+
protected const string rKeyProjAct = "Check:ProjAct";
///
@@ -994,6 +1169,7 @@ namespace WebDoorCreator.Data.Services
protected const int shortTTL = 60 * 5;
protected int idxSim = 0;
+
protected Random rnd = new Random();
#endregion Protected Fields
@@ -1099,13 +1275,19 @@ namespace WebDoorCreator.Data.Services
protected async Task RedHashUpsert(RedisKey currKey, string chiave, string valore)
{
long numReq = 0;
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
+ Stopwatch sw = new Stopwatch();
+ if (logTimingEnable)
+ {
+ sw.Start();
+ }
await redisDb.HashSetAsync(currKey, chiave, valore);
numReq = await redisDb.HashLengthAsync(currKey);
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Trace($"RedHashUpsert | {currKey} | in: {ts.TotalMilliseconds} ms");
+ if (logTimingEnable)
+ {
+ sw.Stop();
+ // gestione statistiche
+ await ProcStatLog("RedHashUpsert", sw.Elapsed, 0);
+ }
return numReq;
}
@@ -1119,8 +1301,7 @@ namespace WebDoorCreator.Data.Services
protected async Task setRSV(string rKey, string rVal, int ttlSec)
{
bool fatto = false;
- await redisDb.StringSetAsync(rKey, rVal, TimeSpan.FromSeconds(ttlSec));
- fatto = true;
+ fatto = await redisDb.StringSetAsync(rKey, rVal, TimeSpan.FromSeconds(ttlSec));
return fatto;
}
@@ -1134,8 +1315,7 @@ namespace WebDoorCreator.Data.Services
protected async Task setRSV(string rKey, int rValInt, int ttlSec)
{
bool fatto = false;
- await redisDb.StringSetAsync(rKey, rValInt, TimeSpan.FromSeconds(ttlSec));
- fatto = true;
+ fatto = await redisDb.StringSetAsync(rKey, rValInt, TimeSpan.FromSeconds(ttlSec));
return fatto;
}
@@ -1156,8 +1336,16 @@ namespace WebDoorCreator.Data.Services
#region Private Fields
private static IConfiguration _configuration = null!;
+
private static JsonSerializerSettings? JSSettings;
+
private static Logger Log = LogManager.GetCurrentClassLogger();
+
+ ///
+ /// Dimensione campione da registrare e trascrivere in log
+ ///
+ private static int statSampleSize = 1;
+
private readonly IEmailSender _emailSender;
///
@@ -1175,6 +1363,11 @@ namespace WebDoorCreator.Data.Services
///
private int cacheTtlShort = 60 * 1;
+ ///
+ /// abilitazione time log con stopwatch
+ ///
+ private bool logTimingEnable = false;
+
///
/// Oggetto per connessione a REDIS
///
@@ -1197,6 +1390,14 @@ namespace WebDoorCreator.Data.Services
get => TimeSpan.FromHours(24);
}
+ ///
+ /// Durata cache di 2 settimane/15gg
+ ///
+ private TimeSpan DblWeekLongCache
+ {
+ get => TimeSpan.FromHours(24 * 15 * rnd.Next(1000, 1100) / 1000);
+ }
+
///
/// Durata cache lunga (+ perturbazione percentuale +/-10%)
///
@@ -1238,13 +1439,6 @@ namespace WebDoorCreator.Data.Services
{
get => TimeSpan.FromHours(24 * 7 * rnd.Next(1000, 1100) / 1000);
}
- ///
- /// Durata cache di 2 settimane/15gg
- ///
- private TimeSpan DblWeekLongCache
- {
- get => TimeSpan.FromHours(24 * 15 * rnd.Next(1000, 1100) / 1000);
- }
#endregion Private Properties
@@ -1279,6 +1473,59 @@ namespace WebDoorCreator.Data.Services
return answ;
}
+ ///
+ /// Processa log statistiche:
+ /// - accumula dati
+ /// - se superata soglia registra log
+ ///
+ ///
+ ///
+ ///
+ /// livello richiesto: 0:trace, 1:debug, 2:info, 3:warn, 4:error, 5: fatal, 6: off
+ ///
+ ///
+ private async Task ProcStatLog(string statName, TimeSpan elapsed, int logLevReq)
+ {
+ bool doWrite = await StatUpsert(statName, elapsed);
+ if (doWrite)
+ {
+ // recupero e resetto
+ ExecStats statRec = await StatReset(statName);
+ string logMsg = $"Eseguito {statName} | call: {statRec.NumCall} | {statRec.AvgTime.TotalMilliseconds:N3}ms";
+ switch (logLevReq)
+ {
+ case 0:
+ Log.Trace(logMsg);
+ break;
+
+ case 1:
+ Log.Debug(logMsg);
+ break;
+
+ case 2:
+ Log.Info(logMsg);
+ break;
+
+ case 3:
+ Log.Warn(logMsg);
+ break;
+
+ case 4:
+ Log.Error(logMsg);
+ break;
+
+ case 5:
+ Log.Fatal(logMsg);
+ break;
+
+ case 6:
+ default:
+ Log.Error(logMsg);
+ break;
+ }
+ }
+ }
+
#endregion Private Methods
}
}
\ No newline at end of file
diff --git a/WebDoorCreator.UI/WebDoorCreator.UI.csproj b/WebDoorCreator.UI/WebDoorCreator.UI.csproj
index 7375eac..ce64ce4 100644
--- a/WebDoorCreator.UI/WebDoorCreator.UI.csproj
+++ b/WebDoorCreator.UI/WebDoorCreator.UI.csproj
@@ -3,7 +3,7 @@
net6.0
enable
- 0.9.2402.1608
+ 0.9.2402.1614
enable
aspnet-WebDoorCreator.UI-dfe95fed-1398-4144-bd43-8b3a765d6608
diff --git a/WebDoorCreator.UI/appsettings.Production.json b/WebDoorCreator.UI/appsettings.Production.json
index 84c77b9..4947734 100644
--- a/WebDoorCreator.UI/appsettings.Production.json
+++ b/WebDoorCreator.UI/appsettings.Production.json
@@ -9,19 +9,13 @@
"RuntimeOpt": {
"MaxDayCalcCache": 7,
"BaseUrl": "/UI"
- //"BaseUrl": "/WDC/UI",
},
"ConnectionStrings": {
"Redis": "wdc-u-redis-01.ovh:6379, DefaultDatabase=12, connectTimeout=5000, syncTimeout=5000, asyncTimeout=5000, abortConnect=false, ssl=false, password=BtN9Py1wtLfLRvmzWnOPJ7RytDM+CLiVsJ/16zduNTlV8IOPGNrtzJSXPUnImA5PqmUMhKaUqo9NdHIG",
"Identity.DB": "Server=WDC-W-SQL-01\\SQLEXPRESS;Database=DCA_WebDoorCreator; User ID=steamware;Password=viadante16; integrated security=False; MultipleActiveResultSets=True; App=WebDoorCreator.UI;",
"WDC.DB": "Server=WDC-W-SQL-01\\SQLEXPRESS;Database=DCA_WebDoorCreator; User ID=steamware;Password=viadante16; integrated security=False; MultipleActiveResultSets=True; App=WebDoorCreator.UI;"
- //"Redis": "nkcredis.steamware.net:6379, DefaultDatabase=12, connectTimeout=5000, syncTimeout=5000, asyncTimeout=5000, abortConnect=false, ssl=false, password=BtN9Py1wtLfLRvmzWnOPJ7RytDM+CLiVsJ/16zduNTlV8IOPGNrtzJSXPUnImA5PqmUMhKaUqo9NdHIG",
- //"Identity.DB": "Server=SQL2016PROD;Database=DCA_WebDoorCreator; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=WebDoorCreator.UI;",
- //"WDC.DB": "Server=SQL2016PROD;Database=DCA_WebDoorCreator; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=WebDoorCreator.UI;"
},
"CompoBaseDirs": {
- //"CurrCompoDir": "J:\\WebDoorSync\\CurrentComp\\Compo",
- //"NewCompoDir": "J:\\WebDoorSync\\NewComp\\Compo",
"CurrCompoDir": "U:\\WebDoorSync\\CurrentComp\\Compo",
"NewCompoDir": "U:\\WebDoorSync\\NewComp\\Compo"
}
diff --git a/WebDoorCreator.UI/appsettings.json b/WebDoorCreator.UI/appsettings.json
index d55caed..8896543 100644
--- a/WebDoorCreator.UI/appsettings.json
+++ b/WebDoorCreator.UI/appsettings.json
@@ -53,5 +53,7 @@
"CompoBaseDirs": {
"CurrCompoDir": "\\\\IIS04\\WebDoorSync\\CurrentComp\\Compo",
"NewCompoDir": "\\\\IIS04\\WebDoorSync\\NewComp\\Compo"
+ //"CurrCompoDir": "J:\\WebDoorSync\\CurrentComp\\Compo",
+ //"NewCompoDir": "J:\\WebDoorSync\\NewComp\\Compo"
}
}
\ No newline at end of file