Live data from Hacker News

Mux – A lightweight, fast HTTP request router for Go

github.com

31–40 of 80 posts

Re: Mux – A lightweight, fast HTTP request router for Go

#31
post #2

Does it use a trie? If not, it probably should. Here's a wonderful talk on using that datastructure (with go) for the gov uk url router: https://gdstechnology.blog.gov.uk/2013/12/05/building-a-new-... The Vulcan proxy from Mailgun does the same thing: http://vulcand.github.io/proxy.html#route It looks like it doesn't, so existing open source golang url routers will perform much better, contrary to this post. The one…

Interestingly enough, I used a trie (without knowing that's what it was called) when building the router for my Frontend framework.

https://github.com/ShamariFeaster/Templar/blob/master/core/R...

Re: Mux – A lightweight, fast HTTP request router for Go

#32
post #16
post #15

My favourite current HTTP request router is https://github.com/pressly/chi The list of those using it in production includes: - Pressly - Cloudflare - Heroku - 99designs - Origami - IT Jobs Watch - CrowdRiff At Cloudflare it's our default router for internal APIs, which are all written in Go. (and yes it uses a trie)

Do you know how it stacks up to httprouter for example? We can run benchmarks all day but it would be cool if you happened to have some real production statistics, by any change?

They're in the same ballpark, choosing one over the other was preference.

The benchmarks skew slightly in favour of httprouter, but only because pressly/chi embraces use of req.Context and this does a few ops. If you add req.Context use to httprouter they're basically the same.

If you're doing work with Context, you aren't going to be able to measure a difference that you'll care about.

If you're just serving static files, perhaps you'll care.

Re: Mux – A lightweight, fast HTTP request router for Go

#33
post #15

My favourite current HTTP request router is https://github.com/pressly/chi The list of those using it in production includes: - Pressly - Cloudflare - Heroku - 99designs - Origami - IT Jobs Watch - CrowdRiff At Cloudflare it's our default router for internal APIs, which are all written in Go. (and yes it uses a trie)

It also uses the new context package which is a huge plus in my book.

Re: Mux – A lightweight, fast HTTP request router for Go

#35
post #34

Why does routing get so complicated? I use Web2py which doesn't even have a router and it's so much easier. Are regxes, variables, http methods all that necessary in the router? Just pass the info to a controller.

If you don't need a router for web2py it's because WSGI is doing all the hard work for you.

https://en.wikipedia.org/wiki/Web_Server_Gateway_Interface

Re: Mux – A lightweight, fast HTTP request router for Go

#36
post #2

Does it use a trie? If not, it probably should. Here's a wonderful talk on using that datastructure (with go) for the gov uk url router: https://gdstechnology.blog.gov.uk/2013/12/05/building-a-new-... The Vulcan proxy from Mailgun does the same thing: http://vulcand.github.io/proxy.html#route It looks like it doesn't, so existing open source golang url routers will perform much better, contrary to this post. The one…

Trie's are my favorite data structure. The implementation in the Linux kernel is a lock free RCU structure (http://lxr.free-electrons.com/source/lib/radix-tree.c). It is used for the page cache among other things.

Re: Mux – A lightweight, fast HTTP request router for Go

#37
post #2

Does it use a trie? If not, it probably should. Here's a wonderful talk on using that datastructure (with go) for the gov uk url router: https://gdstechnology.blog.gov.uk/2013/12/05/building-a-new-... The Vulcan proxy from Mailgun does the same thing: http://vulcand.github.io/proxy.html#route It looks like it doesn't, so existing open source golang url routers will perform much better, contrary to this post. The one…

Why is a trie obviously better then a hash map?

Re: Mux – A lightweight, fast HTTP request router for Go

#38
post #37
post #2

Does it use a trie? If not, it probably should. Here's a wonderful talk on using that datastructure (with go) for the gov uk url router: https://gdstechnology.blog.gov.uk/2013/12/05/building-a-new-... The Vulcan proxy from Mailgun does the same thing: http://vulcand.github.io/proxy.html#route It looks like it doesn't, so existing open source golang url routers will perform much better, contrary to this post. The one…

Why is a trie obviously better then a hash map?

A hash map doesn't solve the same problem. Given a collection of routes, you need to find the longest one which is a prefix of the given URL.

Re: Mux – A lightweight, fast HTTP request router for Go

#39
post #37
post #2

Does it use a trie? If not, it probably should. Here's a wonderful talk on using that datastructure (with go) for the gov uk url router: https://gdstechnology.blog.gov.uk/2013/12/05/building-a-new-... The Vulcan proxy from Mailgun does the same thing: http://vulcand.github.io/proxy.html#route It looks like it doesn't, so existing open source golang url routers will perform much better, contrary to this post. The one…

Why is a trie obviously better then a hash map?

They allow you to match the URL in a series of steps. Where each step can be static (ie "/foo") or dynamic (ie /images/).

You can then easily add features to this structure, like route middlewares at every level in the tree; just apply them while doing the routing.

This also allows you to match route variants easily, ie "foo" and "foo/" are the same, so are "/" and "/index.html". In the same way you can extract query parameters for middleware/handler use.

Re: Mux – A lightweight, fast HTTP request router for Go

#40
post #37
post #2

Does it use a trie? If not, it probably should. Here's a wonderful talk on using that datastructure (with go) for the gov uk url router: https://gdstechnology.blog.gov.uk/2013/12/05/building-a-new-... The Vulcan proxy from Mailgun does the same thing: http://vulcand.github.io/proxy.html#route It looks like it doesn't, so existing open source golang url routers will perform much better, contrary to this post. The one…

Why is a trie obviously better then a hash map?

Fixed lookup time. A trie (aka radix tree) 3 levels deep with 1 million entries has the same lookup time as a 3 level deep trie with 5 entries.
Post reply on HN