CPU Last durch setreading in AT

Begonnen von observian, 08 Oktober 2022, 22:04:07

Vorheriges Thema - Nächstes Thema

observian

Hi zusammen,

für meine zusammengestellte Stromzählererfassung benötige belege ich einen Dummy mit Variablen durch ein AT vom MQTT-Device. Nun stellte ich fest, dass dadurch mein System sehr stark belastet wird. Ich habe den setreading Befehl auf set umgestellt, jedoch dadurch nur geringfügig weniger Last. Bitte um Hilfe.

Beispiel at:

DEF        +*00:01:00 {
my $consumption_hour_now = ReadingsVal("MQTT2_IPs_8xS0_WiFi","consumption_7",0) - ReadingsVal("Stromverbrauch_EUV","count_hour_last",0);
my $consumption_day_now = ReadingsVal("MQTT2_IPs_8xS0_WiFi","consumption_7",0) - ReadingsVal("Stromverbrauch_EUV","count_day_last",0);
my $consumption_week_now = ReadingsVal("MQTT2_IPs_8xS0_WiFi","consumption_7",0) - ReadingsVal("Stromverbrauch_EUV","count_week_last",0);
my $consumption_month_now = ReadingsVal("MQTT2_IPs_8xS0_WiFi","consumption_7",0) - ReadingsVal("Stromverbrauch_EUV","count_month_last",0);
my $consumption_year_now = ReadingsVal("MQTT2_IPs_8xS0_WiFi","consumption_7",0) - ReadingsVal("Stromverbrauch_EUV","count_year_last",0);
fhem("set Stromverbrauch_EUV consumption_hour_now $consumption_hour_now");
fhem("set Stromverbrauch_EUV consumption_day_now $consumption_day_now");
fhem("set Stromverbrauch_EUV consumption_week_now $consumption_week_now");
fhem("set Stromverbrauch_EUV consumption_month_now $consumption_month_now");
fhem("set Stromverbrauch_EUV consumption_year_now $consumption_year_now");
my $consumption_hour_now_prize = $consumption_hour_now * ReadingsVal("Strompreis_Hausanschluss","Preis",0) / 100;
fhem("set Stromverbrauch_EUV consumption_hour_now_prize $consumption_hour_now_prize");
my $consumption_day_now_prize = $consumption_day_now * ReadingsVal("Strompreis_Hausanschluss","Preis",0) / 100;
fhem("set Stromverbrauch_EUV consumption_day_now_prize $consumption_day_now_prize");
my $consumption_week_now_prize = $consumption_week_now * ReadingsVal("Strompreis_Hausanschluss","Preis",0) / 100;
fhem("set Stromverbrauch_EUV consumption_week_now_prize $consumption_week_now_prize");
my $consumption_month_now_prize = $consumption_month_now * ReadingsVal("Strompreis_Hausanschluss","Preis",0) / 100;
fhem("set Stromverbrauch_EUV consumption_month_now_prize $consumption_month_now_prize");
my $consumption_year_now_prize = $consumption_year_now * ReadingsVal("Strompreis_Hausanschluss","Preis",0) / 100;
fhem("set Stromverbrauch_EUV consumption_year_now_prize $consumption_year_now_prize");
if($min==0){
my $count_hour = ReadingsVal("MQTT2_IPs_8xS0_WiFi","consumption_7",0);
my $count_hour_last = ReadingsVal("Stromverbrauch_EUV","count_hour",0);
my $consumption_hour = $count_hour - $count_hour_last;
my $consumption_hour_last = ReadingsVal("Stromverbrauch_EUV","consumption_hour",0);
fhem("set Stromverbrauch_EUV count_hour $count_hour");
fhem("set Stromverbrauch_EUV count_hour_last $count_hour_last");
fhem("set Stromverbrauch_EUV consumption_hour_last $consumption_hour_last");
fhem("set Stromverbrauch_EUV consumption_hour $consumption_hour");
my $consumption_hour_prize = $consumption_hour * ReadingsVal("Strompreis_Hausanschluss","Preis",0) / 100;
fhem("set Stromverbrauch_EUV consumption_hour_prize $consumption_hour_prize");
}
if(($hour==0) && ($min==0)){
my $count_day = ReadingsVal("MQTT2_IPs_8xS0_WiFi","consumption_7",0);
my $count_day_last = ReadingsVal("Stromverbrauch_EUV","count_day",0);
my $consumption_day = $count_day - $count_day_last;
my $consumption_day_last = ReadingsVal("Stromverbrauch_EUV","consumption_day",0);
fhem("set Stromverbrauch_EUV count_day $count_day");
fhem("set Stromverbrauch_EUV count_day_last $count_day_last");
fhem("set Stromverbrauch_EUV consumption_day_last $consumption_day_last");
fhem("set Stromverbrauch_EUV consumption_day $consumption_day");
my $consumption_day_prize = $consumption_day * ReadingsVal("Strompreis_Hausanschluss","Preis",0) / 100;
fhem("set Stromverbrauch_EUV consumption_day_prize $consumption_day_prize");
}
if(($hour==0) && ($min==0) && ($wday==1)){
my $count_week = ReadingsVal("MQTT2_IPs_8xS0_WiFi","consumption_7",0);
my $count_week_last = ReadingsVal("Stromverbrauch_EUV","count_week",0);
my $consumption_week = $count_week - $count_week_last;
my $consumption_week_last = ReadingsVal("Stromverbrauch_EUV","consumption_week",0);
fhem("set Stromverbrauch_EUV count_week $count_week");
fhem("set Stromverbrauch_EUV count_week_last $count_week_last");
fhem("set Stromverbrauch_EUV consumption_week_last $consumption_week_last");
fhem("set Stromverbrauch_EUV consumption_week $consumption_week");
my $consumption_week_prize = $consumption_week * ReadingsVal("Strompreis_Hausanschluss","Preis",0) / 100;
fhem("set Stromverbrauch_EUV consumption_week_prize $consumption_week_prize");
}
if(($hour==0) && ($min==0) && ($mday==1)){
my $count_month = ReadingsVal("MQTT2_IPs_8xS0_WiFi","consumption_7",0);
my $count_month_last = ReadingsVal("Stromverbrauch_EUV","count_month",0);
my $consumption_month = $count_month - $count_month_last;
my $consumption_month_last = ReadingsVal("Stromverbrauch_EUV","consumption_month",0);
fhem("set Stromverbrauch_EUV count_month $count_month");
fhem("set Stromverbrauch_EUV count_month_last $count_month_last");
fhem("set Stromverbrauch_EUV consumption_month_last $consumption_month_last");
fhem("set Stromverbrauch_EUV consumption_month $consumption_month");
my $consumption_month_prize = $consumption_month * ReadingsVal("Strompreis_Hausanschluss","Preis",0) / 100;
fhem("set Stromverbrauch_EUV consumption_month_prize $consumption_month_prize");
}
if(($hour==0) && ($min==0) && ($mday==1) && ($month==1)){
my $count_year = ReadingsVal("MQTT2_IPs_8xS0_WiFie","consumption_7",0);
my $count_year_last = ReadingsVal("Stromverbrauch_EUV","count_year",0);
my $consumption_year = $count_year - $count_year_last;
my $consumption_year_last = ReadingsVal("Stromverbrauch_EUV","consumption_year",0);
fhem("set Stromverbrauch_EUV count_year $count_year");
fhem("set Stromverbrauch_EUV count_year_last $count_year_last");
fhem("set Stromverbrauch_EUV consumption_year_last $consumption_year_last");
fhem("set Stromverbrauch_EUV consumption_year $consumption_year");
my $consumption_year_prize = $consumption_year * ReadingsVal("Strompreis_Hausanschluss","Preis",0) / 100;
fhem("set Stromverbrauch_EUV consumption_year_prize $consumption_year_prize");
}
}

   FUUID      619a33f7-f33f-f27b-ca75-5b3add20d53562a6
   FVERSION   90_at.pm:0.252480/2021-11-21
   NAME       at_Stromverbrauch_EUV
   NR         93
   NTM        22:01:44
   PERIODIC   yes
   RELATIVE   yes
   REP        -1
   STATE      Next: 22:01:44
   TIMESPEC   00:01:00
   TRIGGERTIME 1665259304.04632
   TRIGGERTIME_FMT 2022-10-08 22:01:44
   TYPE       at
   READINGS:
     2022-10-08 22:00:44   state           Next: 22:01:44
   helper:
     bm:
       at_Set:
         cnt        1
         dmx        -1000
         dtot       0
         dtotcnt    0
         mTS        08.10. 22:00:58
         max        2.88486480712891e-05
         tot        2.88486480712891e-05
         mAr:
           HASH(0x55d063555950)
           at_Stromverbrauch_EUV
           ?
