fix: reduce intermittent 503s on stats page and API requests

This commit is contained in:
Jonathan Caicedo 2026-05-20 21:52:28 -04:00
parent e0bb2d925e
commit e2074c1921
3 changed files with 18 additions and 18 deletions

View file

@ -419,7 +419,8 @@ class ChannelStatus:
info['stream_name'] = stream_name
# Add data throughput information to basic info
total_bytes_bytes = proxy_server.redis_client.hget(metadata_key, ChannelMetadataField.TOTAL_BYTES)
# TOTAL_BYTES is already present in the hgetall result — avoid a redundant round-trip
total_bytes_bytes = metadata.get(ChannelMetadataField.TOTAL_BYTES)
if total_bytes_bytes:
total_bytes = int(total_bytes_bytes)
info['total_bytes'] = total_bytes
@ -460,24 +461,25 @@ class ChannelStatus:
client_key = RedisKeys.client_metadata(channel_id, client_id)
# Fetch only the fields we need in one round-trip (hmget returns a list
# in the same order as the requested keys; values are None if absent)
ua, ip, connected_at, user_id = proxy_server.redis_client.hmget(
client_key, 'user_agent', 'ip_address', 'connected_at', 'user_id'
)
client_info = {
'client_id': client_id,
'user_agent': ua,
}
user_agent_bytes = proxy_server.redis_client.hget(client_key, 'user_agent')
client_info['user_agent'] = user_agent_bytes
if ip:
client_info['ip_address'] = ip
ip_address_bytes = proxy_server.redis_client.hget(client_key, 'ip_address')
if ip_address_bytes:
client_info['ip_address'] = ip_address_bytes
if connected_at:
client_info['connected_at'] = float(connected_at)
connected_at_bytes = proxy_server.redis_client.hget(client_key, 'connected_at')
if connected_at_bytes:
client_info['connected_at'] = float(connected_at_bytes)
user_id_bytes = proxy_server.redis_client.hget(client_key, 'user_id')
if user_id_bytes:
client_info['user_id'] = user_id_bytes
if user_id:
client_info['user_id'] = user_id
output_format = proxy_server.redis_client.hget(client_key, 'output_format')
client_info['output_format'] = output_format or 'mpegts'

View file

@ -21,6 +21,8 @@ server {
location / {
include uwsgi_params;
uwsgi_pass unix:/app/uwsgi.sock;
uwsgi_read_timeout 300s;
uwsgi_send_timeout 300s;
}
location /assets/ {

View file

@ -239,11 +239,7 @@ const StatsPage = () => {
}
}, [refreshInterval, fetchChannelStats, fetchVODStats]);
// Fetch initial stats on component mount (for immediate data when navigating to page)
useEffect(() => {
fetchChannelStats();
fetchVODStats();
}, [fetchChannelStats, fetchVODStats]);
// Initial fetch is handled by the polling useEffect above (it fetches immediately on mount)
useEffect(() => {
console.log('Processing channel stats:', channelStats);