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.
How It Works
- Ping All Gateways: Send HEAD requests to all available gateways for the provided path and subdomain
- Measure Response Times: Records the time taken for each gateway to respond
- Select Fastest: Choose the gateway with the lowest response time
Basic Usage
import { FastestPingRoutingStrategy } from '@ar.io/wayfinder-core'
const strategy = new FastestPingRoutingStrategy({
timeoutMs: 500,
maxConcurrency: 3,
})
const selectedGateway = await strategy.selectGateawy({
path: '/'
subdomain: 'ardrive',
gateways: ['https://arweave.net', 'htps://permagate.io', 'https://arweave.dev']
})
// does a HEAD request on each and selects the one that responded the fastest
Parameters
Parameter | Type | Default | Description |
---|---|---|---|
timeoutMs | number | 500 | Timeout for ping requests in milliseconds |
maxConcurrency | number | 3 | Number that determines how many HEAD checks to send at once |
logger | Logger | defaultLogger | Optional logger instance |
Related
- PreferredWithFallbackRoutingStrategy: Static gateway configuration
- RoundRobinRoutingStrategy: Even distribution across gateways
- RandomRoutingStrategy: Randomized gateway selection
- StaticRoutingStrategy: Always use a single, fixed gateway