perf: allow disabling websocket per-message-deflate (#28613)
With delta streaming most websocket frames are tiny per-token deltas, and per-message-deflate pays zlib work on every outgoing frame per subscriber for near-zero gain there; under heavy streaming that shows up as measurable server CPU. The frames that still benefit are the rare large ones (final message, sources), and even a 100k token message is only a few hundred KB uncompressed, which any network delivers without noticeable delay. UVICORN_WS_PER_MESSAGE_DEFLATE=false (default true, current behavior) disables the extension in every entry point: open-webui serve and dev, start.sh both invocations, start_windows.bat and dev.sh. Verified against a running instance: with the flag off the server declines the client-offered permessage-deflate extension, with defaults it still negotiates it.
This commit is contained in:
1 parent
97466deea1
commit
bf08835d6f
5 files changed
+13
-5
No files matched your search
@@ -74,7 +74,7 @@ def serve(
|
||||
os.environ['LD_LIBRARY_PATH'] = ':'.join(LD_LIBRARY_PATH)
|
||||
|
||||
import open_webui.main # noqa: F401
|
||||
from open_webui.env import UVICORN_WORKERS # Import the workers setting
|
||||
from open_webui.env import UVICORN_WORKERS, UVICORN_WS_PER_MESSAGE_DEFLATE
|
||||
|
||||
# On Windows, uvicorn's default loop factory hardcodes ProactorEventLoop,
|
||||
# which is incompatible with psycopg v3 async. Setting loop='none' lets
|
||||
@@ -87,6 +87,7 @@ def serve(
|
||||
port=port,
|
||||
forwarded_allow_ips='*',
|
||||
workers=UVICORN_WORKERS,
|
||||
ws_per_message_deflate=UVICORN_WS_PER_MESSAGE_DEFLATE,
|
||||
loop=loop,
|
||||
)
|
||||
|
||||
@@ -97,12 +98,15 @@ def dev(
|
||||
port: int = 8080,
|
||||
reload: bool = True,
|
||||
):
|
||||
from open_webui.env import UVICORN_WS_PER_MESSAGE_DEFLATE
|
||||
|
||||
uvicorn.run(
|
||||
'open_webui.main:app',
|
||||
host=host,
|
||||
port=port,
|
||||
reload=reload,
|
||||
forwarded_allow_ips='*',
|
||||
ws_per_message_deflate=UVICORN_WS_PER_MESSAGE_DEFLATE,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -443,6 +443,9 @@ try:
|
||||
except (ValueError, TypeError):
|
||||
UVICORN_WORKERS = 1
|
||||
|
||||
# tiny delta-stream frames make per-frame websocket compression CPU-bound, allow opting out (true/false)
|
||||
UVICORN_WS_PER_MESSAGE_DEFLATE = os.getenv('UVICORN_WS_PER_MESSAGE_DEFLATE', 'True').lower() == 'true'
|
||||
|
||||
####################################
|
||||
# WEBSOCKET SUPPORT
|
||||
####################################
|
||||
|
||||
Reference in new issue
Block a user