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 →
StrategyBest ForUse CasePredictabilityInfrastructure Control
Fastest PingReal-time applicationsPerformance-critical apps, gamingMediumLow
Preferred + FallbackDedicated infrastructureCDN with origin fallback, enterprise gatewaysHighMaximum
Round RobinLoad balancingEven distribution across known gatewaysHighHigh
RandomSimple distributionBasic load spreading, testingLowMedium
StaticSingle gatewayDevelopment, specific gateway requirementsMaximumHigh
← Swipe to see more →

How It Works

  1. Ping All Gateways: Send HEAD requests to all available gateways
  2. Measure Response Times: Record the time taken for each gateway to respond
  3. Select Fastest: Choose the gateway with the lowest response time
  4. Cache Results: Optionally cache ping results for a specified duration
  5. 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

ParameterTypeDefaultDescription
timeoutMsnumber500Timeout for ping requests in milliseconds
pingPathstring'/ar-io/info'Path to ping on each gateway
cacheResultsMsnumber0How long to cache ping results (0 = no cache)
loggerLoggerdefaultLoggerOptional 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

  1. Set Appropriate Timeouts: Balance between speed and reliability
  2. Use Caching: Cache ping results to avoid repeated measurements
  3. Monitor Performance: Track which gateways perform best over time
  4. Consider Network Conditions: Results may vary based on user location and network
  5. 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.

Was this page helpful?