Skip to content

Conversation

LiRuihaoA
Copy link
Contributor

What I DO

During lookupRoute, serverWebExchange add a new attribute for PathContainer to avoid repeating parsePath in PathRoutePredicateFactory. Thereby reducing cpu load and increasing throughput.

1. Background:

We have an Spring Cloud Gateway online service with about 2k path predicate routes;
And we found that Spring Cloud Gateway has high cpu load when pressure test request of a route.

2. Flame Graph and Cause

The CPU flame graph shows that the PathContainer.parsePath in PathRoutePredicateFactory consumes high cpu.

截屏2023-03-07 上午10 42 56

From the code, It is normal that the large number of routes leads to frequent execution of Predicate.apply.


But an exchange’s PathContainer is unchanged during the lookupRoute, there is no need to parsePath every time when test predicate.

protected HonoeRoute LookupRoute (ServerwebExchange oxchange)

PathRoutePredicateFactory's test method.

yub Lie boolean tost (SorvorwobExchange oxchango)

3. Change Details

So in PathRoutePredicateFactory, I hope exchange add a new attribute as below, to store its pathContainer.
When there are many path routes, only parsePath one time for a request.

Boverride

Below is the cpu flame graph after the update.

截屏2023-03-07 上午10 44 36

4. BenchMark

The following is the benchmark result of PathRoutePredicateFactory‘s test method. Throughput has been significantly improved after adding the new attribute.

Result of Test method with new attribute.
截屏2023-03-06 下午11 27 03

Result of Test method without new attribute.
0 2   G 001 w

@pivotal-cla
Copy link

@LiRuihaoA Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-cla
Copy link

@LiRuihaoA Thank you for signing the Contributor License Agreement!

@LiRuihaoA LiRuihaoA changed the title In PathRoutePredicateFactory. ServerWebExchange add a new attribute for PathContainer to avoid repeating parsePath Add ServerWebExchange a new attribute for PathContainer to avoid repeating parsePath in PathRoutePredicateFactory. Mar 7, 2023
spencergibb added a commit that referenced this pull request Mar 15, 2023
…oid repeating parsePath in PathRoutePredicateFactory."

See gh-2884
@spencergibb
Copy link
Member

Thanks for your first contribution! I polished things a bit here 5d8c2cf

@spencergibb spencergibb added this to the 3.1.7 milestone Mar 15, 2023
@LiRuihaoA
Copy link
Contributor Author

Hi Spencer, thanks for your code review! Glad to contribute~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

No open projects
Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants