-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add jitter to max lifetime in connection pool #1496
base: master
Are you sure you want to change the base?
feat: add jitter to max lifetime in connection pool #1496
Conversation
dedff31
to
3629f5d
Compare
@vietj Changes for the jitter have been added. I have some doubts regarding the test cases. One way to verify this is by creating a pool and fetching a connection. Then, using a timer, check every few milliseconds whether the connection is still active. Once it closes, record the time. Repeat this process three times and ensure that each recorded time is different. |
3629f5d
to
2235e03
Compare
how can we test this ? |
Signed-off-by: priyanshu-d11 <[email protected]>
2235e03
to
61d0455
Compare
@priyanshu-d11 I think we could test with a TCP server that just does nothing and create a pool of 100 connections and perform a connect storm and measure the connection time between the client and server and ensure that we get a spread of the collected latencies ? we could add a min jitter time that could be helpful for testing, e.g. if we set 30 milliseconds then we can check that there are no latencies under 30 milliseconds |
…ertions Signed-off-by: priyanshu-d11 <[email protected]>
I have added a test case. Here's what the test does:
Let me know if you want me to explain any part in more detail or if you have any other idea to test this scenario. |
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove star import
@@ -105,6 +110,7 @@ public class PoolOptions { | |||
private boolean shared = DEFAULT_SHARED_POOL; | |||
private String name = DEFAULT_NAME; | |||
private int eventLoopSize = DEFAULT_EVENT_LOOP_SIZE; | |||
private int jitter = DEFAULT_JITTER; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we also need a jitterTimeUnit
property which should be by default Willis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
I am looking at the contribution, how does it work initially when the pool is empty and many connections attempts can be made simultaneously ? |
vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/pool/SqlConnectionPool.java
Outdated
Show resolved
Hide resolved
long randomizedJitter = (maxLifetime > 0 && jitter > 0 && maxLifetime > jitter) ? ThreadLocalRandom.current().nextLong(-jitter, jitter + 1) : 0; | ||
this.lifetimeEvictionTimestamp = maxLifetime > 0 ? System.currentTimeMillis() + maxLifetime + randomizedJitter : Long.MAX_VALUE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
long randomizedJitter = (maxLifetime > 0 && jitter > 0 && maxLifetime > jitter) ? ThreadLocalRandom.current().nextLong(-jitter, jitter + 1) : 0; | |
this.lifetimeEvictionTimestamp = maxLifetime > 0 ? System.currentTimeMillis() + maxLifetime + randomizedJitter : Long.MAX_VALUE; | |
this.lifetimeEvictionTimestamp = maxLifetime > 0 ? System.currentTimeMillis() + maxLifetime + Math.max(0, ThreadLocalRandom.current().nextLong(0, jitter)) : Long.MAX_VALUE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added this with nextLong(0, jitter+1)
@vietj Added a test case which does the following: Acquiring 50 connections in parallel.
|
@vietj While reviewing the test cases, I came across one for a |
Connection Storm Prevention with Jitter in Connection Pool #1495
Introduce connection jitter to randomize connection timing:
Fix: #1495