INNER CODE UNIT · Go

sampleTTFT

bhope/hedge · benchmark/streaming/main.go:94

func sampleTTFT() time.Duration {
	if rand.Float64() < cacheMissRate {
		return time.Duration(math.Exp(missMu + missSigma*rand.NormFloat64()))
	}
	return time.Duration(math.Exp(hitMu + hitSigma*rand.NormFloat64()))
}

// ── test servers ────────────────────────────────────────────────────────────

// newStreamingServer flushes 200 OK headers immediately then writes the first
// body byte only after the TTFT delay. This separates header arrival from
// first-token time and makes TTFB measurement produce near-zero observations.
func newStreamingServer(hits *atomic.Int64) *httptest.Server {
	return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		hits.Add(1)
		w.WriteHeader(http.StatusOK)
		if f, ok := w.(http.Flusher); ok {
			f.Flush()

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…