From 1960907547d5da614a73ea35247bbaf771ced3c5 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Fri, 16 Nov 2018 20:09:31 +0100 Subject: moncheck - adjust queries to take less data With selecting only the bare minimum we get much nicer performance. --- cmd/moncheck/main.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'cmd') diff --git a/cmd/moncheck/main.go b/cmd/moncheck/main.go index ca31a02..dba3099 100644 --- a/cmd/moncheck/main.go +++ b/cmd/moncheck/main.go @@ -64,7 +64,7 @@ func check(thread int, db *sql.DB, waitDuration time.Duration) { log.Printf("[%d] could not start transaction: %s", thread, err) 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 { log.Printf("[%d] could not start query: %s", thread, err) tx.Rollback() @@ -128,12 +128,16 @@ func check(thread int, db *sql.DB, waitDuration time.Duration) { 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) + tx.Rollback() + continue } 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) + tx.Rollback() + continue } } tx.Commit() -- cgit v1.2.3-70-g09d2