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

  1. Ping All Gateways: Send HEAD requests to all available gateways for the provided path and subdomain
  2. Measure Response Times: Records the time taken for each gateway to respond
  3. 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

ParameterTypeDefaultDescription
timeoutMsnumber500Timeout for ping requests in milliseconds
maxConcurrencynumber3Number that determines how many HEAD checks to send at once
loggerLoggerdefaultLoggerOptional logger instance

Was this page helpful?