Skip to content

Conversation

LiRuihaoA
Copy link
Contributor

What I DO

In lookupRoute, translate route to Mono will lead into context propagation and additional operators.

When the number of routes increases, it becomes the bottleneck of throughput.

So the PR removes the concatMap in lookupRoute.

1. Background:

After the modification of [PR]#2884, I found that the throughput did not meet expectations.

But there's no suspicious on Spring Cloud Gateway; So turned attention to Reactor.

2. Flame Graph and Cause

By testing 2k routes that predicate is asyncPredicate(s -> Mono.just(Boolean)) ,we found the context propagation in MonoFilterWhen.onNext and operators in the concatMap function is the bottleneck.
1
3
2

4

3. Change Details

So in lookupRoute, I hope to remove the concatMap and use filterWhen instead it.
截屏2023-06-07 下午3 22 38
For the delay error mentioned in the [PR]#427, filterWhen function doesn't return MonoError, so i think no exceptions and logs will be swallowed.

4.Throughput Improvement

After modification, the bottleneck is solved, not too much context propagation and operators.
截屏2023-06-07 下午12 42 47

I have tested the throughput before and after the modification under different routing quantities.
I used wrk -t 1 -c 10 -d 10s http://localhost/test on a 8 core MacBook Pro M1. Below is the result.
截屏2023-06-07 下午3 00 59

From the test results, it can be seen that the modified throughput is significantly improved.

@LiRuihaoA
Copy link
Contributor Author

can refer to this repository to test the number of routes and throughput
https://github.com/LiRuihaoA/scgTest/tree/master

@LiRuihaoA
Copy link
Contributor Author

hi @spencergibb cloud you help review?

@spencergibb spencergibb added this to the 4.1.2 milestone Mar 8, 2024
@spencergibb spencergibb merged commit 074de09 into spring-cloud:main Mar 8, 2024
@spencergibb spencergibb removed this from the 4.1.2 milestone Mar 8, 2024
@spencergibb
Copy link
Member

Unfortunately, I only realized that the error handling changed, and I can't do this in a patch.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants