This commit is contained in:
Julien Voisin 2026-11-15 00:33:43 +00:00 • committed by GitHub
commit f2cc821936
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 3 deletions

View file

@ -0,0 +1,18 @@
package reverseproxy
import (
"strconv"
"testing"
)
func BenchmarkHostByHashing(b *testing.B) {
pool := make(UpstreamPool, 0, 8)
for i := 0; i < 8; i++ {
pool = append(pool, &Upstream{Host: new(Host), Dial: "10.0.0." + strconv.Itoa(i) + ":8080"})
}
const key = "192.168.1.100"
b.ReportAllocs()
for b.Loop() {
_ = hostByHashing(pool, key)
}
}

View file

@ -868,9 +868,7 @@ func hostByHashing(pool []*Upstream, s string) *Upstream {
// hash calculates a fast hash based on s.
func hash(s string) uint64 {
h := xxhash.New()
_, _ = h.Write([]byte(s))
return h.Sum64()
return xxhash.Sum64String(s)
}
func loadFallbackPolicy(d *caddyfile.Dispenser) (json.RawMessage, error) {