-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf(router): adjust the sequence of predicate generated inside a traditional compatible route expression #14267
base: master
Are you sure you want to change the base?
Conversation
…ional compatible route expression
I saw that only the order changed, no other code is touched, am I correct? |
could we add a comment of sequence before get_expression(), like:
|
Yes that's correct
Comment added. |
@@ -331,6 +331,15 @@ local function path_val_transform(op, p) | |||
end | |||
|
|||
|
|||
-- Generates an ATC router expression for traditional compat router flavor | |||
-- match priority for http is as follows: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-- match priority for http is as follows: | |
-- match order for http is as follows: |
-- -> net.dst.ip -> net.dst.port -> http.path -> http.headers | ||
-- -> http.host -> http.method | ||
-- | ||
-- match priority for stream is as follows: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-- match priority for stream is as follows: | |
-- match order for stream is as follows: |
Turn to draft since we are still in discussion. |
I agreed with this idea. However since the |
There definitely exists some scenarios where method evaluation can short-circuit expensive path evaluation. For example, when you have tons of GET APIs but only few POST APIs and you're using regex for all route's path matching, then the POST API request cannot gain any improvements from the PR's change(it'll make them worse instead). However the GET API requests may, because the GET method is the majority of the route set. That is why the change in this PR could not bring performance improvement for all requests under all scenarios, but for general cases in which the path value has more variants than the limited set of http.method. |
However I can also not define "general case" properly as different people may have different ideas, so I'm merely just based on the fact that HTTP protocol supports more value variants configured inside path rather than inside HTTP method 😄 |
That make sense. This PR is good to me, and we could see how it benefits from the perf benchmarking report, I think the perf benchmarking will be more like a real-world user scenarios with more practical routes and traffics. |
Summary
This PR adjusts the sequence of HTTP fields and their predicates generated inside a traditional compatible route expression, expecting to improve routing matching performance in general situations.
Before this PR, the sequence is src_ip -> src_port -> dst_ip -> dst_port -> methods -> hosts -> paths -> headers
After this PR it becomes src_ip -> src_port -> dst_ip -> dst_port -> paths -> headers -> hosts -> methods.
The reason for this change is that the expression is evaluated from left to right in the atc-router, so a field that is most unlikely to be matched should be put into the very left of the expression as a short circuit, otherwise, when we execute the evaluation on a set of very large routes, there will be lots of unnecessary predicates executed and CPU cycles wasted. Note: this PR does not bring performance improvements for all cases, but for general cases in which the path value has more variants than the limited set of http.method.
Checklist
changelog/unreleased/kong
orskip-changelog
label added on PR if changelog is unnecessary. README.mdIssue reference
This was discovered as part of the issue in FTI-6456.