Delay processing messages



  • Sometimes I notice that there is some delay in Home Assistant processing or receiving MySensors messages.
    For example, I have a node with two switches. I press switch A and right after switch B. Looking at the debug logs from HA's MySensors component, switch B state is updated about a second after switch A.

    I have never noticed this delay when using Pimatic instead of HA.


  • Plugin Developer

    Are you using a serial gateway? There's a timeout on the serial read operation of 1 second, which might explain your observed behavior. It might be possible to make this more efficient.



  • @martinhjelmare yes, I'm using the serial gateway. It should be possible to make it better, since I had no issues with the same gateway on Pimatic. I'll try to have a look at the code and let you know if I also find anything



  • @martinhjelmare have you found anything? I've had a quick look at the code and found nothing relevant. The 1 second timeout you're referring to is just a connection timeout, right? It shouldn't affect communication after connecting I guess.
    I'll try to add some debug prints to see if I find anything.


  • Plugin Developer

    No the timeout is for the readline operation. It will read for 1 sec or until a newline character is received. I'm not sure why that would "block" for 1 second between two messages that are sent closer than 1 second. But it's my only explanation at this point. I have an idea for changing the reading from the serial port, making it non blocking without timeout, by checking if there's data available in the read buffer before reading. But I don't have time right now to code that up and test it. I'll probably have time during Christmas. If you want to make a PR before that, you're welcome and I'll review it.



  • Thanks. I've been debugging it, and it seems that sometimes "self.handle_queue()" in run() takes one or two seconds. It is not very frequent, but it seems to be the cause of my issues.
    Also, my node is sending the message twice sometimes (I have yet to check why), and that increases the time also.



  • @martinhjelmare Have you looked into this? I've been noticing delays very frequently 😕
    I don't have those delays with other components, and also had not had them when using Pimatic instead of HA.


  • Plugin Developer

    I did some debugging for another issue:
    https://github.com/home-assistant/home-assistant/issues/5163
    But I wasn't able to find anything wrong at that time on the home assistant / pymysensors side.

    I could see that the serial read operation was not blocking when there were incoming messages. So the full timeout of 1 second only came into play if there were not any messages to read.

    Pymysensors also responded with a send "immediately" (~1 ms) after receiving a request for time in my testing.

    Please post debug logs and version of home assistant and anything else that might be useful. It would be interesting if you can test to use only pymysensors without home assistant and see if you still notice delays.

    I'm not saying there's no problem, but I've just not been able to pinpoint it yet. If you have a test case, that I can replicate, that would be good.



  • @martinhjelmare No problem, I'll try to get some more data. Regarding HA version, I'm always on the latest version (with one or two days delay).


Log in to reply
 

Suggested Topics

  • 1
  • 1
  • 1
  • 8
  • 2

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts