From 612766920c1e9fabed1e8bb140e90b11fffdecbd Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 14 Jul 2025 16:02:15 +0200 Subject: [PATCH 1/2] Totlo da redis coda FLog x diminuire carico --- IOB-UT-NEXT/Iob/BaseObj.cs | 4 +- IOB-UT-NEXT/RedisMan.cs | 168 ++++++++++++++++---------- IOB-WIN-FORM/Iob/Generic.Protected.cs | 9 +- IOB-WIN-FORM/Iob/Generic.Public.cs | 5 +- 4 files changed, 114 insertions(+), 72 deletions(-) diff --git a/IOB-UT-NEXT/Iob/BaseObj.cs b/IOB-UT-NEXT/Iob/BaseObj.cs index ff619dc9..07fe90b1 100644 --- a/IOB-UT-NEXT/Iob/BaseObj.cs +++ b/IOB-UT-NEXT/Iob/BaseObj.cs @@ -630,7 +630,9 @@ namespace IOB_UT_NEXT.Iob QueueAlarm = new DataQueue(codIob, "QueueAlarm", false, redisMan); // valutare se portare di nuovo in redis... QueueIN = new DataQueue(codIob, "QueueIN", useRedis, redisMan); - QueueFLog = new DataQueue(codIob, "QueueFLog", useRedis, redisMan); + // fix a NON redis + QueueFLog = new DataQueue(codIob, "QueueFLog", false, redisMan); + //QueueFLog = new DataQueue(codIob, "QueueFLog", useRedis, redisMan); QueueMessages = new DataQueue(codIob, "QueueMessages", false, redisMan); QueueRawTransf = new DataQueue(codIob, "QueueRawTransf", false, redisMan); QueueULog = new DataQueue(codIob, "QueueULog", false, redisMan); diff --git a/IOB-UT-NEXT/RedisMan.cs b/IOB-UT-NEXT/RedisMan.cs index 60e64fb0..d7d9b1ad 100644 --- a/IOB-UT-NEXT/RedisMan.cs +++ b/IOB-UT-NEXT/RedisMan.cs @@ -29,6 +29,7 @@ namespace IOB_UT_NEXT /// public RedisIobCache() { + initRedisConn(); initMemKeys(); } @@ -43,6 +44,7 @@ namespace IOB_UT_NEXT /// public RedisIobCache(string codServer, string codIob, string tipoIob, int minDeltaS) { + initRedisConn(); // init dati di base... currCodIob = codIob; currIobType = tipoIob; @@ -116,41 +118,21 @@ namespace IOB_UT_NEXT { // init DB (sullo 0) answ = connRedis.GetDatabase(); + int dbNum = baseUtils.CRI("redisDb"); // gestione override... - if (baseUtils.CRI("redisDb") >= 0) + if (dbNum >= 0) { // in questo caso uso il DB configurato in app.config... - answ = connRedis.GetDatabase(baseUtils.CRI("redisDb")); + answ = connRedis.GetDatabase(dbNum); } _currDB = answ; + Logging.Instance.Info($"Apertura di un Redis Database: {dbNum}"); } // restituisco oggetto DB return answ; } } - /// - /// Oggetto statico connessione redis - /// - public ConnectionMultiplexer connRedis - { - get - { - return lazyConnection.Value; - } - } - - /// - /// Oggetto statico connessione redis - /// - public ConnectionMultiplexer connRedisAdmin - { - get - { - return lazyConnectionAdmin.Value; - } - } - /// /// Accesso all'oggetto stato IOB da esterno /// @@ -206,6 +188,7 @@ namespace IOB_UT_NEXT // init DB (sullo 0) answ = connRedis.GetSubscriber(); _currSub = answ; + Logging.Instance.Info($"Apertura di un Redis Message Subscriber"); } // restituisco oggetto DB return answ; @@ -792,35 +775,6 @@ namespace IOB_UT_NEXT return answ; } -#if false - /// - /// Incremento conteggio di un valore dentro una hash - /// - /// chiave - /// valore con conteggio da tracciare - /// scadenza preimpostata hash datetime, se null NON scade - /// - public bool redIncrHashCount(string hashKey, string hashField, DateTime? hashExpire) - { - bool answ = false; - // cerco se ci sia valore in redis... - try - { - RedisKey chiave = hashKey; - cache.HashIncrement(chiave, hashField, 1); - if (hashExpire != null) - { - cache.KeyExpire(chiave, hashExpire); - } - } - catch (Exception exc) - { - Logging.Instance.Error($"redIncrHashCount {exc}"); - } - return answ; - } -#endif - /// /// Incremento conteggio di un valore dentro una hash /// @@ -907,6 +861,18 @@ namespace IOB_UT_NEXT return cache.ListLeftPop(queueName); } + /// + /// Recupero list di TUTTI i valori in QUEUE (FIFO) + /// + /// + /// num max di elementi da recuperare + public List redQueuePopAll(RedisKey queueName) + { + long nCount = cache.ListLength(queueName); + List listData = cache.ListRange(queueName, 0, nCount).ToList(); + return listData; + } + /// /// Recupero una list di valori in QUEUE (FIFO) /// @@ -920,18 +886,6 @@ namespace IOB_UT_NEXT return listData; } - /// - /// Recupero list di TUTTI i valori in QUEUE (FIFO) - /// - /// - /// num max di elementi da recuperare - public List redQueuePopAll(RedisKey queueName) - { - long nCount = cache.ListLength(queueName); - List listData = cache.ListRange(queueName, 0, nCount).ToList(); - return listData; - } - /// /// Scrittura valore in QUEUE (FIFO) /// @@ -1112,6 +1066,7 @@ namespace IOB_UT_NEXT } return answ; } + /// /// Salvataggio di una hash di valori in formato Dictionary /// @@ -1514,6 +1469,7 @@ namespace IOB_UT_NEXT /// private Dictionary LastKeySave = new Dictionary(); +#if false /// /// Connessione lazy a redis... /// @@ -1540,7 +1496,8 @@ namespace IOB_UT_NEXT } return ConnectionMultiplexer.Connect(RedisConnAdmin); - }); + }); +#endif #endregion Private Fields @@ -1556,6 +1513,32 @@ namespace IOB_UT_NEXT /// private ISubscriber _currSub { get; set; } + /// + /// Oggetto statico connessione redis + /// + private ConnectionMultiplexer connRedis { get; set; } +#if false + { + get + { + return lazyConnection.Value; + } + } +#endif + + /// + /// Oggetto statico connessione redis + /// + private ConnectionMultiplexer connRedisAdmin { get; set; } +#if false + { + get + { + return lazyConnectionAdmin.Value; + } +} +#endif + #endregion Private Properties #region Private Methods @@ -1591,6 +1574,59 @@ namespace IOB_UT_NEXT redIobChannel = $"IobChannel_{currCodIob}"; } + /// + /// Init oggetti connessione REDIS + /// + private void initRedisConn() + { + // init obj standard + string RedisConn = baseUtils.CRS("RedisConn"); + if (string.IsNullOrEmpty(RedisConn)) + { + RedisConn = "localhost,abortConnect=false,ssl=false"; + } + connRedis = ConnectionMultiplexer.Connect(RedisConn); + Logging.Instance.Info($"Apertura di un Redis Multiplexer"); + + // initi obj admin + string RedisConnAdmin = baseUtils.CRS("RedisConnAdmin"); + if (string.IsNullOrEmpty(RedisConnAdmin)) + { + RedisConnAdmin = "localhost,abortConnect=false,ssl=false,allowAdmin=true"; + } + connRedisAdmin = ConnectionMultiplexer.Connect(RedisConnAdmin); + Logging.Instance.Info($"Apertura di un Redis Multiplexer Admin"); + } + #endregion Private Methods + +#if false + /// + /// Incremento conteggio di un valore dentro una hash + /// + /// chiave + /// valore con conteggio da tracciare + /// scadenza preimpostata hash datetime, se null NON scade + /// + public bool redIncrHashCount(string hashKey, string hashField, DateTime? hashExpire) + { + bool answ = false; + // cerco se ci sia valore in redis... + try + { + RedisKey chiave = hashKey; + cache.HashIncrement(chiave, hashField, 1); + if (hashExpire != null) + { + cache.KeyExpire(chiave, hashExpire); + } + } + catch (Exception exc) + { + Logging.Instance.Error($"redIncrHashCount {exc}"); + } + return answ; + } +#endif } } \ No newline at end of file diff --git a/IOB-WIN-FORM/Iob/Generic.Protected.cs b/IOB-WIN-FORM/Iob/Generic.Protected.cs index c97de8b6..62cdcdd8 100644 --- a/IOB-WIN-FORM/Iob/Generic.Protected.cs +++ b/IOB-WIN-FORM/Iob/Generic.Protected.cs @@ -5152,7 +5152,9 @@ namespace IOB_WIN_FORM.Iob bool useRedis = IOBConfFull.General.EnabRedisQue; QueueAlarm = new DataQueue(codIob, "QueueAlarm", false, redisMan); QueueIN = new DataQueue(codIob, "QueueIN", useRedis, redisMan); - QueueFLog = new DataQueue(codIob, "QueueFLog", useRedis, redisMan); + // no coda redis + QueueFLog = new DataQueue(codIob, "QueueFLog", false, redisMan); + //QueueFLog = new DataQueue(codIob, "QueueFLog", useRedis, redisMan); QueueMessages = new DataQueue(codIob, "QueueMessages", false, redisMan); QueueRawTransf = new DataQueue(codIob, "QueueRawTransf", false, redisMan); QueueULog = new DataQueue(codIob, "QueueULog", false, redisMan); @@ -5288,8 +5290,9 @@ namespace IOB_WIN_FORM.Iob listaValori = QueueFLog.ToList(); // invio sendDataBlock(urlType.FLog, listaValori); - // svuoto! - QueueFLog = new DataQueue(IOBConfFull.General.FilenameIOB, "QueueFLog", IOBConfFull.General.EnabRedisQue, redisMan); + // svuoto! NO redis + QueueFLog = new DataQueue(IOBConfFull.General.FilenameIOB, "QueueFLog", false, redisMan); + //QueueFLog = new DataQueue(IOBConfFull.General.FilenameIOB, "QueueFLog", IOBConfFull.General.EnabRedisQue, redisMan); lastWatchDog = DateTime.Now; } } diff --git a/IOB-WIN-FORM/Iob/Generic.Public.cs b/IOB-WIN-FORM/Iob/Generic.Public.cs index 5aa5bdbc..e3977805 100644 --- a/IOB-WIN-FORM/Iob/Generic.Public.cs +++ b/IOB-WIN-FORM/Iob/Generic.Public.cs @@ -3315,8 +3315,9 @@ namespace IOB_WIN_FORM.Iob listaValori = QueueFLog.ToList(); // invio sendDataBlock(urlType.FLog, listaValori); - // svuoto! - QueueFLog = new DataQueue(IOBConfFull.General.FilenameIOB, "QueueFLog", IOBConfFull.General.EnabRedisQue, redisMan); + // svuoto! NO REDIS + QueueFLog = new DataQueue(IOBConfFull.General.FilenameIOB, "QueueFLog", false, redisMan); + //QueueFLog = new DataQueue(IOBConfFull.General.FilenameIOB, "QueueFLog", IOBConfFull.General.EnabRedisQue, redisMan); } } // HO FINITO invio di FLog... From fef1bf2deea70f7f8ce45327f3dd3eb58d8e5fe4 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 14 Jul 2025 16:02:42 +0200 Subject: [PATCH 2/2] update test compile x SIMULA --- IOB-WIN-FTP/DATA/CONF/MAIN.ini | 1 + IOB-WIN-MTC/DATA/CONF/MAIN.ini | 1 + IOB-WIN-OPC-UA/DATA/CONF/MAIN.ini | 1 + IOB-WIN-PING/DATA/CONF/MAIN.ini | 1 + IOB-WIN-WPS/DATA/CONF/MAIN.ini | 1 + 5 files changed, 5 insertions(+) diff --git a/IOB-WIN-FTP/DATA/CONF/MAIN.ini b/IOB-WIN-FTP/DATA/CONF/MAIN.ini index ebc0bef6..2cb4f81c 100644 --- a/IOB-WIN-FTP/DATA/CONF/MAIN.ini +++ b/IOB-WIN-FTP/DATA/CONF/MAIN.ini @@ -20,3 +20,4 @@ CLI_INST=SteamWareSim STARTLIST=FTP_SONATEST MAXCNC=10 + diff --git a/IOB-WIN-MTC/DATA/CONF/MAIN.ini b/IOB-WIN-MTC/DATA/CONF/MAIN.ini index 5893f9f9..68924ab3 100644 --- a/IOB-WIN-MTC/DATA/CONF/MAIN.ini +++ b/IOB-WIN-MTC/DATA/CONF/MAIN.ini @@ -25,3 +25,4 @@ STARTLIST=SIMUL_01 ;STARTLIST=3024 MAXCNC=10 + diff --git a/IOB-WIN-OPC-UA/DATA/CONF/MAIN.ini b/IOB-WIN-OPC-UA/DATA/CONF/MAIN.ini index 1a6e344d..65b695c2 100644 --- a/IOB-WIN-OPC-UA/DATA/CONF/MAIN.ini +++ b/IOB-WIN-OPC-UA/DATA/CONF/MAIN.ini @@ -32,3 +32,4 @@ CLI_INST=SteamWareSim STARTLIST=1042 MAXCNC=10 + diff --git a/IOB-WIN-PING/DATA/CONF/MAIN.ini b/IOB-WIN-PING/DATA/CONF/MAIN.ini index ec3f6146..f7213b4a 100644 --- a/IOB-WIN-PING/DATA/CONF/MAIN.ini +++ b/IOB-WIN-PING/DATA/CONF/MAIN.ini @@ -19,3 +19,4 @@ STARTLIST=FTP-PING ;STARTLIST=3024-PING MAXCNC=10 + diff --git a/IOB-WIN-WPS/DATA/CONF/MAIN.ini b/IOB-WIN-WPS/DATA/CONF/MAIN.ini index 73c016b4..a4551270 100644 --- a/IOB-WIN-WPS/DATA/CONF/MAIN.ini +++ b/IOB-WIN-WPS/DATA/CONF/MAIN.ini @@ -23,3 +23,4 @@ STARTLIST=3018 ;STARTLIST=3019 MAXCNC=10 +