Skip to content

Latest commit

 

History

History
68 lines (48 loc) · 1.96 KB

File metadata and controls

68 lines (48 loc) · 1.96 KB

@smithy/undici-http-handler

NPM version NPM downloads

Smithy-compatible HTTP handler backed by Node.js undici.

Usage

Use UndiciHttpHandler as a Smithy-compatible request handler for generated clients. It uses undici for HTTP transport, and accepts optional undici Dispatcher to set up transport details.

Basic example

import { S3 } from "@aws-sdk/client-s3";
import { UndiciHttpHandler } from "@smithy/undici-http-handler";

const client = new S3({
  requestHandler: new UndiciHttpHandler(),
});

client.listBuckets().then(console.log);

Configuring undici Dispatcher

Pass an undici Dispatcher to configure transport behavior such as connection pooling and timeouts.

import { S3 } from "@aws-sdk/client-s3";
import { UndiciHttpHandler } from "@smithy/undici-http-handler";
import { Agent } from "undici";

const dispatcher = new Agent({
  connections: 50,
  headersTimeout: 3000,
  bodyTimeout: 3000,
  connect: {
    timeout: 3000,
  },
});

const client = new S3({
  requestHandler: new UndiciHttpHandler({ dispatcher }),
});

client.listBuckets().then(console.log);

Benchmarks

Our benchmark spin up a local HTTP server and runs two scenarios:

  • 10 sequential GETs – measures per-request latency when requests are issued one after another.
  • 50 concurrent GETs – measures throughput under parallel load using Promise.all.

The results show UndiciHttpHandler spends 20%-30% less time in request handling as compared to NodeHttpHandler from @smithy/node-http-handler.

We recommend running benchmarks for your own use case on your own setup, as results will vary depending on workload, network conditions, and environment.