Home

Awesome

go-router-benchmark

Compare the performance of routers built with golang.

Table of contents

Listed routers

Since net/http#ServeMux does not have the capability to support path param route, only the static route test case is comparable.

Motivation

I have implemented a router called bmf-san/goblin, and I created this repository to compare it with other routers and get hints on how to improve bmf-san/goblin.

Another reason is that julienschmidt/go-http-routing-benchmark seems to have stopped being maintained, so I wanted to have a benchmarker for the router that I could manage myself.

Benchmark test

This benchmark tests is not a perfect comparison of HTTP Router performance. The reasons are as follows

Although the benchmark test is based on a specific case, it is possible to see some trends in performance differences.

Performance measurements will be made on the routing process of the HTTP Router. More specifically, we will test the ServeHTTP function of http#Handler.

We do not measure the performance of the process that defines the routing of the HTTP Router. The process of defining routing is the process of registering data for the routing process. For example, the code for net/http is as follows.

package main

import (
	"fmt"
	"net/http" )
)

func handler(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, "Hello World")
}

func main() {
	mux := http.NewServeMux()
	mux.HandleFunc("/", handler) // here
	ListenAndServe(":8080", mux)
}

We believe that the part that handles routing is called more often than the part that defines routing, and thus accounts for the majority of the HTTP Router's performance.

Static route

A static route is a route without variable parameters such as /foo/bar.

Static route measures performance by benchmarking routing tests with the following three input values.

Path parameter route

A path parameter route is a route with variable parameters such as /foo/:bar.

In path parameter route, we perform benchmark routing tests with the following three input values to measure the performance.

Since different HTTP Routers have different ways of expressing parameters, there are several cases where another symbol is used in addition to :.

Run benchmark tests

CommandDescription
test-benchmarkRun benchmark tests.
test-benchmark-staticRun benchmark tests only static.
test-benchmark-pathparamRun benchmark tests only pathparam.
test-benchmark-by-regexpRun benchmark tests using regexp. ex. make test-benchmark-by-regexp EXP=Goblin, make test-benchmark-by-name EXP=StaticRoutes1

Results

Benchmark results are published in a spreadsheet.

<Public>go-router-benchmark

Benchmark system

Static routes

time

timestatic-routes-rootstatic-routes-1static-routes-5static-routes-10
servemux278317201989195048384662508039
goblin7815128839773182100532894709226
httprouter144303050134171820129710535100000000
chi7614604773040375582886086882
gin44050909434011414317640441443738
bunrouter100000000796997967636866971506602
httptreemux8800170848676965200714769065
beegomux312333932612012684186744674050
gorillamux3210363313841829148682262861
bon10000000010000000010000000097284812
denco134409880134490919133387552131848746
echo65374460606132043992657823414919
gocraftweb1686422164493614601921208860
gorouter89735841648692473183382618472964
ozzorouting47574130455421643550755327385978
techbook13-sample10733499774386531669881523804

time.png

Graph - time

nsop

nsopstatic-routes-rootstatic-routes-1static-routes-5static-routes-10
servemux43.0960.18226.1457.7
goblin15.3430.23119.7265.5
httprouter8.3288.9319.29110.58
chi160159.4159.5183.6
gin27.6627.6827.8129.56
bunrouter10.6315.2415.7218.61
httptreemux137.1140.7183.2270.6
beegomux38.2246.08143.6251.2
gorillamux374.9380.8411.7550.8
bon10.6810.4610.710.93
denco9.0278.9868.9629.076
echo18.5419.7330.1450.64
gocraftweb709.57188261024
gorouter13.718.4637.4971.49
ozzorouting25.426.3133.0143.9
techbook13-sample115.3154.8379.8779.6

nsop.png

Graph - nsop

bop

bopstatic-routes-rootstatic-routes-1static-routes-5static-routes-10
servemux0000
goblin0000
httprouter0000
chi336336336336
gin0000
bunrouter0000
httptreemux360360360360
beegomux32323232
gorillamux784784784784
bon0000
denco0000
echo0000
gocraftweb288288352432
gorouter0000
ozzorouting0000
techbook13-sample336340464904

bop.png

Graph - bop

allocs

