2月14日

(二)性能优化
分析性能瓶颈
使用Prometheus和Grafana监控系统资源(CPU、内存、响应时间)。
使用Spring Boot Actuator收集应用性能指标:
在pom.xml中添加Actuator依赖:
xml

org.springframework.boot
spring-boot-starter-actuator

在application.properties中启用Actuator端点:
properties
management.endpoints.web.exposure.include=*
优化数据库查询
使用MyBatis缓存机制减少数据库访问:
xml

分析慢查询日志,优化SQL语句。
优化缓存策略
使用Redis缓存热点数据,减少数据库压力。
在UserService中缓存用户信息:
java
@Service
public class UserService {
@Autowired
private UserMapper userMapper;
@Autowired
private StringRedisTemplate redisTemplate;

@Cacheable(value = "user", key = "#id")
public User getById(Long id) {
    return userMapper.selectById(id);
}

}
优化线程池配置
在application.properties中调整线程池配置:
properties
server.tomcat.max-threads=400
server.tomcat.min-spare-threads=50

posted @   skurar  阅读(1)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示