In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to achieve ten thousand level concurrency of Java Web container". In daily operation, I believe that many people have doubts about how to realize ten thousand level concurrency of Java Web container. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "how to achieve ten thousand level concurrency of Java Web container". Next, please follow the editor to study!
Most current Java web containers are based on the Bio threading model, such as the common Tomcat, which defaults to 200threads, or 200connections. The problem is that if you want to increase concurrency or resource utilization, you have to increase the number of threads.
As shown below:
Hence the Netty-like Reactor threading model. At the same time, Java officially designed Servlet 3 asynchronous API, which can be programmed asynchronously by returning the class Feature. In some cases, ten thousand levels of concurrency can also be achieved.
But why can't asynchronous programming in the Java community be popularized? To investigate the reason, the database is the culprit, and looking up, it is actually the pot of JDBC. JDBC defines a set of blocking database IO communication model. This causes the thread to block waiting for the DB result with each request. As a result, server resources can not be fully utilized.
Is there a way to make the entire link of a Java web application non-blocking?
A: yes.
Asynchronous programming is the key to improving productivity. The following figure is the model we hypothesized today:
It's actually very simple.
We let Tomcat support the Servlet 3 asynchronous programming model, and the interface returns feature, which is actually implemented by many web containers. Crucially, we made both the DB client and server support the asynchronous programming model. Let DB reuse IO connections like netty. The business thread only needs to hand over the SQL to the database client to return feature, and then releases the current thread (no more blocking, which is the key). When the result of the DB operation returns, you just need to notify the feature. This will greatly improve thread utilization, it is no exaggeration to say that only 8 threads is enough to withstand ten thousand levels of concurrency.
The entire call process is shown in the following figure:
We can see that when a http request comes, the whole process is non-blocking. Instead of waiting for the database to return the result, the business only needs to add a callback. When the database result returns, the callback is triggered automatically.
Of course, this is just a small idea of mine. I think it will be too difficult for Mysql to rewrite the connector. But can those new generation of databases be designed to support asynchronous and multiplexing? In this way, the client of web application can design the whole link asynchronously, which will save a lot of resources and improve productivity.
At this point, the study on "how to achieve ten thousand-level concurrency of Java Web container" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.