tweak for chrome since it works great in firefox but chrome cannot handle it
parent
f3d2003dca
commit
439e2d76b1
|
@ -22,6 +22,7 @@ type AsyncWebSocketCommandHandler = Callable[
|
||||||
DOMAIN: Final = "websocket_api"
|
DOMAIN: Final = "websocket_api"
|
||||||
URL: Final = "/api/websocket"
|
URL: Final = "/api/websocket"
|
||||||
PENDING_MSG_PEAK: Final = 1024
|
PENDING_MSG_PEAK: Final = 1024
|
||||||
|
READY_FUTURE_MAX_MESSAGES: Final = 128
|
||||||
PENDING_MSG_PEAK_TIME: Final = 5
|
PENDING_MSG_PEAK_TIME: Final = 5
|
||||||
# Maximum number of messages that can be pending at any given time.
|
# Maximum number of messages that can be pending at any given time.
|
||||||
# This is effectively the upper limit of the number of entities
|
# This is effectively the upper limit of the number of entities
|
||||||
|
|
|
@ -26,6 +26,7 @@ from .const import (
|
||||||
MAX_PENDING_MSG,
|
MAX_PENDING_MSG,
|
||||||
PENDING_MSG_PEAK,
|
PENDING_MSG_PEAK,
|
||||||
PENDING_MSG_PEAK_TIME,
|
PENDING_MSG_PEAK_TIME,
|
||||||
|
READY_FUTURE_MAX_MESSAGES,
|
||||||
SIGNAL_WEBSOCKET_CONNECTED,
|
SIGNAL_WEBSOCKET_CONNECTED,
|
||||||
SIGNAL_WEBSOCKET_DISCONNECTED,
|
SIGNAL_WEBSOCKET_DISCONNECTED,
|
||||||
URL,
|
URL,
|
||||||
|
@ -247,7 +248,9 @@ class WebSocketHandler:
|
||||||
We will release the ready future if the queue did not grow since the
|
We will release the ready future if the queue did not grow since the
|
||||||
last time we tried to release the ready future.
|
last time we tried to release the ready future.
|
||||||
|
|
||||||
If we reach the peak, we will release the ready future immediately.
|
If we reach READY_FUTURE_MAX_MESSAGES, we will release the ready
|
||||||
|
future immediately so avoid the messages getting to large which
|
||||||
|
can cause Chrome to stall (not not firefox).
|
||||||
"""
|
"""
|
||||||
if (
|
if (
|
||||||
not (ready_future := self._ready_future)
|
not (ready_future := self._ready_future)
|
||||||
|
@ -256,10 +259,7 @@ class WebSocketHandler:
|
||||||
):
|
):
|
||||||
self._release_ready_queue_size = 0
|
self._release_ready_queue_size = 0
|
||||||
return
|
return
|
||||||
# If we are below the peak and there are new messages in the queue
|
if queue_size > self._release_ready_queue_size < READY_FUTURE_MAX_MESSAGES:
|
||||||
# since the last time we tried to release the ready future, we try again
|
|
||||||
# later so we can coalesce more messages.
|
|
||||||
if queue_size > self._release_ready_queue_size < PENDING_MSG_PEAK:
|
|
||||||
self._release_ready_queue_size = queue_size
|
self._release_ready_queue_size = queue_size
|
||||||
self._loop.call_soon(self._release_ready_future_or_reschedule)
|
self._loop.call_soon(self._release_ready_future_or_reschedule)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue