Using components springcloud kit + mysql
A common request of rest, to be a basic user information query, sql been optimized const level, but the pressure-measurement by jemeter, found that the actual amount of concurrency only 20-30, after inspection found that the configuration is not optimized problem solution is as follows:
1. Increase springboot mysql connection pool configuration, HikariDataSource to use by default. Configuration is as follows
spring: datasource: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.cj.jdbc.Driver username: cjs-base password: xxx url: jdbc:mysql://xxx:3306/xxx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true hikari: minimum-idle: 100 maximum-pool-size: 500 idle-timeout: 30000 max-lifetime: 180000 # connection-timeout: 5000 Connection -test-Query: SELECT . 1 Connection -init-SQL: SELECT 2 # how many milliseconds detecting a leaking connection. Leak -detection-threshold: 1000 Test -ON-BORROW: to true Test -ON-Connect: to true Test -On- return : to true Test - the while -idle: to true # specify idle connection check, cleaning waste connection, connection idle operating time interval between the pool size adjustment time -between-eviction-the runs of millis-: 10000 # whether connection packaging, to prevent the connection closed after being used. use -disposable-Connection-Facade:to true Validation -interval: 10000 alidation -query: SELECT . 3 Validation -query-timeout: 5000 # connection check timeout setting, specifies the pool when a Connection Hikari alidation -timeout: 5000
In which the connection pool size, configuration items according to their own situation.
2. Modify fegin configuration, the general default is like. Mainly to prevent resource consumption can not be released, we need to set a relatively small timeout.
feign: hystrix: enabled: true okhttp: enabled: true httpclient: enabled: false client: config: feignName: connectTimeout: 1000 readTimeout: 1000 compression: request: enabled: true response: enabled: true
3. Modify hystrix configuration, the connector size is set to be greater than the amount required concurrent
hystrix: threadpool: default: coreSize: 500 maxQueueSize: 1000 command: default: circuitBreaker: requestVolumeThreshold: 50 execution: isolation: semaphore: maxConcurrentRequests: 1000 strategy: SEMAPHORE thread: timeoutInMilliseconds: 1000 shareSecurityContext: true
4. Modify ribbon configuration
# Timeout process request Ribbon: ReadTimeout: 1000 the ConnectTimeout: 1000
The increased number of instances of micro and services, expansion in the number of each micro-demand services K8S, each micro my side expansion three service instances, with the above configuration optimization, concurrency can be controlled at about 250 It has to meet current business needs. Such as the need for further optimization, can be used to increase the service instance, increased to achieve the implementation of NOSQL