Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 当业务下有大量的执行作业,加载 web 页面首页的时候会触发DB慢查询 #2228

Closed
wangyu096 opened this issue Jul 14, 2023 · 1 comment
Labels
done 已上线到正式环境并验收通过 for test 可以在测试环境进行验收 kind/bug 程序故障Bug,漏洞

Comments

@wangyu096
Copy link
Collaborator

Version / Branch / tag
3.7.X

出了什么问题?(What Happened?)

当业务下有大量的执行作业,加载 web 页面首页的时候会触发DB慢查询

慢查询 SQL

select count(*) from `job_execute`.`task_instance` where (`job_execute`.`task_instance`.`app_id` = 9991001 and `job_execute`.`task_instance`.`create_time` >= -2591941000);

触发慢查询的 API:
image

createTime >= -2591941000 会导致全表扫描。这个时间为负数,是不合法的
如何复现?(How to reproduce?)

加载首页 - 查询最近执行记录必现

预期结果(What you expect?)
优化慢查询

@wangyu096 wangyu096 added kind/bug 程序故障Bug,漏洞 backlog 需求初始状态,等待产品进行评估 todo 进入开发排期的状态,纳入了最近的迭代 labels Jul 14, 2023
@wangyu096
Copy link
Collaborator Author

wangyu096 commented Jul 14, 2023

问题分析

企业微信截图_97b7ce4e-20e4-4b64-b39e-f5ce04e308ef 企业微信截图_84a6a8c8-1e6d-4604-abcf-cd4f5de4c5e0 image

计算开始时间错误,LocalDateTime.of(LocalDate.now(), LocalTime.MAX).getSecond() 实际上获取的秒数,这里都是 固定返回59 秒,导致 start 算出来为 59*1000-30 * 24 * 3600 * 1000= -2591941000

wangyu096 added a commit that referenced this issue Jul 14, 2023
fix: 当业务下有大量的执行作业,加载 web 页面首页的时候会触发DB慢查询 #2228
jsonwan added a commit that referenced this issue Jul 17, 2023
fix: 当业务下有大量的执行作业,加载 web 页面首页的时候会触发DB慢查询 #2228
@bkjob-bot bkjob-bot added done 已上线到正式环境并验收通过 and removed backlog 需求初始状态,等待产品进行评估 todo 进入开发排期的状态,纳入了最近的迭代 labels Jul 17, 2023
jsonwan added a commit that referenced this issue Jul 18, 2023
fix: 当业务下有大量的执行作业,加载 web 页面首页的时候会触发DB慢查询 #2228
@bkjob-bot bkjob-bot added the for test 可以在测试环境进行验收 label Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
done 已上线到正式环境并验收通过 for test 可以在测试环境进行验收 kind/bug 程序故障Bug,漏洞
Projects
None yet
Development

No branches or pull requests

2 participants