Skip to content

Aries-2121 Add TCP provider connection persistence with connection pool#58

Open
amichair wants to merge 5 commits intoapache:masterfrom
amichair:ARIES-2121
Open

Aries-2121 Add TCP provider connection persistence with connection pool#58
amichair wants to merge 5 commits intoapache:masterfrom
amichair:ARIES-2121

Conversation

@amichair
Copy link
Copy Markdown
Contributor

@amichair amichair commented Jul 2, 2025

Implements ARIES-2121 wtih a simple connection pool. Performance tests (when increasing the number of calls in TcpProviderTest) show an increase in throuput on the order of 100x.

Note that this PR is on top of ARIES-2120, so that PR has to be merged first.

@jbonofre jbonofre self-requested a review October 5, 2025 10:54
BasicObjectOutputStream out;
BasicObjectInputStream in;

public Connection(Socket socket) throws IOException {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpicking: public is not necessary

private int timeoutMillis;

private final Deque<Connection> pool = new ArrayDeque<>();
private int acquired; // counts connections currently in use (not in pool)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we can make the comment a javadoc

private Connection acquireConnection() throws IOException {
Connection conn;
synchronized (pool) {
acquired++; // must be first
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

there are no limits?

Connection conn;
synchronized (pool) {
acquired++; // must be first
if (closed) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this check may be first?

return conn;
}

// must be called exactly once for each call to acquireConnection,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the comments above the methods may be the javadoc

// regardless of the outcome - if there was an error, pass null
private void releaseConnection(Connection conn) {
synchronized (pool) {
acquired--; // must be first
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we have negative check?


private void closeConnection(Connection conn) throws IOException {
if (conn != null) {
conn.socket.close();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  1. can we have method close on Connection class?
  2. we don't need to close in/out?

closed = true; // first prevent acquiring new connections
while (true) {
// close all idle connections
for (Iterator<Connection> it = pool.iterator(); it.hasNext(); ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  1. can we use for each normally? for (Connection connection : pool)?
  2. should we run in try catch for each connection?

handleCall(invoker, in, out);
}
} catch (SocketException | SocketTimeoutException | EOFException se) {
return; // e.g. connection closed by client or read timeout due to inactivity
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we log on debug?

* over a TCP connection, to be executed by the remote service.
*/
public class TcpInvocationHandler implements InvocationHandler {
public class TcpInvocationHandler implements InvocationHandler, Closeable {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we test the new changes? there are not a lot of tests at the end of this PR

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.

2 participants