fix: clarify effective limit debug output
This commit is contained in:
+66
-14
@@ -301,11 +301,9 @@ def get_usage_key(clean_model, api_base=None):
|
|||||||
return f"daily_usage:{date_str}:{clean_model}{suffix}"
|
return f"daily_usage:{date_str}:{clean_model}{suffix}"
|
||||||
|
|
||||||
|
|
||||||
def get_static_limit(clean_model, api_base):
|
def get_static_limit_for_hash(clean_model, current_hash=None):
|
||||||
"""Check static configuration in HARD_DAILY_LIMITS."""
|
"""Check static configuration in HARD_DAILY_LIMITS using an optional endpoint hash."""
|
||||||
current_hash = generate_api_base_hash(api_base)
|
if current_hash:
|
||||||
|
|
||||||
# 1. Exact Match with Hash
|
|
||||||
specific_key = f"{clean_model}:{current_hash}"
|
specific_key = f"{clean_model}:{current_hash}"
|
||||||
if specific_key in HARD_DAILY_LIMITS:
|
if specific_key in HARD_DAILY_LIMITS:
|
||||||
return HARD_DAILY_LIMITS[specific_key]
|
return HARD_DAILY_LIMITS[specific_key]
|
||||||
@@ -328,6 +326,59 @@ def get_static_limit(clean_model, api_base):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def get_static_limit(clean_model, api_base):
|
||||||
|
"""Check static configuration in HARD_DAILY_LIMITS."""
|
||||||
|
current_hash = generate_api_base_hash(api_base) if api_base else None
|
||||||
|
return get_static_limit_for_hash(clean_model, current_hash)
|
||||||
|
|
||||||
|
|
||||||
|
def get_monitored_static_limit(clean_model, model_hashes=None):
|
||||||
|
"""
|
||||||
|
Resolve the static limit for monitored-model debug output.
|
||||||
|
If multiple endpoint hashes exist, show the strictest applicable static cap.
|
||||||
|
"""
|
||||||
|
specific_limits = []
|
||||||
|
|
||||||
|
for current_hash in model_hashes or []:
|
||||||
|
limit_val = get_static_limit_for_hash(clean_model, current_hash)
|
||||||
|
if limit_val is not None:
|
||||||
|
specific_limits.append(float(limit_val))
|
||||||
|
|
||||||
|
if specific_limits:
|
||||||
|
return min(specific_limits)
|
||||||
|
|
||||||
|
return get_static_limit_for_hash(clean_model, None)
|
||||||
|
|
||||||
|
|
||||||
|
def calculate_effective_limit(static_limit, dynamic_limit):
|
||||||
|
"""Return the effective cap after combining static and dynamic limits."""
|
||||||
|
try:
|
||||||
|
if dynamic_limit is None:
|
||||||
|
return float(static_limit) if static_limit is not None else None
|
||||||
|
|
||||||
|
dynamic_limit = float(dynamic_limit)
|
||||||
|
if static_limit is None:
|
||||||
|
return dynamic_limit
|
||||||
|
|
||||||
|
return min(float(static_limit), dynamic_limit)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
return float(static_limit) if static_limit is not None else None
|
||||||
|
|
||||||
|
|
||||||
|
def format_limit_debug_fields(static_limit=None, stable_limit=None, effective_limit=None):
|
||||||
|
"""Render explicit limit labels for debug logs to avoid confusing stable and effective caps."""
|
||||||
|
fields = []
|
||||||
|
|
||||||
|
if static_limit is not None:
|
||||||
|
fields.append(f"StaticLimit={int(float(static_limit)):,}")
|
||||||
|
if stable_limit is not None:
|
||||||
|
fields.append(f"StableLimit={int(float(stable_limit)):,}")
|
||||||
|
if effective_limit is not None:
|
||||||
|
fields.append(f"EffectiveLimit={int(float(effective_limit)):,}")
|
||||||
|
|
||||||
|
return " | ".join(fields) if fields else "EffectiveLimit=unknown"
|
||||||
|
|
||||||
|
|
||||||
def get_effective_limit(clean_model, api_base, current_usage=None):
|
def get_effective_limit(clean_model, api_base, current_usage=None):
|
||||||
"""
|
"""
|
||||||
Calculate effective limit using the Peak-Buffer strategy.
|
Calculate effective limit using the Peak-Buffer strategy.
|
||||||
@@ -350,19 +401,14 @@ def get_effective_limit(clean_model, api_base, current_usage=None):
|
|||||||
if stable_limit_val is not None:
|
if stable_limit_val is not None:
|
||||||
try:
|
try:
|
||||||
dynamic_limit = float(stable_limit_val)
|
dynamic_limit = float(stable_limit_val)
|
||||||
|
effective_limit = calculate_effective_limit(static_limit, dynamic_limit)
|
||||||
# Apply Static Limit override if stricter
|
|
||||||
if static_limit:
|
|
||||||
effective_limit = min(float(static_limit), dynamic_limit)
|
|
||||||
else:
|
|
||||||
effective_limit = dynamic_limit
|
|
||||||
|
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
effective_limit = static_limit
|
effective_limit = calculate_effective_limit(static_limit, None)
|
||||||
else:
|
else:
|
||||||
# Fallback: If daemon hasn't calculated stable limit yet, use old logic?
|
# Fallback: If daemon hasn't calculated stable limit yet, use old logic?
|
||||||
# Or just use static. Safer to wait for daemon.
|
# Or just use static. Safer to wait for daemon.
|
||||||
effective_limit = static_limit
|
effective_limit = calculate_effective_limit(static_limit, None)
|
||||||
|
|
||||||
# Legacy fallback (Optional: Enable if you want immediate loose limits before first sync)
|
# Legacy fallback (Optional: Enable if you want immediate loose limits before first sync)
|
||||||
# dynamic_remaining = redis_client.get(f"limit:dynamic:volcengine:remaining:{clean_model}")
|
# dynamic_remaining = redis_client.get(f"limit:dynamic:volcengine:remaining:{clean_model}")
|
||||||
@@ -1210,8 +1256,14 @@ def active_monitor_loop():
|
|||||||
redis_client.setex(stable_limit_key, 86400, int(stable_limit))
|
redis_client.setex(stable_limit_key, 86400, int(stable_limit))
|
||||||
|
|
||||||
if DEBUG_MODE:
|
if DEBUG_MODE:
|
||||||
|
static_limit = get_monitored_static_limit(
|
||||||
|
target, target_hashes
|
||||||
|
)
|
||||||
|
effective_limit = calculate_effective_limit(
|
||||||
|
static_limit, stable_limit
|
||||||
|
)
|
||||||
print(
|
print(
|
||||||
f"DEBUG: {target} PeakPool={int(current_peak):,} | Limit={int(stable_limit):,} | Usage={int(current_usage):,}",
|
f"DEBUG: {target} PeakPool={int(current_peak):,} | Usage={int(current_usage):,} | {format_limit_debug_fields(static_limit=static_limit, stable_limit=stable_limit, effective_limit=effective_limit)}",
|
||||||
flush=True,
|
flush=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user