httpbench Benchmarks
Prerequisites
Installation
package main
import (
"flag"
"fmt"
"io"
"net/http"
"sync"
"sync/atomic"
"time"
)
func main() {
conc := flag.Int("c", 16, "concurrency (parallel workers)")
dur := flag.Duration("d", 30*time.Second, "duration")
flag.Parse()
urls := flag.Args()
if len(urls) == 0 {
fmt.Println("usage: httpbench -c CONC -d DUR URL1 URL2 ...")
return
}
tr := &http.Transport{
MaxIdleConns: *conc * 2,
MaxIdleConnsPerHost: *conc * 2,
MaxConnsPerHost: *conc * 2,
IdleConnTimeout: 60 * time.Second,
DisableCompression: true,
ForceAttemptHTTP2: false,
}
client := &http.Client{Transport: tr, Timeout: 5 * time.Minute}
var totalBytes, totalReqs int64
var wg sync.WaitGroup
deadline := time.Now().Add(*dur)
t0 := time.Now()
for i := 0; i < *conc; i++ {
wg.Add(1)
go func(gid int) {
defer wg.Done()
j := gid
for time.Now().Before(deadline) {
url := urls[j%len(urls)]
j++
resp, err := client.Get(url)
if err != nil {
continue
}
n, _ := io.Copy(io.Discard, resp.Body)
resp.Body.Close()
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
atomic.AddInt64(&totalBytes, n)
atomic.AddInt64(&totalReqs, 1)
}
}
}(i)
}
wg.Wait()
elapsed := time.Since(t0).Seconds()
fmt.Printf("Reqs: %d Bytes: %.2f GB Time: %.2fs\n",
totalReqs, float64(totalBytes)/1e9, elapsed)
fmt.Printf("→ %.2f GB/s (%.1f Gbps)\n",
float64(totalBytes)/elapsed/1e9, float64(totalBytes)*8/elapsed/1e9)
}Usage
Scenario: Pattern 1 — Single Worker, Local-only Keys
Scenario: Pattern 2 — Single Client, Full Bucket via Redirect
Scenario: Pattern 3 — N Clients × N Workers Paired Aggregate
Troubleshooting
See Also
Last updated