allocsstatic-routes-rootstatic-routes-1static-routes-5static-routes-10
servemux0000
goblin0000
httprouter0000
chi2222
gin0000
bunrouter0000
httptreemux3333
beegomux1111
gorillamux7777
bon0000
denco0000
echo0000
gocraftweb6666
gorouter0000
ozzorouting0000
techbook13-sample231121

allocs.png

Graph - allocs

Pathparams routes

time

timepathparam-routes-1pathparam-routes-5pathparam-routes-10
servemux987961530956321716556
goblin554342732887812148358
httprouter33200109125201927242321
chi412425325609721262286
gin359341041836131610710009
bunrouter59392094105879975214822
httptreemux376403520229781000000
beegomux395367825862651457932
gorillamux2004242961486521152
bon756555753220814093870
denco2467984697089246409720
echo46360610152374988387311
gocraftweb1287634960009717404
gorouter620998942951803322506
ozzorouting35132318156356719333058
techbook13-sample34363511000000647994

time.png

Graph - time

nsop

nsoppathparam-routes-1pathparam-routes-5pathparam-routes-10
servemux120.8383.8697.1
goblin217.7367.2558
httprouter36.396.27155.5
chi304.8468.1961.9
gin33.4464.27104.1
bunrouter20.3115.1229.9
httptreemux316.65991080
beegomux316.7466.9826
gorillamux609.512152327
bon159.2226.9293.9
denco49.59123.2187
echo26.1778.84143.4
gocraftweb936.612281654
gorouter196.1277.9364.7
ozzorouting33.9977.03129
techbook13-sample355.310451813

nsop.png

Graph - nsop

bop

boppathparam-routes-1pathparam-routes-5pathparam-routes-10
servemux16240496
goblin360360360
httprouter32160320
chi6726721254
gin000
bunrouter000
httptreemux7129361774
beegomux7047041286
gorillamux108811521815
bon336336336
denco32160320
echo000
gocraftweb6569441862
gorouter392520680
ozzorouting000
techbook13-sample46410001824

bop.png

Graph - bop

allocs

allocspathparam-routes-1pathparam-routes-5pathparam-routes-10
servemux145
goblin333
httprouter111
chi445
gin000
bunrouter000
httptreemux6911
beegomux556
gorillamux889
bon222
denco111
echo000
gocraftweb91214
gorouter444
ozzorouting000
techbook13-sample103359

allocs.png

Graph - allocs

Conclusion

It can be seen that the HTTP Router with better performance has less performance degradation in each test case. This is a clear trend that shows that the implementation is optimized.

The better performing HTTP Route seems to employ a more sophisticated tree structure. Echo,gin,httprouter,bon,chi seem to adopt Radix tree (Patricia trie) and denco double array.

As for my implementation of goblin, it is a proprietary extension of the trie tree, which is not very well optimized, and I could clearly see that its performance is lower than the other HTTP Routers. (I will try my best to improve it...)

I don't think it is reasonable to assume that HTTP Router should not be adopted because of its seemingly poor performance in this benchmark result.

Some HTTP Routers are considered to be highly functional and easy to use, even if their performance is a little lower.

Some of the HTTP Routers listed here are no longer under development.

Since goblin has no plans to stop development for the time being, please try it if you like!

Contribution

We are always accepting issues, pull requests, and other requests and questions.

We look forward to your contribution!

Want to add an HTTP Router ?

If you have an HTTP Router or test case you would like to add, please send us an Issue or Pull Request.

If you are submitting an Issue, please tell us about the HTTP Router you would like to add.

If you are submitting a PullRequest, please add a test case. Reporting of benchmark runs is done by the owner, so you do not need to update the run results.

If you have any questions, you can ask them in Issue.

Contribution

Issues and Pull Requests are always welcome.

We would be happy to receive your contributions.

Please review the following documents before making a contribution.

CODE_OF_CONDUCT CONTRIBUTING

Sponsor

If you like it, I would be happy to have you sponsor it!

GitHub Sponsors - bmf-san

Or I would be happy to get a STAR.

It motivates me to keep up with ongoing maintenance :D

License

Based on the MIT License.

LICENSE

Author

bmf-san