Smart Proxy Selector
Relevant source files
The following files were used as context for generating this wiki page:
The Smart Proxy Selector automates node selection by evaluating real-time performance metrics through the Prism Engine. It eliminates manual switching by calculating scores based on latency, stability, and success rates to maintain an optimal connection.
Sources: README_en.md, FEATURES.md
Architecture and Scoring Logic
The selector uses an Exponential Moving Average (EMA) scoring system to rank proxy nodes. This mathematical model prioritizes recent performance while maintaining historical context to prevent selection oscillation.
Scoring Components
The system calculates a final score (0-100) using three weighted variables:
- Latency (p90): Measures the 90th percentile of response times to ensure speed.
- Success Rate: Tracks the percentage of successful connections to ensure reliability.
- Stability: Evaluates the consistency of node performance over time.
Sources: README_en.md, FEATURES.md, apps/desktop/src/ui/plugins-smart.js:410-415
Data Flow for Node Selection
The following diagram illustrates how the Prism Engine processes metrics to update node rankings:
The system performs background polling and applies decay to scores using a configurable half-life.
Sources: FEATURES.md, apps/desktop/src/ui/plugins-smart.js:460-475
Configuration Management
You configure the Smart Proxy Selector through the Settings or Advanced pages. The interface allows fine-tuning of the weighting and scheduling parameters.
Weights and Decay Settings
| Option | Default | Description |
|---|---|---|
| Latency Weight | 0.4 | Importance of speed in the final score calculation. |
| Success Weight | 0.4 | Importance of connection reliability. |
| Stability Weight | 0.2 | Importance of performance consistency. |
| Half-life (Hours) | 1.0 | The time required for a score to lose 50% of its weight. |
Sources: apps/desktop/src/ui/settings.js:1460-1475, apps/desktop/src/ui/plugins-smart.js:410-420
Scheduler Parameters
| Option | Range | Description |
|---|---|---|
| Min Test Interval | >= 10s | Minimum time between automated node tests. |
| Max Test Interval | <= 3600s | Maximum time allowed between tests. |
| Base Interval | 300s | The starting frequency for the test scheduler. |
| Adaptive Toggle | On/Off | Enables the system to adjust test frequency based on results. |
Sources: apps/desktop/src/ui/settings.js:1480-1485, apps/desktop/src/ui/plugins-smart.js:421-425
System Integration
The Smart Proxy Selector integrates directly with the Mihomo core and the desktop UI.
User Interface Elements
The implementation includes several UI components defined in the main application structure:
- Smart Toggle: A global switch in the settings to enable/disable the feature.
- Auto Speed Test Toggle: Controls the periodic background testing scheduler.
- Ranking List: A visual display showing node scores with color-coded progress bars (Success: Green, Warning: Yellow, Danger: Red).
- Best Node Shortcut: A UI button to manually trigger the selection of the current top-ranked node.
Sources: apps/desktop/src/index.html:438-445, apps/desktop/src/ui/plugins-smart.js:490-505
Interaction Sequence
The sequence diagram below shows the interaction between the UI, the Smart Selector, and the Proxy Core when a user saves a new configuration:
Operational Functions
The selector provides specific functions for state management and diagnostic testing:
- Validate Config: Checks parameters (e.g., weights must sum to 1.0) before applying changes.
- Trim History: Purges old performance data to maintain a specific record count (default 500).
- Clear History: Deletes all EMA records to restart the learning process.
- Reset Failover: Clears the consecutive failure counts associated with nodes.
Sources: apps/desktop/src/ui/plugins-smart.js:370-400
Summary
The Smart Proxy Selector provides an automated, performance-driven approach to proxy management within Zephyr. By utilizing EMA scoring and an adaptive scheduler, it ensures that traffic is always routed through the most reliable and efficient nodes without requiring manual user intervention.