Closed alexandrevicenzi closed 1 year ago
Are you referring to the for loop in ServeHTTP()?
@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.
@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.
@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).
@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)
@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.
@alexandrevicenzi exactly what I was thinking yes.
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.
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?
The best option is to run go test -v ./...
. This will run all tests in verbose mode.
Already see this project: https://github.com/julienschmidt/httprouter
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.