Server | Improve Springboot Concurrency

Option One

1. Undertow replaces tomcat

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-start-tomcat</artifactId>
         </exclusion>
    </exclusions>
</dependency>


<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-undertow</artifactId>
</dependency>

2. Add related configuration

server:
  undertow:
    direct-buffers: true
    io-threads: 4
    worker-threads: 160

Restart, you can see in the console that the container has been switched to undertow

Option II

1. Cache
Put some hot data or static data in the local cache or redis, and update the cached data regularly if necessary

third solution

1. Asynchronous

2. Add @EnableAsync annotation to the startup class

3. Add @Async annotation to the specified method when needed. If you need to wait for the return value, the demo is as follows

Option Four

1. If there are thread variables or mdc in logback, you can increase the transfer

 

Option Five

1. Integrated message queue
There are many scenarios where the real-time data requirements are not so strong, or when the business is fault-tolerant, the message can be sent to Kafka, and then delayed consumption. For example, send push messages to specified users based on conditional query, here can be on time, day, month, etc.

Option Six

1. Update the database by adding the version number version to the database. If the read version is inconsistent with the version in the database, the update will fail, or if the update fails, the database inventory will be cyclically retrieved. If the inventory is greater than 0, it will continue until the update is successful. , So the pressure on the database is relatively large, if the amount of concurrency is not large, you can consider

Guess you like

Origin blog.csdn.net/qq_41920732/article/details/109071651