moncheck - adjust queries to take less data
With selecting only the bare minimum we get much nicer performance.
This commit is contained in:
parent
f759b2f993
commit
1960907547
@ -64,7 +64,7 @@ func check(thread int, db *sql.DB, waitDuration time.Duration) {
|
|||||||
log.Printf("[%d] could not start transaction: %s", thread, err)
|
log.Printf("[%d] could not start transaction: %s", thread, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
rows, err := tx.Query("select check_id, check_id, cmdLine, states, next_time from active_checks where next_time < now() and enabled order by next_time for update skip locked limit 1;")
|
rows, err := tx.Query("select check_id, cmdLine, states, notify from active_checks where next_time < now() and enabled order by next_time for update skip locked limit 1;")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[%d] could not start query: %s", thread, err)
|
log.Printf("[%d] could not start query: %s", thread, err)
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
@ -128,12 +128,16 @@ func check(thread int, db *sql.DB, waitDuration time.Duration) {
|
|||||||
states = append([]int64{0}, states[:statePos]...)
|
states = append([]int64{0}, states[:statePos]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := tx.Exec("update active_checks set next_time = now() + interval, states = $2 where check_id = $1", id, pq.Array(&states)); err != nil {
|
if _, err := tx.Exec("update active_checks set next_time = now() + intval, states = $2 where check_id = $1", id, pq.Array(&states)); err != nil {
|
||||||
log.Printf("[%d] could not update row '%d': %s", thread, id, err)
|
log.Printf("[%d] could not update row '%d': %s", thread, id, err)
|
||||||
|
tx.Rollback()
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if notify {
|
if notify {
|
||||||
if _, err := tx.Exec("insert into notifications(check_id, states, output) values ($1, $2, $3);", id, pq.Array(&states), &output); err != nil {
|
if _, err := tx.Exec("insert into notifications(check_id, states, output) values ($1, $2, $3);", &id, pq.Array(&states), output.Bytes()); err != nil {
|
||||||
log.Printf("[%d] could not create notification for '%d': %s", thread, id, err)
|
log.Printf("[%d] could not create notification for '%d': %s", thread, id, err)
|
||||||
|
tx.Rollback()
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tx.Commit()
|
tx.Commit()
|
||||||
|
Loading…
Reference in New Issue
Block a user