Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Longest-Match Router #730

Merged
merged 12 commits into from
Aug 15, 2024
Merged

Longest-Match Router #730

merged 12 commits into from
Aug 15, 2024

Conversation

jranson
Copy link
Member

@jranson jranson commented Aug 12, 2024

This patch replaces the embedded gorrila/mux router with a new Longest-Match router. The LM Router is made for high-performance proxies in that it only uses basic string prefix matching, with no path parameter parsing or use of regular expressions. Some notes:

  • Path Prefix Matching does not require a trailing / separator, so /my/path-is-kinda-long will match a route of /my/path. Include the trailing / in the route config to avoid this as needed.
  • The router auto-sorts prefix path routes from longest to shortest each time a route is registered, thus the sorting logic previously needed to work with Gorilla has been removed from /pkg/routing/routing.go.
  • Route paths can be registered multiple times, with the last registration winning on a per-method basis.
  • For routers that don't use host header or path prefix matching (e.g., the pprof router), those mechanisms can be disabled on the router itself for optimal route matching performance.

Key Files:

  • ./pkg/router/router.go
  • ./pkg/router/route/route.go
  • ./pkg/router/lm/lm.go
  • ./pkg/router/lm/lm_test.go
  • ./pkg/routing/routing.go

Benchmarks:

BenchmarkGorillaMux_GithubStatic    705271   1606.00 ns/op     784 B/op     7 allocs/op
BenchmarkLMRouter_GithubStatic    21476557     55.63 ns/op       0 B/op     0 allocs/op

BenchmarkGorillaMux_GPlusStatic    2740124    438.00 ns/op     784 B/op     7 allocs/op
BenchmarkLMRouter_GPlusStatic     68944386     16.97 ns/op       0 B/op     0 allocs/op

BenchmarkGorillaMux_ParseStatic    2073722    575.70 ns/op     784 B/op     7 allocs/op
BenchmarkLMRouter_ParseStatic     47952765     24.58 ns/op       0 B/op     0 allocs/op

BenchmarkGorillaMux_StaticAll         3350    348207 ns/op  123092 B/op  1099 allocs/op
BenchmarkLMRouter_StaticAll         134061      9001 ns/op       0 B/op     0 allocs/op

@coveralls
Copy link

coveralls commented Aug 12, 2024

Pull Request Test Coverage Report for Build 10357898241

Details

  • 235 of 292 (80.48%) changed or added relevant lines in 15 files are covered.
  • 4 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+1.3%) to 90.273%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/proxy/handlers/rpc/rpc.go 0 1 0.0%
pkg/proxy/handlers/clickhouse/clickhouse.go 0 2 0.0%
pkg/proxy/handlers/influxdb/influxdb.go 0 2 0.0%
pkg/proxy/handlers/prometheus/prometheus.go 0 2 0.0%
pkg/proxy/methods/methods.go 0 4 0.0%
pkg/proxy/handlers/purge.go 0 8 0.0%
pkg/httpserver/httpserver.go 0 16 0.0%
pkg/httpserver/listeners.go 0 22 0.0%
Files with Coverage Reduction New Missed Lines %
pkg/cache/bbolt/bbolt.go 4 88.55%
Totals Coverage Status
Change from base Build 9143081403: 1.3%
Covered Lines: 17253
Relevant Lines: 19112

💛 - Coveralls

@jranson jranson merged commit 86df65a into trickstercache:main Aug 15, 2024
5 checks passed
@jranson jranson deleted the lm-router branch August 15, 2024 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants