mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2026-03-03 22:57:29 +01:00
Further optimize queries for better index usage
This commit is contained in:
@@ -718,7 +718,7 @@ func (r *JobRepository) StopJobsExceedingWalltimeBy(seconds int) error {
|
|||||||
Set("job_state", schema.JobStateFailed).
|
Set("job_state", schema.JobStateFailed).
|
||||||
Where("job.job_state = 'running'").
|
Where("job.job_state = 'running'").
|
||||||
Where("job.walltime > 0").
|
Where("job.walltime > 0").
|
||||||
Where("(? - job.start_time) > (job.walltime + ?)", currentTime, seconds).
|
Where("job.start_time < (? - job.walltime)", currentTime-int64(seconds)).
|
||||||
RunWith(r.DB).Exec()
|
RunWith(r.DB).Exec()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cclog.Warnf("Error while stopping jobs exceeding walltime: %v", err)
|
cclog.Warnf("Error while stopping jobs exceeding walltime: %v", err)
|
||||||
|
|||||||
@@ -270,24 +270,21 @@ func (r *JobRepository) FindConcurrentJobs(
|
|||||||
stopTime = startTime + int64(job.Duration)
|
stopTime = startTime + int64(job.Duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Time buffer constants for finding overlapping jobs
|
// Time buffer constant for finding overlapping jobs
|
||||||
// overlapBufferStart: 10s grace period at job start to catch jobs starting just after
|
|
||||||
// overlapBufferEnd: 200s buffer at job end to account for scheduling/cleanup overlap
|
// overlapBufferEnd: 200s buffer at job end to account for scheduling/cleanup overlap
|
||||||
const overlapBufferStart = 10
|
|
||||||
const overlapBufferEnd = 200
|
const overlapBufferEnd = 200
|
||||||
|
|
||||||
startTimeTail := startTime + overlapBufferStart
|
|
||||||
stopTimeTail := stopTime - overlapBufferEnd
|
stopTimeTail := stopTime - overlapBufferEnd
|
||||||
startTimeFront := startTime + overlapBufferEnd
|
startTimeFront := startTime + overlapBufferEnd
|
||||||
|
|
||||||
// Reminder: BETWEEN Queries are slower and dont use indices as frequently: Can this be optimized?
|
queryRunning := query.Where("job.job_state = ?", "running").
|
||||||
queryRunning := query.Where("job.job_state = ?").Where("(job.start_time BETWEEN ? AND ? OR job.start_time < ?)",
|
Where("job.start_time <= ?", stopTimeTail)
|
||||||
"running", startTimeTail, stopTimeTail, startTime)
|
|
||||||
// Get At Least One Exact Hostname Match from JSON Resources Array in Database
|
// Get At Least One Exact Hostname Match from JSON Resources Array in Database
|
||||||
queryRunning = queryRunning.Where("EXISTS (SELECT 1 FROM json_each(job.resources) WHERE json_extract(value, '$.hostname') = ?)", hostname)
|
queryRunning = queryRunning.Where("EXISTS (SELECT 1 FROM json_each(job.resources) WHERE json_extract(value, '$.hostname') = ?)", hostname)
|
||||||
|
|
||||||
query = query.Where("job.job_state != ?").Where("((job.start_time BETWEEN ? AND ?) OR (job.start_time + job.duration) BETWEEN ? AND ? OR (job.start_time < ?) AND (job.start_time + job.duration) > ?)",
|
query = query.Where("job.job_state != ?", "running").
|
||||||
"running", startTimeTail, stopTimeTail, startTimeFront, stopTimeTail, startTime, stopTime)
|
Where("job.start_time < ?", stopTimeTail).
|
||||||
|
Where("(job.start_time + job.duration) > ?", startTimeFront)
|
||||||
// Get At Least One Exact Hostname Match from JSON Resources Array in Database
|
// Get At Least One Exact Hostname Match from JSON Resources Array in Database
|
||||||
query = query.Where("EXISTS (SELECT 1 FROM json_each(job.resources) WHERE json_extract(value, '$.hostname') = ?)", hostname)
|
query = query.Where("EXISTS (SELECT 1 FROM json_each(job.resources) WHERE json_extract(value, '$.hostname') = ?)", hostname)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user