Memoryleak during rule execution?

  • Platform information:
    • Hardware: AMD Ryzen 9 3900X / 64GB / 1TB NVME
    • OS: Windows 10
    • Java Runtime Environment: 8.0.2510.8
    • openHAB version: 2.5.9
  • Issue of the topic:
    Hello everybody,

I’m kind of new to Openhab and have an issue regarding memory usage. I’ve created a rule to do a full color fade for 3 of my WiFi LED Binding using LED controller. When turned off it is supposed to stop the timer and send off commands to the switches of the 3 LED controllers.

What worries me now is that during the execution of the rule the memory used by the Java™ Platform SE binary is constantly increasing. About 2-4mb / second. I’ll post my rule below this text because I just cannot find my error.

When i stop the execution of the rule (Turn the Switch Oben_Fading to OFF) the memory increase stops at once.

Maybe anybody of you can help me here? Thank you in advance.

Best regards,
Patrick


    var Timer timer = null
    var HSBType hsb = null
    var HSBType newHsb = null
    var DecimalType color = null

    rule "Start Wabe 3 Rechts fading"
     when 
      Item Oben_Fading changed
     then
      if (Oben_Fading.state == ON) {
        // set a timer to sligtly change the color again and again
        timer = createTimer(now, [|
          if (Wabe3Links_Eingeschaltet.state == OFF) {
            Wabe3Links_Eingeschaltet.sendCommand(ON)
          }
          if (Wabe3Links_Eingeschaltet.state == OFF) {
            Wabe3Links_Eingeschaltet.sendCommand(ON)
          }
          if (Wabe3STREAM_Eingeschaltet.state == OFF) {
            Wabe3STREAM_Eingeschaltet.sendCommand(ON)
          }
          Oben_Fade_Next.sendCommand(now.toString)
          if (timer !== null) {
            timer.reschedule(now.plusMillis(100))
          }
        ])      
      }
      else {
        timer = null
        Thread::sleep(1000)
        Wabe3Links_Eingeschaltet.sendCommand(OFF)
        Wabe3LinksUnten_Eingeschaltet.sendCommand(OFF)
        Wabe3STREAM_Eingeschaltet.sendCommand(OFF)
      }
    end

    rule "Wabe 3 Rechts Fade Next"
      when 
        Item Oben_Fade_Next changed
      then
        if (Oben_Fading.state == ON) {
          // get your current color
          hsb = Wabe3Links_Color.state as HSBType

          // change it a little bit
          color = new DecimalType(hsb.hue.intValue % 359 + 1) // 0-360; 0=red, 120=green, 240=blue, 360=red(again)

          newHsb = new HSBType(color,new PercentType(100),new PercentType(100))

          // set the new color    
          Wabe3Links_Color.send(newHsb)
          Wabe3LinksUnten_Color.send(newHsb)
          Wabe3STREAM_Color.send(newHsb)
        }
    end

If you are not running out of memory it’s probably not a problem. I’ve not heard of any reports of memory leaks in rules and it’s been over a year since there was a change to the Rules DSL rules engine. If there were I problem I would expect to have seen if before now.

There is nothing that jumps out as unusual in the rules except for that sleep which is a bit long and should probably be a timer instead.

There is nothing wrong with the current approach, but I would have expected the fade next rule’s code to just be inside the Timer instead of creating a new Item and rule to handle it.

1 Like