-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Performance degradation in Web layer after upgrade to Spring 6 #31098
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
Comments
Thanks for the report @alexey-anufriev , but there not so much actionable here, or at least conflicting messages. You're first mentioning Tomcat's Again, without much context, it's hard to understand why this part of the execution is slow. Request matching is of course an important part and we've optimized it with Discussing about performance is often tricky as it's easy to waste time setting up an imperfect benchmark test harness and draw the wrong conclusions. Comparing the same application with two different versions and pointing to the difference should be a good first step. Pointing to parts of the request processing and asking for performance improvements is not a good way to start; we've got multiple micro-benchmarks in the Framework codebase and spending time there is not always the most efficient way to optimize for your case.
The |
Fair enough, let me prepare benchmarks. |
@alexey-anufriev I'm not suggesting you to prepare benchmarks, quite the opposite. It takes a lot of time to design and implement a benchmark and consider its biases. Here, I'm really requesting a full picture of the CPU time (your datadog flame graph) for the 2.7.x and 3.1.x versions of the same application. Comparing CPU time there should point to possible regressions that I could look into. |
Thanks for the update! If I understand correctly, both applications are Spring MVC, one using the it looks like the It would be interesting to get more information about the particular endpoints involved here:
With that information I can start building a sample application involving Spring Security, a few controller endpoints and find out if there is a performance issue with the matching phase. |
|
hi @bclozel, are there any updates here? or maybe some additional information required? |
I'm still working on it. So far nothing conclusive. I do see that the mvc request matcher is taking longer, which is not unexpected since it's doing more in the first place. The number of req/s is still comparable, and the ratio of time taken by request matching is still nowhere near where your samples are. I've profiled locally with Yourkit and wrk on a sample app that should be comparable. With ant matcher: With mvc request matcher: I'll continue investigating this in the next days and keep you posted. I might share the sample with you at some point or write JMH benchmarks to see if I can optimize a few spikes I'm seeing. |
Thank you for the update. Looking forward to the next steps. |
I can share some observations... |
Hi @bclozel - Is there any suggestion for this observation. @alexey-anufriev the tomcat latency around toString upon checking their repo there isn’t any updates made on that code. Can you share how did you mitigate this issue. |
@smotron @akhilbrao I'm afraid this issue does not intend to cover all performance aspects of Spring web frameworks with Security. We are still investigating (although I had to prioritize 6.1 work as the release is approaching) and we'll share our findings here. Our initial findings do not point to a particular place nor show a huge difference in latency nor throughput. We might find some optimization opportunities along the way but as you can see Spring is only involved in some parts of the flame charts. Spring Boot upgrades usually involve lots of other components as well. |
@bclozel thanks for the update. We have recently upgraded to spring boot 3.1.2 lets see how the performance would be. Though we don’t have many url patterns. @alexey-anufriev when you find some time let us know the solution for tomcat if you had done anything. |
@alexey-anufriev We have the exact same issue, after some digging I found that the |
spring-projects/spring-security#14128 is now fixed and available in Spring Security 6.1.6-SNAPSHOT and 6.2.1-SNAPSHOT. Please test your applications with the current Spring Boot 3.2.1-SNAPSHOT version to check the performance changes. Release is scheduled next week for Spring Boot. |
@bclozel, thank you for your effort, I will test the new build and will come back with the results soon. |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue. |
It took a bit of time to validate the fix completely (also considering NY holidays), but we are done now, and I can confirm, that we not only got rid of performance degradation, but also got performance boost with path-parser vs ant-matcher. @bclozel, and the rest of spring team, thank you for your effort and help! |
@alexey-anufriev Awesome, thanks for letting us know! |
@bclozel Thanks for considering the issue and getting it fixed. |
This comment has been minimized.
This comment has been minimized.
hi @tushar-meesho, yes, Spring Boot 3.2.1 contains a fix (note that normally you should not use a SNAPSHOT version, it is just for testing). Also, 3.2.5 has it included, so don't see a reason to not upgrade to the latest one. |
Hi, @alexey-anufriev So in one of your previous posts you mentioned that you could verify that it's fixed? thanks in advance |
hi @goafabric, yes, APM showed good metrics and latency went back to normal, so it was confirmed that the performance is good |
Yeah I'm still getting this in 3.2 with security as well |
I can confirm that it was fixed. After the fix our execution time for a time-critical operation was even faster than before with 9ms and it is still there, today. |
@smotron Thx. I'll check the filters/interceptors. I'll just add a trace |
@smotron so I ran traces on filters/interceptors and even swapped out the cache. No effective change. Was getting 7000/rps with security (jwt, oauth, session mngmt, cors, rbac/abac) but NOW it is only 6000/rps. I test the RPS using Apachebench and Beapi-bench using 500 concurrency and 5000 requests over 50 tests (with a 1 second pause between tests); generally, the test hits its stride at around the 10th test. I have been testing this for about a month now and it is undeniable that the web functionality has deteriorated significantly. I should also add that I am using a SimpleUrlHandlerMapping rather that RequestMappingHandlerMapping. I doubt this would effect anything unless they optimized for one type of mapping and neglected the others. This is the only real difference I can see aside from switching my cache provider(ehcache2 to caffeine) I'm beginning to think this may be a stability fix and my numbers now reflect additionals checks being done. |
NVM. That was it. Tomcat config not optimized. Was adding an async executor and had not optimized it. Adding this reference. |
Affects: 6.0.10 (Spring Boot 3.1.1)
Summary:
After upgrade to Spring Boot 3.x application started to take more time for web requests processing.
Description:
Initially, the application was based on Spring Boot 2.7.14 (Java 17). But since we upgraded to Spring Boot 3.1.1 we noticed performance degradation in web layer. Requests processing took extra time in comparison with Boot 2.x. Upgrade to Spring Boot 3.1.2 made it ever worse. Tomcat's
MessageBytes
serialization started to perform even slower. So we reverted to Spring Boot 3.1.1.One more thing that was discovered in the profiler is slow performance of
AntMatcher
. So we followed the recommendation from upgrade guide of Spring Boot 2.6 and witched toPathParser
. As it turns out, this did not make much of an improvement (see details below).CPU
Here are some details captured using DataDog profiler.
Here is a request processing of the URL that has path variables:

And here is a request processing of the URL that has no path variables:

Memory
One more thing that was discovered is memory consumption, most of the allocations are happening here:

This is the size per minute

How can this be improved? One thought is around some kind of caching for
PathParser
to avoid extra calculations while request matching.The text was updated successfully, but these errors were encountered: