FastestPingRoutingStrategy
Overview
The FastestPingRoutingStrategy
selects the gateway with the lowest latency by performing HEAD requests to all available gateways and choosing the one that responds fastest. This strategy optimizes for performance by dynamically selecting the most responsive gateway for each request.
Routing Strategy Comparison
← Swipe to see more →
Strategy | Best For | Use Case | Predictability | Infrastructure Control |
---|---|---|---|---|
Fastest Ping | Real-time applications | Performance-critical apps, gaming | Medium | Low |
Preferred + Fallback | Dedicated infrastructure | CDN with origin fallback, enterprise gateways | High | Maximum |
Round Robin | Load balancing | Even distribution across known gateways | High | High |
Random | Simple distribution | Basic load spreading, testing | Low | Medium |
Static | Single gateway | Development, specific gateway requirements | Maximum | High |
← Swipe to see more →
How It Works
- Ping All Gateways: Send HEAD requests to all available gateways
- Measure Response Times: Record the time taken for each gateway to respond
- Select Fastest: Choose the gateway with the lowest response time
- Cache Results: Optionally cache ping results for a specified duration
- Fallback: If all pings fail, fall back to the first available gateway
Configuration
Basic Usage
import { FastestPingRoutingStrategy } from '@ar.io/wayfinder-core'
const strategy = new FastestPingRoutingStrategy({
timeoutMs: 500,
pingPath: '/ar-io/info',
})
With Caching
const strategy = new FastestPingRoutingStrategy({
timeoutMs: 500,
cacheResultsMs: 30000, // Cache ping results for 30 seconds
pingPath: '/ar-io/info',
})
Parameters
Parameter | Type | Default | Description |
---|---|---|---|
timeoutMs | number | 500 | Timeout for ping requests in milliseconds |
pingPath | string | '/ar-io/info' | Path to ping on each gateway |
cacheResultsMs | number | 0 | How long to cache ping results (0 = no cache) |
logger | Logger | defaultLogger | Optional logger instance |
Integration with Wayfinder
import { Wayfinder, FastestPingRoutingStrategy } from '@ar.io/wayfinder-core'
const wayfinder = new Wayfinder({
routingSettings: {
strategy: new FastestPingRoutingStrategy({
timeoutMs: 500,
cacheResultsMs: 30000, // Cache results for 30 seconds
}),
},
})
Use Cases
Performance-Critical Applications
Perfect for applications where response time is crucial and you want the fastest possible data access.
const performanceStrategy = new FastestPingRoutingStrategy({
timeoutMs: 500,
cacheResultsMs: 10000, // Short cache for frequent updates
})
Gaming and Real-Time Apps
Ideal for gaming applications or real-time data feeds where latency matters most.
const gamingStrategy = new FastestPingRoutingStrategy({
timeoutMs: 300, // Very fast timeout
cacheResultsMs: 5000, // Frequent re-evaluation
})
Load Testing and Benchmarking
Useful for testing gateway performance and identifying the fastest gateways in your region.
const benchmarkStrategy = new FastestPingRoutingStrategy({
timeoutMs: 1000,
cacheResultsMs: 0, // No caching for accurate measurements
})
Best Practices
- Set Appropriate Timeouts: Balance between speed and reliability
- Use Caching: Cache ping results to avoid repeated measurements
- Monitor Performance: Track which gateways perform best over time
- Consider Network Conditions: Results may vary based on user location and network
- Combine with Fallback: Use with other strategies for high availability
The FastestPingRoutingStrategy
is ideal for applications where performance and low latency are the primary concerns.