Mybatis-plus性能分析功能
性能分析拦截器,用于输出每条 SQL 语句及其执行时间
SQL 性能执行分析,开发环境使用,超过指定时间,停止运行。有助于发现问题
1、配置插件
1、参数说明
参数:maxTime: SQL 执行最大时长,超过自动停止运行,有助于发现问题。
参数:format: SQL是否格式化,默认false。
2、在 MybatisPlusConfig 中配置
/**
* SQL 执行性能分析插件
* 开发环境使用,线上不推荐。 maxTime 指的是 sql 最大执行时长
* 三种环境
* dev开发环境
* test测试环境
* prod生产环境
*/
@Bean
@Profile({"dev","test"})// 设置 dev test 环境开启
public PerformanceInterceptor performanceInterceptor() {
PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
performanceInterceptor.setMaxTime(200);//ms,超过此处设置的ms则sql不执行
performanceInterceptor.setFormat(true);
return performanceInterceptor;
}
3、Spring Boot 中设置dev环境
在application.properties中加入
#环境设置:dev、test、prod
spring.profiles.active=dev
可以针对各环境新建不同的配置文件application-dev.properties、application-test.properties、application-prod.properties
也可以自定义环境名称:如test1、test2
二、测试
1、常规测试
//添加操作
@Test
public void addUser(){
User user=new User();
user.setName("哎呦尼亚");
user.setAge(88);
user.setEmail("chahasas5461@qq.com");
// userMapper.insert(user);
Integer insert=userMapper.insert(user);
System.out.println("insert:"+insert);
// int shu=userMapper.insert(user);
// System.out.println("insert:"+shu);
}
二、使用步骤
1.引入库
代码如下(示例):
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
2、将maxTime 改小之后再次进行测试
performanceInterceptor.setMaxTime(1);//ms,超过此处设置的ms不执行
如果执行时间过长,则抛出异常:The SQL execution time is too large,