mirror of
https://github.com/open-webui/open-webui.git
synced 2026-12-03 02:07:46 -05:00
perf: start up without waiting for tool and terminal servers to answer (#34866)
Open WebUI stayed offline at startup until every configured tool server and terminal server had answered or timed out, one after the other, so a single unreachable server kept the app and its health check down for over 20 seconds. Startup now kicks off that fetch in the background and starts serving right away. Anything that needs the tool server details before the fetch lands loads them on demand, as it already did when nothing was cached. If an admin saves the tool or terminal server settings while the startup fetch is still waiting on an unreachable server, the startup fetch can finish last and put back the old list until the next save. <table> <tr><th>Startup time (until the app answers)</th><th>Before</th><th>After</th></tr> <tr><td>Tool and terminal server unreachable</td><td>23.0 s</td><td>0.6 s</td></tr> <tr><td>Tool and terminal server answering in 300 ms</td><td>1.35 s</td><td>0.6 s</td></tr> </table> Fixes #34865
This commit is contained in:
1 parent
5e61d4ef03
commit
6f0a52c1de
1 file changed
+18
-11
+18
-11
@@ -499,18 +499,22 @@ async def lifespan(app: FastAPI):
|
||||
}
|
||||
)
|
||||
|
||||
log.info('Initializing tool servers...')
|
||||
try:
|
||||
await set_tool_servers(mock_request)
|
||||
log.info('Initialized %s tool server(s)', len(app.state.TOOL_SERVERS))
|
||||
except Exception as e:
|
||||
log.warning(f'Failed to initialize tool servers at startup: {e}')
|
||||
async def prefetch_tool_servers():
|
||||
log.info('Initializing tool servers...')
|
||||
try:
|
||||
await set_tool_servers(mock_request)
|
||||
log.info('Initialized %s tool server(s)', len(app.state.TOOL_SERVERS))
|
||||
except Exception as e:
|
||||
log.warning(f'Failed to initialize tool servers at startup: {e}')
|
||||
|
||||
try:
|
||||
await set_machines(mock_request)
|
||||
log.info('Initialized %s terminal server(s)', len(app.state.MACHINES))
|
||||
except Exception as e:
|
||||
log.warning(f'Failed to initialize terminal servers at startup: {e}')
|
||||
try:
|
||||
await set_machines(mock_request)
|
||||
log.info('Initialized %s terminal server(s)', len(app.state.MACHINES))
|
||||
except Exception as e:
|
||||
log.warning(f'Failed to initialize terminal servers at startup: {e}')
|
||||
|
||||
# Don't hold startup on unreachable servers
|
||||
app.state.prefetch_tool_servers = asyncio.create_task(prefetch_tool_servers())
|
||||
|
||||
# Mark application as ready to accept traffic from a startup perspective.
|
||||
if license_task:
|
||||
@@ -540,6 +544,9 @@ async def lifespan(app: FastAPI):
|
||||
if hasattr(app.state, 'redis_task_heartbeat'):
|
||||
app.state.redis_task_heartbeat.cancel()
|
||||
|
||||
if hasattr(app.state, 'prefetch_tool_servers'):
|
||||
app.state.prefetch_tool_servers.cancel()
|
||||
|
||||
app.state.periodic_socket_authentication.cancel()
|
||||
app.state.periodic_usage_pool_cleanup.cancel()
|
||||
app.state.periodic_session_pool_cleanup.cancel()
|
||||
|
||||
Reference in new issue
Block a user