database/sql: predictable request queue satisfaction #50358
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
change random satisfaction of the query queue to sequential
test simulate situation when query append faster that execution
Sitaution:
I have 2 source of query:
Trouble:
The connection poll satisfied request by random. This behavior does not guarantee the execution of the request in a finite time. I am faced with situation an unlimited growth of latency.
I make test to demonstration my situation.
Results of random satisfaction:
delay(diff = 5m30.844350115s, expected = 1m58.8s, max = 7m29.644350115s), queue(len=298, max=1486, min=364, diff=1122)
sql_db_test.go:51: current delay 7m34.568549607s is 2 times greater than expected 1m59.6s
--- FAIL: TestDB_queryQueue (600.00s)
FAIL
Results of sequenced satisfaction:
delay(diff = 344.00638ms, expected = 1m58.8s, max = 1m59.14400638s), queue(len=298, max=1486, min=1189, diff=297)
--- PASS: TestDB_queryQueue (600.00s)
PASS
queue.len - length of request to execution
queue.max - max index of request from queue
queue.min - min index of request from queue
queue.diff = queue.max - queue.min
If queue.diff is much longer that queue.len then queue has request with big latency
delay.expected = (queue.len - 1) * appendReuqestDelay
delay.max - latency of older request
delay.diff = delay.max - delay.expected
Solution:
Change the connection behavior from random to sequenced.