perf: Implement 2-stage map routing for faster domain lookup
Split domain routing into two stages for improved performance: - Stage 1: map_str for exact domains (O(log n) using ebtree) - Stage 2: map_dom for wildcards only (O(n) but small set) Wildcards now stored in separate wildcards.map file. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -58,8 +58,11 @@ frontend http_front
|
||||
# use_backend acme_backend if is_acme
|
||||
# http-request redirect scheme https unless is_acme
|
||||
|
||||
# Map-based dynamic routing (same as HTTPS)
|
||||
use_backend %[req.hdr(host),lower,map_dom(/usr/local/etc/haproxy/domains.map)] if { req.hdr(host),lower,map_dom(/usr/local/etc/haproxy/domains.map) -m found }
|
||||
# 2-stage map-based routing for performance:
|
||||
# Stage 1: Exact match with map_str (O(log n) - fast, uses ebtree)
|
||||
use_backend %[req.hdr(host),lower,map_str(/usr/local/etc/haproxy/domains.map)] if { req.hdr(host),lower,map_str(/usr/local/etc/haproxy/domains.map) -m found }
|
||||
# Stage 2: Wildcard fallback with map_dom (O(n) - slower, but only for wildcards)
|
||||
use_backend %[req.hdr(host),lower,map_dom(/usr/local/etc/haproxy/wildcards.map)] if { req.hdr(host),lower,map_dom(/usr/local/etc/haproxy/wildcards.map) -m found }
|
||||
|
||||
default_backend default_backend
|
||||
|
||||
@@ -75,8 +78,11 @@ frontend https_front
|
||||
acl is_tailscale src 100.64.0.0/10
|
||||
http-request deny deny_status 401 if is_mcp !valid_token !is_tailscale
|
||||
|
||||
# Map-based dynamic routing (no reload needed for domain changes)
|
||||
use_backend %[req.hdr(host),lower,map_dom(/usr/local/etc/haproxy/domains.map)] if { req.hdr(host),lower,map_dom(/usr/local/etc/haproxy/domains.map) -m found }
|
||||
# 2-stage map-based routing for performance:
|
||||
# Stage 1: Exact match with map_str (O(log n) - fast, uses ebtree)
|
||||
use_backend %[req.hdr(host),lower,map_str(/usr/local/etc/haproxy/domains.map)] if { req.hdr(host),lower,map_str(/usr/local/etc/haproxy/domains.map) -m found }
|
||||
# Stage 2: Wildcard fallback with map_dom (O(n) - slower, but only for wildcards)
|
||||
use_backend %[req.hdr(host),lower,map_dom(/usr/local/etc/haproxy/wildcards.map)] if { req.hdr(host),lower,map_dom(/usr/local/etc/haproxy/wildcards.map) -m found }
|
||||
|
||||
default_backend default_backend
|
||||
|
||||
|
||||
Reference in New Issue
Block a user