Attributes:
   room       2_Geraete->Energie
   stateFormat state
   webCmd     execNow:active:inactive




active-timers: 28; max-active timers: 31; max-timer-load: 25  min-tmrHandlingTm: 0.0ms; max-tmrHandlingTm: 397.2ms; totAvgDly: 99.5ms

name                                     function                               max    count      total  average   maxDly   avgDly TS Max call     param Max call
tmr-at_Exec                              HASH(0x55d063479d78)                    48        3     117.25    39.08   392.99   337.18 08.10. 21:59:44 HASH(at_Stromverbrauch_Licht_HUE_EG)
tmr-at_Exec                              HASH(0x55d0634c1a38)                    42        3     113.58    37.86    57.71    52.64 08.10. 22:00:44 HASH(at_Stromverbrauch_Waermestrom)
tmr-at_Exec                              HASH(0x55d0634e4940)                    55        3     147.07    49.02     0.64     0.50 08.10. 22:00:44 HASH(at_Stromverbrauch_Hauptzaehler)
tmr-at_Exec                              HASH(0x55d0635182b8)                    56        3     146.50    48.83    90.57    87.10 08.10. 22:00:44 HASH(at_Stromverbrauch_EG)
tmr-at_Exec                              HASH(0x55d063518b50)                    39        3     106.83    35.61   144.49   132.93 08.10. 22:00:44 HASH(at_Stromverbrauch_Klima_Schlafen)
tmr-at_Exec                              HASH(0x55d063519108)                    39        3     102.84    34.28   181.37   165.57 08.10. 22:00:44 HASH(at_Stromverbrauch_Klima_Wohnen)
tmr-at_Exec                              HASH(0x55d063554098)                    53        3     133.92    44.64   217.78   196.67 08.10. 22:00:44 HASH(at_Stromverbrauch_Praxis)
tmr-at_Exec                              HASH(0x55d063554908)                    57        3     142.44    47.48   267.69   238.20 08.10. 22:00:44 HASH(at_Stromverbrauch_OG)
tmr-at_Exec                              HASH(0x55d063555140)                    52        3     136.59    45.53   322.36   282.53 08.10. 22:00:44 HASH(at_Stromverbrauch_DG)
tmr-at_Exec                              HASH(0x55d063555950)                    54        3     135.17    45.06   371.99   324.84 08.10. 22:00:44 HASH(at_Stromverbrauch_EUV)
HmDRAP,DRBL,DRS,DRI,ASIR,SPDR,SPI,FAL,SWDO,SCTH,SWOB,SWSD,SWD,BSL,WRC2,WRC6,STH,WTH,LC_Bl1
4xHMCCU,3xHUE,HarmonyHub,
Müllkalender,HomeConnect,Alexa,INSTAR9020,Fritzbox,Fritzrep,Fully,360,JudoIsoft,Velux,KFL,HeliosKWL,Sonoff(POW2,Basic,DS18B20),IPs8xS0,DaikinEHVX,Roborock,iRobot,IoBroker

