1.Tomcat覆盖默认配置 server: tomcat: max-connections: 2000 accept-count: 100 threads: max: 800 min-spare: 100 max-http-header-size: 131072 2.优化线程池配置 @EnableAsync @Configuration public class AsyncConfig { public static final int CPUNMU = Runtime.getRuntime().availableProcessors(); @Bean(name = "taskExecutor") public TaskExecutor taskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(CPUNMU); executor.setMaxPoolSize(CPUNMU * 25); executor.setQueueCapacity(5000); executor.setKeepAliveSeconds(60); executor.setThreadNamePrefix("Async-"); executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); executor.setWaitForTasksToCompleteOnShutdown(true); executor.setAwaitTerminationSeconds(60); return executor; } } 3.增加数据库连接池 @Primary @Bean(name = "dataSource") public DataSource dsDataSource(Environment environment) throws IOException { SQLServerDataSource ds = new SQLServerDataSource(); HikariDataSource ds2 = new HikariDataSource(); ds2.setDataSource(ds); ds2.setMaximumPoolSize(100); ds2.setConnectionTimeout(1800000); ds2.setPoolName("DataSource-"); ds2.setMinimumIdle(20); } catch (Exception e) { logger.error("Config error: {}", e.getMessage()); } return ds2; 4.增加缓存(SpringBoot Cache) // Constant info cache private static Map<String, String> constantCache = new ConcurrentHashMap<>(1024 * 5); // token cache private static Map<String, TokenCache> tokenCache = new ConcurrentHashMap<>(1024 * 5); 5.优化索引 5.增加Pod数量 6.增加Ingress数量 7.升级数据库的DTU 8.第三方API采用多线程调用 9.blob文件上传下载采用多线程 10.异步日志
<Loggers> <AsyncLogger name="com.xx.Main" level="trace" additivity="false"> <appender-ref ref="RollingFile"/> </AsyncLogger> <AsyncLogger name="RollingFile2" level="trace" additivity="false"> <appender-ref ref="RollingFile2"/> </AsyncLogger> <Root level="debug"> <AppenderRef ref="Console"/> <AppenderRef ref="RollingFile"/> </Root> </Loggers>