client_per_worker

command
v1.18.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: BSD-3-Clause Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package main is ./example/concurrency with one change: every worker builds its own tls-client instead of sharing one. All workers still request the same host, so the two programs are directly comparable.

What changes with a client per worker:

  • Each client keeps its own connection pool, so the workers cannot share a connection. The dial counter below shows one dial per worker rather than one for the whole run, which means one TLS handshake per worker too.
  • Each client keeps its own TLS session cache, so nothing is resumed across workers.
  • The fixed cost of a client is paid N times. The line after the clients are built reports what that costs on the heap.

Sharing one client is the better default for this workload. Build a client per worker when the workers need to differ - a proxy or profile each, say - not to get concurrency, which a single client already handles.

Each worker decodes the response and then waits a couple of seconds, so the target sees a trickle of traffic rather than a load test.

Run:

go run ./example/client_per_worker
go run ./example/client_per_worker -goroutines 8 -requests 10
go run ./example/client_per_worker -memprofile heap.out

Inspect a heap profile with: go tool pprof heap.out

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL