Slow reactions to external mosquitto broker for both publish and subscribe

I have a home assistant instance that only deals with mtt (mqtt devices, mqtt commands).

if i run
mosquitto_publish -h <broker> -t "x/command" -m "{\"state\":\"ON\"}"
or
mosquitto_publish -h <broker> -t "x/command" -m "{\"state\":\"OFF\"}"

then the light turns on or off almost immediately (dims up/down fast in 1 second to full/no brightness)

I ran this 100 times with a script and got zero delay every time, so MQTT -> light -> MQTT works fine. I also see updates to topic x/state like
{"brightness":255,"state":"OFF"}
or
{"brightness":255,"state":"ON"}

The light is configured like this

 - platform: mqtt_json
   id: officelamp
   name: Office Lamp
   state_topic:        service/nodered/officelamp/state
   command_topic:      service/nodered/officelamp/command
   availability_topic: service/nodered/officelamp/connection
   brightness: true

If I click on the home assistant interface on the button to turn the light ON or OFF, I see a publish in mqtt in about 15 seconds, the lights turns on immediately, then after about another 15 seconds the light is marked on

  • 0 second
  • click in homeassistant to turn on or off the light
  • after ~15 seconds
  • see a publish to /command with correct message
  • see a publish to /state with correct message
  • after ~ 30 seconds
  • state updates in homeassistant

How do I debug this? Before a full system restart everything worked with zero issues and now everything seems laggy ( for example showing the about page, the area that shows errors takes a very long time to load )

Thank you for your time!

The usual problem with unresponsive systems is the size of the HA database, so I would check that first.

I had to disable recorder some time ago because of this, I’m making a nodejs service to push data to mysql in a more optimized way.