orchard
mirrorEvery site I host, in one repo, along with the Cloudflare Tunnel and Caddy that front them. It's all Go, Vite, and SQLite, and it runs on a desktop at home with nothing listening on an inbound port.
blogbuncaddycloudflare-tunneldockergogolanghomelabhtml-templatemonorepoself-hostedseosqlitestatic-sitetypstuptime-monitoringviteweb-analytics
1package main
2
3import (
4 "context"
5 "fmt"
6 "os"
7 "sort"
8 "testing"
9 "time"
10)
11
12// TestProbeTiming is a diagnostic rather than an assertion, and is skipped
13// unless asked for, since it runs the real phasedHop against the live internet.
14//
15// STATUS_PROBE_BENCH=https://blog.bythewood.me go test -run TestProbeTiming -v
16func TestProbeTiming(t *testing.T) {
17 target := os.Getenv("STATUS_PROBE_BENCH")
18 if target == "" {
19 t.Skip("set STATUS_PROBE_BENCH=<url> to run this diagnostic")
20 }
21
22 u, err := parseHTTPURL(target)
23 if err != nil {
24 t.Fatal(err)
25 }
26
27 n := 15
28 var dns, tcp, tls, ttfb, total []int64
29 for i := 0; i < n; i++ {
30 hop, err := phasedHop(context.Background(), u)
31 if err != nil {
32 t.Fatalf("probe %d: %v", i, err)
33 }
34 dns = append(dns, *hop.timings.DNSMS)
35 tcp = append(tcp, *hop.timings.TCPMS)
36 tls = append(tls, *hop.timings.TLSMS)
37 ttfb = append(ttfb, *hop.timings.TTFBMS)
38 total = append(total, hop.timings.TotalMS)
39 time.Sleep(time.Second)
40 }
41
42 med := func(v []int64) int64 {
43 s := append([]int64(nil), v...)
44 sort.Slice(s, func(i, j int) bool { return s[i] < s[j] })
45 return s[len(s)/2]
46 }
47 fmt.Printf("phasedHop against %s, %d samples\n", target, n)
48 for _, p := range []struct {
49 name string
50 v []int64
51 }{{"dns", dns}, {"tcp", tcp}, {"tls", tls}, {"ttfb", ttfb}, {"total", total}} {
52 fmt.Printf(" %-6s median %4dms\n", p.name, med(p.v))
53 }
54}