Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
[gateway] Inefficient and Arbitrary selection of API in DefaultReactorHandlerResolver #1445
When DefaultReactorHandlerResolver figures out which API to route a request to, it iterates through the context paths from it's hash map (so entries are ordered by a mod of the hash code) and finds the first one whose value starts with the request path. This is both inefficient (when a large number of APIs are defined) and arbitrary (if there is a context path that is the prefix of another, it is difficult to know which one will be chosen).
Instead, the longest context path that starts the request path should be chosen and it should do so efficiently.
Using a sorted map or checking for exact match of the request path (removing the latest path segment each iteration until matched) are two different ways to implement this more efficiently.
We anticipate our customers will have a growing number of APIs and we are concerned for the additional latency that might incur if the routing logic is not efficient.
You're absolutely right !
We do not consider to work on such performance for the reactor since we are looking to implement virtual-hosting per API.
Implementing this new feature will be the good moment to work on such performance / benchmark.
I hope being able to work on virtual hosting for 1.20 (mid-october).