Skip to content

PriorityHandling

Ulrich Germann edited this page Feb 4, 2021 · 6 revisions

Priority Handling in the Request Queue

Here's what I (UG) propose for handling priorities in the queue.

As usual, please respond by using quotation markup (> , >>, etc.) to respond to suggestions and responses, and mark with your github id so that we can keep track of who's saying what.

ugermann: Like so ...

SomeoneElse: Responding to @ugermann.

Currently, Individual Sentence Translation Requests ('request') are prioritised by sequence numbers. The sequence number is incrementally increased for each incoming request, and the lower the sequence number, the higher the priority.

I propose to combine this with priority levels based on the notion of patience. Let's assume we implement patience and sequence numbers as signed integer values.

  • A request is automatically assigned a sequence number (int32_t; if we reach the end of the range new requests should be blocked until the queue is empty and then the sequence number should be reset to 0; this will happen only very, very rarely, if ever, but the code should provide for it. If the queue is ever idle, we can automatically reset the sequence counter). Currently, the sequence number is the sole criterion that determines the order of priority.

  • In addition, requests will have a patience level (int32_t). This parameter indicates how many other requests a particular request is willing to let in front of it before insisting on being processed.

  • For patience levels < 0, the patience level is the primary sorting criterion and the sequence number is the tie breaker.

  • For patience levels >= 0, the sum of sequence number and patience level is the primary sorting criterion, and the sequence number is the tie breaker.

e.g.

if (A.patience == B.patience) {   // I expect this to be the most common case, so we check this first
  return A.sequence_number < B.sequence_number;
}
else if (A.patience <= 0 || B.patience <= 0) {
  return A.patience < B.patience; // One of the two is impatient; go by patience level
}
else { // both are patient, go by sum of patience level and sequence number
  return int64_t(A.sequence_number) + A.patience < int64_t(B.sequence_number) + B.patience;
}
Clone this wiki locally