# http_head

How long an HTTPS `HEAD` metadata request to S3 takes, from the box to the endpoint its Service
names, over a new connection per request or over one kept connection, one request at a time on
one thread, with exponential pauses of mean `gap_mean_ms`. Supports SigV4 (`sigv4`), S3 Express
One Zone (`s3express`), and unsigned (`none`) requests, plus optional distinct-key pooling via
`key_pool_size`.

## What a figure means

HTTPS `HEAD` requests to S3, one request per sample (`repetitions: 1`). The binary resolves DNS
directly over UDP, connects TCP, negotiates TLS 1.2/1.3 with statically linked AWS-LC, signs
each request before the sample clock starts, writes HTTP/1.1 by hand, and stops parsing right
after the response header block (`\r\n\r\n`) since `HEAD` responses carry no body.

Sample 0 is a warmup; counted samples `1..LM_SAMPLES` follow. Under Method `runs` v1, a counted
Run (exit 0) yields one figure: the median total `HEAD` latency in nanoseconds
(`time_per_repetition_ns`). Each request also emits phase timestamps (`name_resolved`,
`connection_opened`, `connection_secured`, `request_sent`, `first_byte`, `response_headers`,
`http_op_ended` or `http_op_failed`) with thread `cpu_ns` and `tcp_info`.

## What a figure does not show

- One thread issues one request at a time with pauses of mean `gap_mean_ms`; it does not measure
  S3 metadata throughput under concurrency.
- With `connection` `reused`, DNS, TCP, and TLS setup happen outside the sample.
- No object payload bytes are transferred; payload read latency is measured by `http_get`.
- Method `runs` v1 reports the per-Run median, not the tail of individual requests.

## Parameters

The benchmark's Series and their figures are listed at
[https://api.ledgermath.com/v1/benchmarks/http_head.json](https://api.ledgermath.com/v1/benchmarks/http_head.json).

| Variable | Quick default | Meaning |
|---|---|---|
| `LM_PARAM_KEY` | `http_get/v1/4096` | Base object key (1 to 1024 bytes, no leading `/`) |
| `LM_PARAM_KEY_POOL_SIZE` | optional (`0`) | When `> 0`, request `k` targets `<key>/%04llu` with `k % key_pool_size` |
| `LM_PARAM_CONNECTION` | `new` | `new` (fresh DNS/TCP/TLS per request) or `reused` (single kept connection) |
| `LM_PARAM_GAP_MEAN_MS` | `10` | Mean exponential inter-request pause in milliseconds (fixed seed) |
| `LM_PARAM_BUDGET_SECONDS` | `60` | Wall-clock budget before ending the Run early |
| `LM_PARAM_TIMEOUT_MS` | `5000` | Socket read/write/connect timeout in milliseconds |
| `LM_PARAM_CA_FILE` | `/etc/pki/tls/certs/ca-bundle.crt` | PEM CA bundle for TLS certificate verification |
| `LM_PARAM_RESOLV_CONF` | `/etc/resolv.conf` | Resolver file (first IPv4 `nameserver`, optional `:port`) |
| `LM_PARAM_AUTH` | `sigv4` | `sigv4` (service `s3`), `s3express` (service `s3express`, `x-amz-s3session-token`), or `none` |

Service inputs: `LM_SERVICE_ENDPOINT` (`https://<host>[:<port>]`), and for signed modes
`LM_SERVICE_REGION`, `LM_SERVICE_AWS_ACCESS_KEY_ID`, `LM_SERVICE_AWS_SECRET_ACCESS_KEY`, and
optional `LM_SERVICE_AWS_SESSION_TOKEN`.

## Observed values

Opening `observed`: `tls_library`, `tls_library_source_sha256`, `tls_offer`, `client_hello`,
`ca_file_sha256`, `ca_certificates_loaded`, `ca_certificates_rejected`, `resolver`,
`cpu_clock_read_ns`, and `key_pool_size` (only when `LM_PARAM_KEY_POOL_SIZE` is set).

Closing `observed`: `requests_made`, `requests_not_made`, `ended_early`, `connections_opened`,
`connection_setups_failed`, `responses`, `responses_2xx`, `requests_failed`, `statuses`,
`failures`, `fields_withheld`, and `lines_withheld`.

## Findings

Against the local stand-in, `HEAD` avoids all body framing and transfers only response headers,
isolating S3 control/metadata latency and TLS round-trip overhead. Keep-alive is evaluated from
the HTTP version and `Connection` header even when `Content-Length` is omitted.

## How it works

1. Memory dumps are disabled (`RLIMIT_CORE = 0`, `PR_SET_DUMPABLE = 0`) and credentials are
   registered with `lm_lines` before any network I/O so no secret or signature reaches stdout.
2. Each request is built and signed before `sample_started`.
3. `lm_http_feed` parses the response header block and stops immediately at `\r\n\r\n`; any
   trailing bytes in the same TLS record fail the request as a protocol error (`http_op_failed`).
4. `http_op_ended` records `status`, `content_length`, `etag`, `cpu_ns`, and `tcp_info`.
5. `verified` is the first 64 bits of SHA-256 over the status, `Content-Length`, and `ETag` of
   every 2xx response in order.
6. Exit codes: `0` all 2xx, `1` fatal setup error, `2` usage error, `3` stdout error, `4` any
   non-2xx, failed request, setup failure, or early budget/unreachable stop.

## Building and testing

```bash
make -C benchmarks/http_head AWS_LC_ARCHIVE=/path/to/aws-lc.tar.gz
```

Produces `benchmarks/http_head/build/static/http_head`. Verified end-to-end against the local
HTTPS stand-in in `tests/s3-benchmarks.test.ts`.

---

Authorship: Written entirely by AI.
