Skip to content

Commit

Permalink
Reset the following timestamp slot to avoid possible race-collisions …
Browse files Browse the repository at this point in the history
…(GC thread is not aligned to wall clock)

Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Oct 3, 2024
1 parent 7ec1478 commit 7e12e40
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/shmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1219,11 +1219,12 @@ void update_qps(const time_t timestamp)
shmSettings->qps[slot]++;
}

// Reset queries per second (qps) value for a given timeslot
// Reset queries per second (qps) value for the timeslot following the current
// one
void reset_qps(const time_t timestamp)
{
// Get the timeslot for the current timestamp
const unsigned int slot = timestamp % QPS_AVGLEN;
const unsigned int slot = (timestamp + 1) % QPS_AVGLEN;

// Reset the query count
shmSettings->qps[slot] = 0;
Expand All @@ -1241,5 +1242,6 @@ double __attribute__((pure)) get_qps(void)
for(unsigned int i = 0; i < QPS_AVGLEN; i++)
qps += shmSettings->qps[i];

// Return the computed value divided by N (the number of slots)
return qps / QPS_AVGLEN;
}

0 comments on commit 7e12e40

Please sign in to comment.