A system can withstand much concurrency, to a large extent determines the architecture ~~ following a project with personal experience of the author (SMS project company level) to analyze the next
background
Online messaging system and stable operation of more than a year, suddenly one day a large number of system requests a timeout, the service is not available, the investigation down there are divisions engaged in marketing activities, a large number of centralized marketing message push, cause the system to short-term request load is too high, so in I immediately next dominant architecture for messaging systems have been adjusted, the SMS marketing by the synchronous nature of asynchronous changed, of course, adjust the system architecture can largely improve the throughput of the system, but this step can sometimes be difficult. Architecture adjustment is not discussed here, assuming that your architecture is no longer adjustable. For ordinary springboot application, how to optimize it?
In SpringBoot Web project, the default uses a built-in Tomcat, of course, can also be configured to support the built-in jetty, built what good is it?
- Micro convenient service deployment.
- Easy project start, no need to download Tomcat or Jetty
We need to consider the following optimization points:
- Threads
- overtime time
- jvm optimization
Is the focus of a number of threads, the initial number of threads and the maximum number of threads, the initial number of threads guarantee startup, if there are a large number of users to access, very stable reception can request.
Maximum number of threads used to ensure the stability of the system, and to ensure that the connection timeout continued to wait, if there are a large number of requests over the delay is relatively high, is not easy playing in the thread, in this case, the production is more common, once network instability, preferring to packet loss, nor can the machine defeat.
jvm general optimization is to increase the maximum set the initial heap and stack, and garbage collection.
In the spring boot configuration file application.yml, add the following configuration
server:
tomcat:
min-spare-threads: 20
max-threads: 100
connection-timeout: 5000
Tomcat was a piece of optimized configuration, the maximum number of threads is 100, initialize the thread is 20, the timeout is 5000ms
More optimization points only to provide an optimized direction, the specific parameter settings, or to subject to the actual production of pressure measurement results! ! !
Reproduced in: https: //www.jianshu.com/p/8b94abe57208