Skip to content

Commit 2169b3f

Browse files
committed
queue pos exp documentation
1 parent 2a6574a commit 2169b3f

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

docs/software-architecture.md

+76
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,79 @@ The following sequence diagram shows the steps that are used with the Virtual Wa
289289

290290
![Use API Gateway Authorizer Sequence Diagram](use-api-gateway-authorizer.jpg)
291291

292+
293+
294+
295+
296+
## Understanding Queue Position Expiry
297+
298+
### Template parameters pertaining to queue position expiry
299+
1. EnableQueuePositionExpiry = allowed values of true or false.
300+
If set to `False`, queue position expiry period is not applicable.
301+
302+
2. QueuePositionExpiryPeriod (*QPExP*) = value is specified in seconds.
303+
It is the time interval beyond which a queue is ineligible to generate a token.
304+
305+
3. IncrSvcOnQueuePositionExpiry (*IncSCQP*) = allowed values of true or false.
306+
If set to `True`, SC is automatically advanced based on expired queue positions that were unable to generate tokens.
307+
308+
### Some definitions
309+
- Queue position entry time (*QPET*) = time at which a particular RID enters the queue
310+
- Token request time (*TRT*) = time at which RID requests a token, approx. current time
311+
- Serving Counter issue time (*SCIT*) = time at which the serving counter is incremented
312+
- Time in Queue (*TIQ*) = calculated based on eligibility to obtain a token when a particular *RID* gets in the queue
313+
- Max Queue Position Expired (*MQPE*) = marker for upper limit of queue positions that have expired (calculated metric)
314+
- If `QP <= MQPE` then we know the corresponding queue positions has expired without the need to check it's *TIQ*
315+
316+
### How do the related Dynamo DB tables look like?
317+
Queue Position EntryTime Table
318+
Updated when when a request id enters a queue.
319+
Example:
320+
|Request Id | Queue Position | Entry time | Status |
321+
---- | --- | --- | --- |
322+
1a02207b-92d5-48e0-820f-59329a86230c | 1 | 166023612 | 0
323+
7678f7fb-6535-4a06-a3ca-acbf62120e15 | 4 | 166023620 | 0
324+
c5ba2727-5e3f-43a2-9705-b4cad7c4198a | 2 | 166023614 | 0
325+
4369451c-5070-44a6-a5c7-421ff976bedb | 5 | 166023622 | 0
326+
32b6d7be-fd56-4a6a-a71c-25a15fab5089 | 3 | 166023615 | 0
327+
328+
Serving Counter IssuedAt Table (*SCIT*)
329+
Updated when the serving counter is incremented.
330+
The cumulative value is recorded in the Serving Counter column.
331+
Queue positions served is updated when a token is successfully generated for a queue position in the serving counter range
332+
Example:
333+
|Event Id|Serving Counter| Issue time | Queue Positions Served|
334+
---- | --- | --- | --- |
335+
|Sample | 10 | 166023600 | 8
336+
|Sample | 25 | 166023610 | 15
337+
|Sample | 45 | 166023620 | 6
338+
|Sample | 100 | 166023690 | 49
339+
340+
### How does *QPExP* work?
341+
Scenarios when you get in the queue:
342+
1. Serving Counter (SC) >= Queue position (QP)
343+
In this case, the TIQ is the time till the generation of JWT token is requested
344+
`TIQ = TRT - QPET`
345+
2. Serving Counter < Queue Position
346+
RID is eligible to obtain a token only when SC >= QP
347+
In this case TIQ is calculated from the time once the SC >= QP
348+
`TIQ = TRT - SCIT`
349+
350+
Succinctly `TIQ = Max(QPET, SCIT)`
351+
If `TIQ > QPET` then the *RID is no longer eligible* to obtain a JWT token else a token is generated
352+
353+
### Lambda: set_max_queue_position_expired
354+
This function is invoked periodically every minute.
355+
This checks the boundary values of *SCIT* if there is an expired QP corresponding to that value.
356+
If such a queue position exists then the MQPE value is set to that particular SC.
357+
We obtain values from *SCIT* with the condition `SC > MQPT`
358+
359+
### Lambda: get_queue_position_expiry_time
360+
This is invoked by calling the public_api?eventId=EvtId&requestId=reqId
361+
If `TIQ > QPET` then the remaining time is returned in seconds else an error message is returned
362+
363+
### Automatic Serving Counter increment based on expired queue positions. How does IncSCQP work ?
364+
In set_max_queue_position lambda, if `IncSCQP == True` then the serving counter is advanced using the following logic
365+
Increment the serving counter by taking the difference of counter item entries and subtract positions served in that range
366+
`Increment by = [(Current counter - Previous counter) - (Queue positions served in that range)]`
367+
This is done to recover *SC* values that were not used due to *QPExp*

0 commit comments

Comments
 (0)