Increase websocket_api allowed peak time to 10s (#141680)

* Increase websocket_api allowed peak time to 10s

fixes #141624

During integration reload or startup, we can end up sending a message for
each entity being created for integrations that create them from an external
source (ie MQTT) because the messages come in one at a time. This can overload
the loop and/or client for more than 5s. While we have done significant work
to optimize for this path, we are at the limit at what we can expect clients
to be able to process in the time window, so increase the time window.

* adjust test
This commit is contained in:
J. Nick Koston 2025-03-28 09:32:00 -10:00 committed by GitHub
parent 26268357a0
commit fd9f002e9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View File

@ -21,7 +21,7 @@ type AsyncWebSocketCommandHandler = Callable[
DOMAIN: Final = "websocket_api"
URL: Final = "/api/websocket"
PENDING_MSG_PEAK: Final = 1024
PENDING_MSG_PEAK_TIME: Final = 5
PENDING_MSG_PEAK_TIME: Final = 10
# Maximum number of messages that can be pending at any given time.
# This is effectively the upper limit of the number of entities
# that can fire state changes within ~1 second.

View File

@ -241,7 +241,7 @@ async def test_pending_msg_peak(
instance: http.WebSocketHandler = cast(http.WebSocketHandler, setup_instance)
# Fill the queue past the allowed peak
for _ in range(10):
for _ in range(20):
instance._send_message({"overload": "message"})
async_fire_time_changed(
@ -251,7 +251,7 @@ async def test_pending_msg_peak(
msg = await websocket_client.receive()
assert msg.type is WSMsgType.CLOSE
assert "Client unable to keep up with pending messages" in caplog.text
assert "Stayed over 5 for 5 seconds" in caplog.text
assert "Stayed over 5 for 10 seconds" in caplog.text
assert "overload" in caplog.text