Fair verification queue; up to 8 batches waiting per account (was 4)
Verification took the oldest batch overall, so the per-account cap of 4 was what kept one fast contributor from holding every slot. Now the next slot goes to the account with the fewest batches verifying, and the cap can be higher. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RNwtXPYqFu3oKaaXwYwNWW
This commit is contained in:
parent
e3fda917c5
commit
22b5975ffc
2 changed files with 7 additions and 2 deletions
|
|
@ -294,7 +294,7 @@ export class Tasks {
|
|||
return this.store.tx(() => {
|
||||
for (const id of ids) this.requireLease(user, id);
|
||||
// Keep the verification queue moving: a few batches waiting per account at a time.
|
||||
const max = this.config.maxQueuedBatches ?? 4;
|
||||
const max = this.config.maxQueuedBatches ?? 8;
|
||||
const waiting = this.store.get(`SELECT COUNT(*) AS n FROM batches WHERE user_id = ? AND state IN ('queued', 'verifying')`, user.id).n;
|
||||
if (waiting >= max) {
|
||||
throw new HttpError(429, `you have ${waiting} batches waiting for verification (the limit is ${max}); keep your claims, do peer reviews meanwhile (td_list_peer_reviews), and submit again when one is done (td_get_batch shows it)`, { retryAfterSeconds: 120 });
|
||||
|
|
|
|||
|
|
@ -79,7 +79,12 @@ export class Verifier {
|
|||
// Verification compiles only the submitted units, so every batch is small here; the units
|
||||
// that include a changed header are compiled in the merge's big lane.
|
||||
const b = this.store.tx(() => {
|
||||
const row = this.store.get(`SELECT * FROM batches WHERE state = 'queued' ORDER BY id LIMIT 1`);
|
||||
// Fair between accounts: the oldest batch of whoever has the fewest batches verifying, so a
|
||||
// fast contributor with several batches waiting does not hold every slot.
|
||||
const row = this.store.get(
|
||||
`SELECT b.* FROM batches b WHERE b.state = 'queued'
|
||||
ORDER BY (SELECT COUNT(*) FROM batches v WHERE v.user_id = b.user_id AND v.state = 'verifying'), b.id LIMIT 1`,
|
||||
);
|
||||
if (row) {
|
||||
this.store.run(`UPDATE batches SET state = 'verifying' WHERE id = ?`, row.id);
|
||||
this.store.run(`UPDATE attempts SET state = 'verifying' WHERE batch_id = ? AND state = 'queued'`, row.id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue