ExLLM.Infrastructure.CircuitBreaker.Adaptive (ex_llm v0.8.1)

View Source

Adaptive circuit breaker that automatically adjusts failure thresholds based on error patterns.

This module runs as a GenServer that periodically analyzes circuit performance and adjusts thresholds to optimize fault tolerance and availability.

Configuration

config :ex_llm, :circuit_breaker,
  adaptive: %{
    enabled: true,
    update_interval: 60_000,       # 1 minute
    min_calls_for_adaptation: 10,  # Minimum calls before adapting
    adaptation_factor: 0.1,        # How aggressively to adapt (0.0-1.0)
    min_threshold: 2,              # Minimum failure threshold
    max_threshold: 20              # Maximum failure threshold
  }

Adaptation Algorithm

The adaptive algorithm analyzes recent circuit performance and adjusts thresholds:

  • High error rate (>30%): Decrease threshold for faster fault detection
  • Moderate error rate (10-30%): Maintain current threshold
  • Low error rate (<10%): Increase threshold for more tolerance
  • Very low error rate (<2%): Significantly increase threshold

Adjustments are gradual and bounded by min/max limits to prevent oscillation.

Summary

Functions

Returns a specification to start this module under a supervisor.

Get adaptive metrics for a specific circuit.

Get configuration for the adaptive system.

Start the adaptive circuit breaker GenServer.

Update configuration for the adaptive system.

Manually trigger threshold updates for all circuits.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_circuit_metrics(circuit_name)

Get adaptive metrics for a specific circuit.

get_config()

Get configuration for the adaptive system.

start_link(opts \\ [])

Start the adaptive circuit breaker GenServer.

update_config(new_config)

Update configuration for the adaptive system.

update_thresholds()

Manually trigger threshold updates for all circuits.