Gisbert

Hallo observian,

vergiss deine eigenen Definitionen und werte stattdessen den Stromverbrauch mit dem ElectricityCalculator Modul aus. Damit wirst du deine Performance-Probleme los.

Viele Grüße Gisbert
Aktuelles FHEM | PROXMOX | Fujitsu Futro S740 | Debian 12 | UniFi | Homematic, VCCU, HMUART | ESP8266 | ATtiny85 | Wasser-, Stromzähler | tuya local | Wlan-Kamera | SIGNALduino, Flamingo Rauchmelder FA21/22RF | RHASSPY | DEYE | JK-BMS | ESPHome

jhohmann

Interessant wäre noch, ob auf dem Device Stromverbrauch_EUV ein oder mehrere Notifys hängen. Hier wird bei dem Gerät so oft was geändert, dass bei einem schlecht definierten notify zu wahnsinnig vielen Events führen wird.
Und das dürfte dann die Systemlast bewirken.
Raspberry Pi 4 - bookworm / EnOcean - Rollo+Licht, deCONZ - Licht+Sensoren, ZWave - CO Messung, HMCCU mit piVCCU - Heizung+Rollo
plus dovecot, minidlna

Beta-User

Zitat von: observian am 08 Oktober 2022, 22:04:07
habe den setreading Befehl auf set umgestellt, jedoch dadurch nur geringfügig weniger Last.
Das halte ich für eine subjektive Fehleinschätzung...

