MTC: esclusione track dati raw x problemi performances (da indagare jetco 3024...)

This commit is contained in:
Samuele Locatelli
2025-07-16 09:21:47 +02:00
parent 321b3d5129
commit 53a8f88aca
6 changed files with 76 additions and 15 deletions
+6
View File
@@ -86,6 +86,12 @@
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.1.0\lib\net462\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Text.Encodings.Web, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Encodings.Web.8.0.0\lib\net462\System.Text.Encodings.Web.dll</HintPath>
</Reference>
<Reference Include="System.Text.Json, Version=8.0.0.6, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Json.8.0.6\lib\net462\System.Text.Json.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.6.0\lib\net462\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
+58 -10
View File
@@ -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;
}
/// <summary>
/// Gestione loop da evitare x serializzazioni
/// </summary>
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
};
/// <summary>
/// Traccia in redis l'attività di lettura dati
/// </summary>
@@ -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
/// </summary>
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,
+1 -1
View File
@@ -50,7 +50,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.6" newVersion="8.0.0.6" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Channels" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
+2
View File
@@ -16,6 +16,8 @@
<package id="System.Memory" version="4.6.0" targetFramework="net462" />
<package id="System.Numerics.Vectors" version="4.6.0" targetFramework="net462" />
<package id="System.Runtime.CompilerServices.Unsafe" version="6.1.0" targetFramework="net462" />
<package id="System.Text.Encodings.Web" version="8.0.0" targetFramework="net462" />
<package id="System.Text.Json" version="8.0.6" targetFramework="net462" />
<package id="System.Threading.Tasks.Extensions" version="4.6.0" targetFramework="net462" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net462" />
<package id="YamlDotNet" version="16.3.0" targetFramework="net462" />
+2 -2
View File
@@ -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
+7 -2
View File
@@ -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);
}
/// <summary>
@@ -1896,6 +1898,8 @@ namespace IOB_WIN_MTC.Iob
/// <param name="observation"></param>
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