In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "how to understand Spring non-blocking programming mode". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Testing method
In this article, we tried the following four combinations:
Spring Web MVC + JDBC database driver
Spring Web MVC + R2DBC database driver
Spring WebFlux + JDBC database driver
Spring WebFlux + R2DBC database driver
I have increased the number of parallel requests in units of 50 from 4 to 500, assigning four cores to the load generator and the service (my laptop has 12 cores). I configured all the connection pools to 100. Why fix the number of cores and the size of the connection pool? Because changing these factors did not provide more data in previous tests on JDBC and R2DBC, I decided to keep fixed variables in this test to reduce the time it takes to run the test.
I simulate a GET request on the service. The service fetches 10 records from the database and returns them as JSON. First of all, I warmed up the service for 2 seconds. Next, I started an one-minute benchmark. I run each scenario five times (instead of running other tests five times later) and calculate the average of the results. I only counted those tests that had no errors. When I increased the number of concurrency to more than 1000, all implementations failed without exception.
I used Postgres (12.2) as the database. And use wrk for benchmarking. I parse the output of wrk using the following method. Main measurements:
Response time-from Wrk test report
Throughput (number of requests)-from Wrk test report
Process CPU usage-user and kernel time (based on / proc/PID/Stat)
Memory usage-private and shared process memory (based on / proc/PID/maps)
You can check the test script used here [1]. You can check the code used here [2].
Test result
You can view the raw data I used in the chart here [3].
Response time
Obviously, Spring Web MVC + JDBC may not be your best choice under high concurrency. Obviously, with higher concurrency, R2DBC can provide better response time. Spring Web MVC and Spring WebFlux have a similar trend.
Throughput
Similar to response time, using JDBC+Spring Web MVC performs even worse at high concurrency. Similarly, R2DBC is clearly doing better. If you still use JDBC on your back end, it's not a good idea to move from Spring Web MVC to Spring WebFlux. Spring Web MVC + JDBC performs best at low concurrency.
CPU
CPU refers to the CPU time throughout the run, that is, the sum of the process user and kernel time.
The scheme that uses JDBC+Web MVC consumes the highest CPU at high concurrency. JDBC+WebFlux 's scheme uses the least CPU time, but also the lowest throughput. When you look at the average CPU used per request, you can measure the efficiency of CPU use in various ways.
On average, R2DBC uses less CPU per request than JDBC. Using JDBC+WebFlux doesn't seem like a good idea. JDBC+Web MVC is worse at high concurrency, while the implementation of at least one other non-blocking component is more stable. However, Web MVC + JDBC can make the most effective use of CPU at low concurrency.
Memory
We measure the process's private memory consumption as memory at the end of the run. Memory usage depends on garbage collection. We use JDK 11.0.6 and G1GC. The Xms is set to 0. 5 Gb (the default is 1 of 32 Gb of my available memory). Xmx is set to 8 Gb (the default is 1 of 32 Gb of my available memory).
Compared to WebMVC, WebFlux's memory usage seems to be more stable, while WebMVC's memory usage is higher at high concurrency. When using WebFlux+R2DBC, memory usage is minimal in high concurrency cases. At low concurrency, Web MVC + JDBC uses less memory, but at high concurrency, WebFlux + R2DB uses the least memory per request on average.
Fat Jar Siz
JPA takes up a big head in the image below. If you don't use R2DBC, the size of Fat JAR will drop to about 15Mb!
The successor to JDBC.
That's all for "how to understand Spring non-blocking programming mode". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.