Skip to content
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

fix for issue #715 - ensure cached consul connections are specific to… #716

Merged
merged 1 commit into from
Jun 5, 2020

Conversation

miklish
Copy link
Collaborator

@miklish miklish commented Jun 4, 2020

… a thread to avoid concurrent use of the connections across threads.

See issue #715 for details.

… a thread to avoid concurrent use of the connections across threads
@codecov-commenter
Copy link

Codecov Report

Merging #716 into 1.6.x will not change coverage.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              1.6.x     #716   +/-   ##
=========================================
  Coverage     49.73%   49.73%           
  Complexity     1915     1915           
=========================================
  Files           261      261           
  Lines         11738    11738           
  Branches       1663     1663           
=========================================
  Hits           5838     5838           
  Misses         5209     5209           
  Partials        691      691           
Impacted Files Coverage Δ Complexity Δ
.../com/networknt/consul/client/ConsulClientImpl.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7d331a2...ddb88f0. Read the comment docs.

@stevehu stevehu requested a review from GavinChenYan June 4, 2020 20:45
Copy link
Contributor

@stevehu stevehu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@miklish It looks good to me. I found a method needsToCreateConnection called from the send method to ensure that the connection is open before using it. Thanks.

@GavinChenYan
Copy link
Contributor

It looks good. Thanks.

But if local thread is closed, the connection will be still in the cache map. Even the local thread ill be reused by JVM, but in special case the connection cache map could be group to big size:

private ConcurrentHashMap<String, ConsulConnection> connectionPool = new ConcurrentHashMap<>();

I would like suggest to add a feature to clear the connection pool cache if it reach config size (for example, 1000), we clear the map and let it rebuild by new connection:

connectionPool.clear()

@miklish
Copy link
Collaborator Author

miklish commented Jun 4, 2020

@miklish It looks good to me. I found a method needsToCreateConnection called from the send method to ensure that the connection is open before using it. Thanks.

@stevehu Yes, I saw that too. That is why I didn't add any code in getConnection to check if cached connections were still alive (as we had discussed yesterday).

@GavinChenYan
Copy link
Contributor

the default max work threads size is 200, maybe we are find with the cache size

@miklish
Copy link
Collaborator Author

miklish commented Jun 4, 2020

It looks good. Thanks.

But if local thread is closed, the connection will be still in the cache map. Even the local thread ill be reused by JVM, but in special case the connection cache map could be group to big size:

private ConcurrentHashMap<String, ConsulConnection> connectionPool = new ConcurrentHashMap<>();

I would like suggest to add a feature to clear the connection pool cache if it reach config size (for example, 1000), we clear the map and let it rebuild by new connection:

connectionPool.clear()

If the HTTP connection inside the ConsulConnection object is not used for a long time, I believe either undertow or Consul will kill the connection. So only the ConsulConnection object will remain holding a closed connection.

If later (after the connection has been closed), and a thread requests that same ConsulConnection object, the ConsulConnection object first checks the status of the connection it holds, and will create a new one if needed.

@stevehu stevehu merged commit cc5789f into 1.6.x Jun 5, 2020
@stevehu stevehu deleted the fix/consul-http branch June 5, 2020 16:22
stevehu pushed a commit that referenced this pull request Jun 5, 2020
… a thread to avoid concurrent use of the connections across threads (#716)
@miklish
Copy link
Collaborator Author

miklish commented Jun 5, 2020

@chenyan71 @jsu216 Can you folks approve today? @chenyan71 You have a tight timeline... it appears you are OK with the changes. If you could approve asap it would be appreciated.

@miklish
Copy link
Collaborator Author

miklish commented Jun 5, 2020

@chenyan71 @jsu216 Nevermind, I see that this has been merged already :)

younggwon1 pushed a commit to younggwon1/light-4j that referenced this pull request Feb 10, 2024
…ecific to a thread to avoid concurrent use of the connections across threads (networknt#716)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants