From 53a8f88aca8dcd2a330c8cc5d6aafe9b7debe140 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 16 Jul 2025 09:21:47 +0200 Subject: [PATCH] MTC: esclusione track dati raw x problemi performances (da indagare jetco 3024...) --- IOB-WIN-FORM/IOB-WIN-FORM.csproj | 6 +++ IOB-WIN-FORM/Iob/Generic.Protected.cs | 68 +++++++++++++++++++++++---- IOB-WIN-FORM/app.config | 2 +- IOB-WIN-FORM/packages.config | 2 + IOB-WIN-MTC/DATA/CONF/MAIN.ini | 4 +- IOB-WIN-MTC/Iob/MTConn.cs | 9 +++- 6 files changed, 76 insertions(+), 15 deletions(-) diff --git a/IOB-WIN-FORM/IOB-WIN-FORM.csproj b/IOB-WIN-FORM/IOB-WIN-FORM.csproj index d8ebf9a6..0e370c50 100644 --- a/IOB-WIN-FORM/IOB-WIN-FORM.csproj +++ b/IOB-WIN-FORM/IOB-WIN-FORM.csproj @@ -86,6 +86,12 @@ ..\packages\System.Runtime.CompilerServices.Unsafe.6.1.0\lib\net462\System.Runtime.CompilerServices.Unsafe.dll + + ..\packages\System.Text.Encodings.Web.8.0.0\lib\net462\System.Text.Encodings.Web.dll + + + ..\packages\System.Text.Json.8.0.6\lib\net462\System.Text.Json.dll + ..\packages\System.Threading.Tasks.Extensions.4.6.0\lib\net462\System.Threading.Tasks.Extensions.dll diff --git a/IOB-WIN-FORM/Iob/Generic.Protected.cs b/IOB-WIN-FORM/Iob/Generic.Protected.cs index aa026999..b1e5584c 100644 --- a/IOB-WIN-FORM/Iob/Generic.Protected.cs +++ b/IOB-WIN-FORM/Iob/Generic.Protected.cs @@ -3,6 +3,7 @@ using IOB_UT_NEXT; using MapoSDK; using Newtonsoft.Json; using NLog; +using NLog.Targets; using System; using System.Collections; using System.Collections.Generic; @@ -13,6 +14,9 @@ using System.Linq; using System.Net; using System.Net.NetworkInformation; using System.Reflection; +using System.Runtime.Serialization.Formatters.Binary; +using System.Text.Json; +using System.Text.Json.Serialization; using System.Threading; using System.Windows.Forms; using System.Xml.Serialization; @@ -3177,7 +3181,7 @@ namespace IOB_WIN_FORM.Iob Assembly entryAssembly = Assembly.GetEntryAssembly(); if (IOBConfFull != null) { - // creo obj dati necessari... + // creo genObj dati necessari... currDict.Add("IobName", IOBConfFull.General.FilenameIOB); currDict.Add("IobType", $"{IOBConfFull.General.IobType}"); currDict.Add("MachIp", IOBConfFull.Device.Connect.IpAddr); @@ -3394,7 +3398,7 @@ namespace IOB_WIN_FORM.Iob LastTSVC.Add(item.Key, 0); } } - // infine se obj memoria valido salvo in MP-IO x sue applicazioni + // infine se genObj memoria valido salvo in MP-IO x sue applicazioni if (memMap != null) { // invio su cloud conf memoria... @@ -3656,17 +3660,61 @@ namespace IOB_WIN_FORM.Iob { try { - // salvo indicazione valore ricevuto - string rawVal = JsonConvert.SerializeObject(genObj); +#if false + long byteSize = GetObjectSize(genObj, false); // salvo dim caratteri ricevuti - trackExchData(rawVal.Length, val2rec); + trackExchData(byteSize, val2rec); +#endif } catch (Exception exc) { - lgError($"trackExchDataRaw | errore in fase di track obj ricevuto{Environment.NewLine}{exc}"); + lgError($"trackExchDataRaw | errore in fase di track Obj ricevuto{Environment.NewLine}{exc}"); } } + protected static long GetObjectSize(object genObj, bool isSerializable) + { + long result = 0; + if (isSerializable) + { + using (var stream = new MemoryStream()) + { + + var formatter = new BinaryFormatter(); + formatter.Serialize(stream, genObj); + result = stream.Length; + } + } + else + { + // salvo indicazione valore ricevuto +#if false + string rawVal = JsonConvert.SerializeObject(genObj, JSSettings); +#endif + string rawVal = System.Text.Json.JsonSerializer.Serialize(genObj, options); + result = rawVal.Length; + } + return result; + } + + /// + /// Gestione loop da evitare x serializzazioni + /// + private static readonly JsonSerializerSettings JSSettings = new JsonSerializerSettings() + { + Formatting = Formatting.None, + NullValueHandling = NullValueHandling.Ignore, + DefaultValueHandling = DefaultValueHandling.Ignore, + //ContractResolver = new DefaultContractResolver(), + ReferenceLoopHandling = ReferenceLoopHandling.Ignore + }; + + private static readonly JsonSerializerOptions options = new JsonSerializerOptions + { + ReferenceHandler = ReferenceHandler.IgnoreCycles, + WriteIndented = false // Optional: set to true for pretty-printing + }; + /// /// Traccia in redis l'attività di lettura dati /// @@ -3883,7 +3931,7 @@ namespace IOB_WIN_FORM.Iob // invio un blocco <= maxSendPzCountBlock if (delta > minSendPzCountBlock) { - // init obj display + // init genObj display newDisplayData currDispData = new newDisplayData(); // resta indietro di ALMENO minSendPzCountBlock pezzi x recuperare 1:1... numIncr = delta > maxSendPzCountBlock + minSendPzCountBlock ? maxSendPzCountBlock : delta - minSendPzCountBlock; @@ -3945,7 +3993,7 @@ namespace IOB_WIN_FORM.Iob /// protected void trySendValues() { - // init obj display + // init genObj display newDisplayData currDispData = new newDisplayData(); try { @@ -4800,7 +4848,7 @@ namespace IOB_WIN_FORM.Iob // verifico se sia abilitato processing... if (queueInEnabCurr) { - // init obj display + // init genObj display newDisplayData currDispData = new newDisplayData(); // in primis SALVO valori previous/precedenti B_previous = B_output; @@ -4863,7 +4911,7 @@ namespace IOB_WIN_FORM.Iob } if (memMap != null && memMap.mMapWrite.ContainsKey(item.Key)) { - // preparo obj da scrivere + // preparo genObj da scrivere objItem newWrite = new objItem() { uid = item.Key, diff --git a/IOB-WIN-FORM/app.config b/IOB-WIN-FORM/app.config index f6d19825..1f0a5c1d 100644 --- a/IOB-WIN-FORM/app.config +++ b/IOB-WIN-FORM/app.config @@ -50,7 +50,7 @@ - + diff --git a/IOB-WIN-FORM/packages.config b/IOB-WIN-FORM/packages.config index a4273766..1b8aed93 100644 --- a/IOB-WIN-FORM/packages.config +++ b/IOB-WIN-FORM/packages.config @@ -16,6 +16,8 @@ + + diff --git a/IOB-WIN-MTC/DATA/CONF/MAIN.ini b/IOB-WIN-MTC/DATA/CONF/MAIN.ini index 68924ab3..93859fea 100644 --- a/IOB-WIN-MTC/DATA/CONF/MAIN.ini +++ b/IOB-WIN-MTC/DATA/CONF/MAIN.ini @@ -17,9 +17,9 @@ CLI_INST=SteamWareSim ;STARTLIST=SIMUL_01,SIMUL_02,SIMUL_03,SIMUL_04 ;STARTLIST=IMI_50 ;STARTLIST=GT593 -;STARTLIST=3024 +STARTLIST=3024 ;STARTLIST=TEST -STARTLIST=SIMUL_01 +;STARTLIST=SIMUL_01 ;NB: mettere copy always ai file di conf x fare test... ;STARTLIST=3024 diff --git a/IOB-WIN-MTC/Iob/MTConn.cs b/IOB-WIN-MTC/Iob/MTConn.cs index 1d1193a3..4ff32d2b 100644 --- a/IOB-WIN-MTC/Iob/MTConn.cs +++ b/IOB-WIN-MTC/Iob/MTConn.cs @@ -1694,8 +1694,10 @@ namespace IOB_WIN_MTC.Iob { lgInfo($"STEP 03 invio dati di {elencoDataItems.Count} records"); sendDataItemsList(elencoDataItems); +#if false // provoa a tracciare dataitems... - trackExchDataRaw(elencoDataItems, 1024); + trackExchDataRaw(elencoDataItems, 1024); +#endif } hasReadItems = true; lgInfo($"STEP 04: memorizzati {dataItemMem.Count} oggetti in memoria"); @@ -1716,7 +1718,7 @@ namespace IOB_WIN_MTC.Iob lastCurrent = DateTime.Now; lgTrace("SAMPLE received"); checkAndSend(document, false); - trackExchDataRaw(document, 1024); + trackExchDataRaw(document, 1024); } /// @@ -1896,6 +1898,8 @@ namespace IOB_WIN_MTC.Iob /// private void traceObservation(IObservation observation) { + // SOLO in debug... +#if false string sMsg = $"VETO: - {observation.DataItemId} | {observation.Category}"; if (observation.Values != null && observation.Values.Count() > 0) { @@ -1906,6 +1910,7 @@ namespace IOB_WIN_MTC.Iob } lgTrace(sMsg); trackExchDataRaw(observation, 1024); +#endif } #endregion Private Methods