-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Performance improvement in RequestMappingInfo #22598
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
Conversation
Would it make sense to immediately return |
I think it make sense, and the modification is committed. |
|
RequestMappingInfo
RequestMappingInfo
@rstoyanchev @jhoeller as an FYI, I've got an alternate |
RequestMappingInfo
Thanks @bclozel. I've marked this 5.1.6 since the suggested changes are straight-forward. Maybe the alternate MediaType implementation could target 5.2. @aftersss unless I hear from you that you're reworking the PR, I will process this later today so there is a chance to test the outcome ahead of next week's 5.1.6 release. |
OK, I have done this change. |
I've processed the PR + some extra polish. Note that I reversed the order so that patterns are after consumes and produces. Both are now cached for WebFlux. Also I've created #22644 to make further optimizations for 5.2 where Spring MVC should catch up on caching request values. @aftersss it would be great if you could confirm 5.1.6.BUIlD-SNAPSHOT against the baseline numbers you have. |
We are using
spring-cloud-gateway
integrated withspring-boot-starter-actuator
, we run a load test on it(using jmeter, and my gateway program runs on a linux server with 4 cores/2GB) and found thatRequestMappingInfo
have some performance problem.Scene 1: We added a

Http Header Manager
intojmeter
with the headerAccept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
,(default value of chrome)then I run jmeter and let my gateway program run to 2000 qps, the cpu usage is about 60%:
Scene 2: We added a

Http Header Manager
intojmeter
with the headerAccept:
, then I run jmeter and let my gateway program run to 2000 qps, the cpu usage is about 35%:As you can see, the performance is affected by the length of
Accept
header, maybe hackers can use this performance problem to make ddos attack easier.I use
async-profiler
(https://github.com/jvm-profiling-tools/async-profiler) to profile my program, and this is the result:aaa.txt
there are many stacktraces like the following costs too much cpu:
I found that the key point is that
MediaType.parseMediaType
is invoked too many times(more than 400) in one http request, this will cost too much cpu, so I change the order of the code, and test it again(also run to 2000 qps), this time the cpu usage is no more than 35%, the cpu usage will not be affected by the length ofAccept
header any more.