Skip to content

fix: renew route lrucache when the routes change#8119

Closed
kingluo wants to merge 2 commits into
apache:masterfrom
kingluo:dynamic_route_lrucache
Closed

fix: renew route lrucache when the routes change#8119
kingluo wants to merge 2 commits into
apache:masterfrom
kingluo:dynamic_route_lrucache

Conversation

@kingluo

@kingluo kingluo commented Oct 19, 2022

Copy link
Copy Markdown
Contributor

Description

Fixes # (issue)

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@membphis

Copy link
Copy Markdown
Member

@kingluo pls rebase your branch

@kingluo
kingluo force-pushed the dynamic_route_lrucache branch from f9357b6 to 82620f7 Compare October 21, 2022 03:03
membphis
membphis previously approved these changes Oct 21, 2022
Comment thread apisix/plugins/ai.lua
core.log.info("use ai plane to match route")
router.router_http.match = ai_match

local count = #routes + 3000

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not familiar with the route cache design, so the questions below need to be answered by someone who is familiar with it. CC @membphis @tzssangglass

  1. do we need to clean the cache when we switch 'cache' to 'no cache'?
  2. is it desirable to recreate cache once the router is rebuilt (a new route is added)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If it is desirable, we need to switch the cache lookup way from key + ver to key as each ver has its own cache now. Also, we may not need to init the cache as it may be created in the first router building.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

2. is it desirable to recreate cache once the router is rebuilt (a new route is added)?

no, if the router is rebuilt, the cache version(router.router_http.user_routes.conf_version) would be changed, so a new request comes in and generates the cache key as old would execute origin router_match and generates new matched_route, and cache new matched_route.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do we need to clean the cache when we switch 'cache' to 'no cache'?

I don't think it's needed because 'cache' to 'no cache' means router.router_http.user_routes.conf_version has changed, refer to the explanation above.

Do we need to recreate the lrucache when switching 'cache' to 'no cache'? @membphis

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

for the better performance and logic simple, I think we should renew the lrucache and ignore router.router_http.user_routes.conf_version, which is more simpler to read and understanding

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think it's needed because 'cache' to 'no cache' means router.router_http.user_routes.conf_version has changed, refer to the explanation above.

So it is acceptable to keep the unused cache when we move to 'no cache'?

BTW, look like we can remove the init in

local route_lrucache = core.lrucache.new({
as there will always create a router cache here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So it is acceptable to keep the unused cache when we move to 'no cache'?

I think it's needed.

@kingluo
kingluo force-pushed the dynamic_route_lrucache branch 2 times, most recently from f9357b6 to 6b0009f Compare October 23, 2022 07:28
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.

4 participants