alexandrevicenzi / yagm

Yet Another Go Mux
MIT License
3 stars 2 forks source link

Better router algorithm #1

Closed alexandrevicenzi closed 1 year ago

alexandrevicenzi commented 7 years ago

There's a for loop to find the correct path, maybe we could cache something or maybe find a better algorithm to search the correct path using regexp.

rkomiyama commented 7 years ago

Are you referring to the for loop in ServeHTTP()?

alexandrevicenzi commented 7 years ago

@rkomiyama Yes, this one.

I think if someone have a lot of routes it could be a little bit slow, need to run a stress test on this to check.

IngCr3at1on commented 7 years ago

@alexandrevicenzi in regards to a "cache" maybe a cuckoofilter or bloomfilter would likely be applicable and allow a large number of routes with fast lookup capabilities.

I could implement this if it's wanted.

alexandrevicenzi commented 7 years ago

@IngCr3at1on Never heard about them lol

Just a link to know what it is:

cuckoo it's an improvement over boom (just a quick read).

IngCr3at1on commented 7 years ago

@alexandrevicenzi that's correct yes. They're designed for sorting and searching extremely large datasets so the number of routers shouldn't make a difference when checking either of them. Normally they exist in memory state only but I just forked a cuckoofilter repo the other day to add gob decoding so we could save the state of one to disk when reloading a service (I don't think that's really needed in this case obviously lol)

alexandrevicenzi commented 7 years ago

@IngCr3at1on no, it doesn't need.

The biggest problem could be call /foo endpoint 300 times per second. If we cache this for some time (while app is alive) we can save some CPU and lower response time.

IngCr3at1on commented 7 years ago

@alexandrevicenzi exactly what I was thinking yes.

alexandrevicenzi commented 7 years ago

For this scenario any cache system can solve. Call once, save for later use.

If the scenario is call random endpoints in an API with 1k endpoint it will take a while to check every regular expression. A good start point for this is to take a look in Django or another framework that uses regexp urls.

rkomiyama commented 7 years ago

I'm new to the Go language. Do you just run the test by doing go test? How do you know which test cases it runs through?

alexandrevicenzi commented 7 years ago

The best option is to run go test -v ./.... This will run all tests in verbose mode.

guiferpa commented 7 years ago

Already see this project: https://github.com/julienschmidt/httprouter