joBr99 / nspanel-lovelace-ui

Custom Firmware for NsPanel with the design of HomeAssistant's lovelace UI in mind, works with Tasmota.
GNU General Public License v3.0
857 stars 187 forks source link

[BUG] Long (relatively) delay between touching the screen and something happening #835

Closed jacekowski closed 7 months ago

jacekowski commented 1 year ago

I'm experiencing a relatively high latency when i touch the screen.

I've narrowed it down to somewhere around appdaemon + nspanel-lovelace-ui app

comms from nspanel to MQTT broker (i've removed not relevant packets)

8 01:10:07.665081152 10.42.10.196 → 10.42.99.189 MQTT 109 Publish Message [tele/NSPanel_D3E4D4/RESULT]
10 01:10:08.279466491 10.42.99.189 → 10.42.10.196 MQTT 109 Publish Message [cmnd/NSPanel_D3E4D4/CustomSend]
12 01:10:08.292347194 10.42.99.189 → 10.42.10.196 MQTT 98 Publish Message [cmnd/NSPanel_D3E4D4/CustomSend]

comms from mqtt broker to appdaemon

15 01:10:07.665517703 10.42.99.189 → 172.30.33.5  MQTT 151 Publish Message [tele/NSPanel_D3E4D4/RESULT]
17 01:10:08.277492375  172.30.33.5 → 10.42.99.189 MQTT 121 Publish Message [cmnd/NSPanel_D3E4D4/CustomSend]

appdaemon logs:

2023-03-27 01:10:08.247387 INFO nspanel-5: MQTT callback for: {'topic': 'tele/NSPanel_D3E4D4/RESULT', 'wildcard': None, 'payload': '{"CustomRecv":"event,buttonPress2,screensaver,bExit,1"}'}
2023-03-27 01:10:08.248387 INFO nspanel-5: Received Message from Screen: event,buttonPress2,screensaver,bExit,1
2023-03-27 01:10:08.249085 INFO nspanel-5: Button Press Event; entity_id: screensaver; button_type: bExit; value: 1
2023-03-27 01:10:08.273321 INFO nspanel-1: Sending MQTT Message: pageType~cardEntities

as can be seen there is a significant latency between mqtt message being delivered by the broker to appdaemon and message appearing in the logs (so appdaemon reacting to it)

HA VM is not overloaded in any way

joBr99 commented 1 year ago

The MQTT callback for: message is the first thing the backend does after receiving the mqtt message. If there is a huge delay before this log message, this sounds more like an issue with the appdaemon (https://github.com/AppDaemon/appdaemon) than with this backend app.

Do you have configured core-mosquitto.local.hass.io as address for mqtt in appdaemon?

jacekowski commented 1 year ago

I'm running mqtt broker in a separate VM (on same proxmox cluster and connected via 40G ethernet) so i'm using different address.

Latency is clearly not caused by MQTT broker or network (i can see MQTT messages delivered on time when i run tshark (message was delivered at 15 01:10:07.665517703 but backend log message only appears nearly 600ms later)), which means it's either appdaemon or this backend app.

How much latency are other people seeing?

joBr99 commented 1 year ago

AppDaemon is calling this function:

https://github.com/joBr99/nspanel-lovelace-ui/blob/main/apps/nspanel-lovelace-ui/luibackend/mqtt.py#L15

First thing that is done there is logging this calback message. I cannot run tshark to check the network packets, however there is also no long delay on my panels.

jacekowski commented 1 year ago

So, my further testing indicates that the issue is caused by appdeamon and how threading in python and appdaemon works.

This call https://github.com/AppDaemon/appdaemon/blob/dev/appdaemon/plugins/mqtt/mqttplugin.py#L311 schedules everything, but then there can be a significant delay between event actually being dealt with.

joBr99 commented 1 year ago

looking into appdaemons config options uvloop might improve this

https://appdaemon.readthedocs.io/en/latest/CONFIGURE.html#advanced-options

phoenixtechnam commented 1 year ago

I have been wondering about the same issue. After reading this ticket I did some testing.

See video attached which shows the inconsistencies in delay, sometimes it responds fast, sometimes slower, sometimes not at all.

https://user-images.githubusercontent.com/29205326/234601027-4dad8168-b231-4d40-9459-49fb525d3b4a.mp4

The physical button on this nspanel send out an MQTT messages to toggle the remote light above me and as you can see it always shows an "instant" response which proves it is not a WIFI issue. Deactivating screensaver and dialling through the interface cards has a lot of delay in comparison and the delay is not very consistent, e.g. shows a response time between between 0.5-2 seconds.

I also experience bugs (rarely but consistent) like,

I also looked at real-time logs from appdeamon and noticed that processing seems to be very fast with no considerable delay. Given the fact that the physical buttons activate a remote light instantly, I would say most of the delays are caused by the UI rendering and touch event processing. Using uvloop variable in appdaemon config had no effect in my setup.

Correct me if you have different insights. Thanks for the good work anyway!

kuckuckmann commented 1 year ago

I updated from version 47 to 50 an hour ago and the difference feels huge. In comparisson to the former version it's now closly 2 secconds of response after touching.

Doughboy68 commented 11 months ago

I updated from version 47 to 50 an hour ago and the difference feels huge. In comparisson to the former version it's now closly 2 secconds of response after touching.

What is the version 47 and 50 in reference to? I seem to have performance issues also and wondering how to fix. Or am I reading your post incorrect, and you said version 50 caused slow performance? I realize this is a couple months old so probably changed now?

stleusc commented 10 months ago

I am having similar issues with the latest version. Sometimes it takes several seconds for something to happen.

rwagoner commented 9 months ago

I'm have the same issue. Sometimes it's slow to respond or doesn't respond when waking the screen. I can press the left/right buttons while this is occurring and those events fire immediately. Thoughts?

rwagoner commented 9 months ago

What would be needed to track this down? I'm happy to capture logs and test as necessary. When passing by the panel and want to make a change, if it takes more than a few seconds, I find I just pull out my phone.

jacekowski commented 9 months ago

From my testing it looks like the issue is with asyncio in python and how it is used in appdaemon (it can take really long time for it to actually process the event, uvloop seems to be slightly better, but not significantly as the real issue is with python limitations and how appdeamon makes thigs worse)

joBr99 commented 7 months ago

fixed by #1058