Skip to content
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

router: only cache single route for the active request #26045

Merged
merged 33 commits into from
Apr 4, 2023

Conversation

wbpcode
Copy link
Member

@wbpcode wbpcode commented Mar 12, 2023

Commit Message: router: only cache single route for the active request
Additional Description:

In the previous impl of the route table, every active request will keep a reference of the whole route table. If there route table is updated frequently and there are some long-live http request, the old versions route tables cannot be released timely and increase the overhead of memory.

This PR try to fix this problem by cache single route for active request.

See #20800 for more detailed background.

Risk Level: High. Core code patch. Change the lifetime of route table.
Testing: Added/fixed.
Docs Changes: n/a.
Release Notes: n/a.
Platform Specific Features: n/a.

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
@wbpcode wbpcode marked this pull request as draft March 12, 2023 08:51
Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
@wbpcode wbpcode marked this pull request as ready for review March 13, 2023 06:36
envoy/router/router.h Outdated Show resolved Hide resolved
Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
@alyssawilk
Copy link
Contributor

/wait on CI - I think the router drop is real
Or were you waiting for first pass before writing tests? If so I think @adisuissa could do a round as this looks like it's a config lifetime change

@JakeCooper
Copy link

JakeCooper commented Mar 15, 2023

Hello from the Railway folks (original filers of #20800)

Patch is looking great! Will circle back if anything changes but, hopefully that provides a nice little datapoint "in the wild"

CleanShot 2023-03-14 at 17 21 32@2x

CC @char8

@wbpcode
Copy link
Member Author

wbpcode commented Mar 15, 2023

Will to write some tests to improve the coverage of the common/router.

It would be great if more experts could help to review this PR. This lifetime change always be dangerous patch.

@wbpcode
Copy link
Member Author

wbpcode commented Mar 15, 2023

cc @JakeCooper Thanks for your feedback. Note this patch is no completed and it couldn't be used in the production. Especially if scoped rds & ondemand rds are used by you.

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
@wbpcode
Copy link
Member Author

wbpcode commented Mar 15, 2023

I rechecked the code of ondemand rds. Seems the ondemand callback is managed by the route config provider. So this patch will not effect it.

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
Copy link
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Overall, the code changes LGTM, but would add a few tests that validate that the new behavior is maintained (if the config is changed during execution time, the new one is latched onto).

IMO there is a fundamental question here: when should the filter-manager latch to the route table (see Matt's comment?
Prior to this PR the routing table is latched during the decodeHeaders() call.
This PR changes it to latch later when route() is called.
Changing the routing table view in the midst of routing is possible, but it should be reviewed by someone that understands the details of the router.
Also cc @envoyproxy/senior-maintainers to chime in on this.

Another alternative to consider is to explicitly release the routing table, once a request "realizes" that the route is fixed (i.e., no need to reroute). It may be a bit easier to understand the code, and clearly find the cases where there could be an old-new view conflict of the routing table. WDYT?

envoy/router/router.h Outdated Show resolved Hide resolved
source/common/http/conn_manager_impl.cc Outdated Show resolved Hide resolved
@wbpcode
Copy link
Member Author

wbpcode commented Mar 16, 2023

Prior to this PR the routing table is latched during the decodeHeaders() call. This PR changes it to latch later when route() is called.

In fact, we still will get the route table in the decodeHeaders() to get the initial route.

Another alternative to consider is to explicitly release the routing table, once a request "realizes" that the route is fixed (i.e., no need to reroute). It may be a bit easier to understand the code, and clearly find the cases where there could be an old-new view conflict of the routing table. WDYT

Sounds a good idea. Then we can keep current behaviors completely. Typically, we can do this in the router filter. And I think we can also make this a interface of StreamFilterCallback. May be call it freezeRouteCache or something.
cc @mattklein123 @alyssawilk

@alyssawilk alyssawilk removed their assignment Mar 30, 2023
Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
@repokitteh-read-only
Copy link

CC @envoyproxy/runtime-guard-changes: FYI only for changes made to (source/common/runtime/runtime_features.cc).

🐱

Caused by: #26045 was synchronize by wbpcode.

see: more, trace.

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a few comments, thank you for tackling this tough problem! Awesome.

/wait

changelogs/1.25.0.yaml Outdated Show resolved Hide resolved
envoy/router/router.h Outdated Show resolved Hide resolved
source/common/http/conn_manager_impl.cc Outdated Show resolved Hide resolved
source/common/http/conn_manager_impl.h Outdated Show resolved Hide resolved
source/common/http/conn_manager_impl.h Show resolved Hide resolved
Co-authored-by: Matt Klein <mattklein123@gmail.com>
Signed-off-by: code <wangbaiping@corp.netease.com>
wbpcode and others added 3 commits April 1, 2023 11:41
Co-authored-by: Matt Klein <mattklein123@gmail.com>
Signed-off-by: code <wangbaiping@corp.netease.com>
Co-authored-by: Matt Klein <mattklein123@gmail.com>
Signed-off-by: code <wangbaiping@corp.netease.com>
Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
mattklein123
mattklein123 previously approved these changes Apr 3, 2023
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work. LGTM!

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
@wbpcode
Copy link
Member Author

wbpcode commented Apr 4, 2023

Hi, @mattklein123 could you give a stamp again? 😸 @ Conflict resolved and minor update to the changelog format.

@wbpcode wbpcode enabled auto-merge (squash) April 4, 2023 01:40
@wbpcode wbpcode merged commit 6468024 into envoyproxy:main Apr 4, 2023
63 of 65 checks passed
@wbpcode wbpcode deleted the dev-route-config-opt branch April 4, 2023 09:23
RiverPhillips pushed a commit to RiverPhillips/envoy that referenced this pull request Apr 7, 2023
)

* router: only cache single route for the active request

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>

In the previous impl of the route table, every active request will keep a reference of the whole route table. If there route table is updated frequently and there are some long-live http request, the old versions route tables cannot be released timely and increase the overhead of memory.

This PR try to fix this problem by cache single route for active request.

See envoyproxy#20800 for more detailed background.

Risk Level: High. Core code patch. Change the lifetime of route table.
Testing: Added/fixed.
Docs Changes: n/a.
Release Notes: n/a.
Platform Specific Features: n/a.
Optional Runtime guard: envoy.reloadable_features.prohibit_route_refresh_after_response_headers_sent

---------

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
Signed-off-by: code <wangbaiping@corp.netease.com>
Co-authored-by: Matt Klein <mattklein123@gmail.com>
Signed-off-by: River Phillips <riverphillips1@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants