Skip to content

Commit

Permalink
only check every 10.000 row if the query has been canceled
Browse files Browse the repository at this point in the history
checking the channel did take too much time
  • Loading branch information
sni committed Sep 20, 2023
1 parent 5472bfa commit d0332e2
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions lmd/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import (
const (
// SpinUpPeersTimeout sets timeout to wait for peers after spin up
SpinUpPeersTimeout = 5 * time.Second

// Number of processes rows after which the context is checked again
RowContextCheck = 10000
)

// Response contains the livestatus response data as long with some meta data
Expand Down Expand Up @@ -865,12 +868,15 @@ func (res *Response) gatherResultRows(ctx context.Context, store *DataStore, res

done := ctx.Done()
Rows:
for _, row := range store.GetPreFilteredData(req.Filter) {
select {
case <-done:
// request canceled
return
default:
for i, row := range store.GetPreFilteredData(req.Filter) {
// only check every couple of rows
if i%RowContextCheck == 0 {
select {
case <-done:
// request canceled
return
default:
}
}

result.RowsScanned++
Expand Down Expand Up @@ -907,12 +913,15 @@ func (res *Response) gatherStatsResult(ctx context.Context, store *DataStore) *R

done := ctx.Done()
Rows:
for _, row := range store.GetPreFilteredData(req.Filter) {
select {
case <-done:
// request canceled
return nil
default:
for i, row := range store.GetPreFilteredData(req.Filter) {
// only check every couple of rows
if i%RowContextCheck == 0 {
select {
case <-done:
// request canceled
return nil
default:
}
}
result.RowsScanned++
// does our filter match?
Expand Down

0 comments on commit d0332e2

Please sign in to comment.