Jeder "set" oder "setreading"-Befehl erzeugt am Ende einen "trigger" und löst damit potentiell auch die komplette Eventverarbeitung aus, ergo macht es in der Hinsicht überhaupt keinen Unterschied, welches der beiden Kommandos man verwendet. Hat man (viele) "ungünstig" definierte Eventhandler (z.B. eben notify ohne NOTIFYDEV), dauert die Abarbeitung eben entsprechend länger...

Deswegen ist der Hinweis von Gisbert auf spezielle Tools (ich verwende z.B. lieber statistics) schon prinzipiell der bessere Ansatz: Da werden die erforderlichen Daten ggf. dann nicht-triggernd verwaltet und nur am Ende ggf. dann gleich für den ganzen "Event-Stapel" (readings per bulk update aktualisiert) die Event-Verarbeitung angestoßen, was dementsprechend weniger Last bedeutet.

Man könnte was ähnliches erreichen, wenn man die "Details" in (sauber getriggerte) userReadings steckt und dann nur minütlich ein "Leitreading" aktualisiert, das dann den Rest über den trigger berechnet.
userReadings werden im selben "Stapel" abgearbeitet wie das triggernde Reading.

Ergänzend: für Plots etc. kann man auch die "delta"-Varianten hernehmen, dann braucht man uU. gar keine entsprechenden Einträge in den Logs, sondern berechnet es dann, wenn man es haben will.
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: ZigBee2mqtt, MiLight@ESP-GW, BT@OpenMQTTGw | ZWave | SIGNALduino | MapleCUN | RHASSPY
svn: u.a Weekday-&RandomTimer, Twilight,  div. attrTemplate-files, MySensors

observian

Perfekt. Danke für die Erklärungen. Ich werde den Aufbau diese Woche mal prüfen und die Performance beobachten. Danke für eure Mithilfe.
HmDRAP,DRBL,DRS,DRI,ASIR,SPDR,SPI,FAL,SWDO,SCTH,SWOB,SWSD,SWD,BSL,WRC2,WRC6,STH,WTH,LC_Bl1
4xHMCCU,3xHUE,HarmonyHub,
Müllkalender,HomeConnect,Alexa,INSTAR9020,Fritzbox,Fritzrep,Fully,360,JudoIsoft,Velux,KFL,HeliosKWL,Sonoff(POW2,Basic,DS18B20),IPs8xS0,DaikinEHVX,Roborock,iRobot,IoBroker