Skip to content

Commit

Permalink
Refactor server stats updating on connection lifecycle hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinbunney committed Oct 6, 2023
1 parent 5222417 commit 9b4eacb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ public boolean release(final PooledConnection conn) {
connsInUse.decrementAndGet();

final DiscoveryResult discoveryResult = conn.getServer();
discoveryResult.decrementActiveRequestsCount();
discoveryResult.incrementNumRequests();
updateServerStatsOnRelease(conn);

boolean released = false;

Expand Down Expand Up @@ -274,6 +273,12 @@ public boolean release(final PooledConnection conn) {
return released;
}

protected void updateServerStatsOnRelease(final PooledConnection conn) {
final DiscoveryResult discoveryResult = conn.getServer();
discoveryResult.decrementActiveRequestsCount();
discoveryResult.incrementNumRequests();
}

protected void releaseHandlers(PooledConnection conn) {
final ChannelPipeline pipeline = conn.getChannel().pipeline();
removeHandlerFromPipeline(OriginResponseReceiver.CHANNEL_HANDLER_NAME, pipeline);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public Promise<PooledConnection> acquire(
}

requestConnCounter.increment();
server.incrementActiveRequestsCount();
updateServerStatsOnAcquire();

Promise<PooledConnection> promise = eventLoop.newPromise();

Expand All @@ -180,6 +180,10 @@ public Promise<PooledConnection> acquire(
return promise;
}

protected void updateServerStatsOnAcquire() {
server.incrementActiveRequestsCount();
}

public PooledConnection tryGettingFromConnectionPool(EventLoop eventLoop) {
PooledConnection conn;
Deque<PooledConnection> connections = getPoolForEventLoop(eventLoop);
Expand Down Expand Up @@ -284,25 +288,29 @@ protected ChannelFuture connectToServer(EventLoop eventLoop, CurrentPassport pas
protected void handleConnectCompletion(
ChannelFuture cf, Promise<PooledConnection> callerPromise, CurrentPassport passport) {
connCreationsInProgress.decrementAndGet();

updateServerStatsOnConnectCompletion(cf);
if (cf.isSuccess()) {

passport.add(PassportState.ORIGIN_CH_CONNECTED);
server.incrementOpenConnectionsCount();
createConnSucceededCounter.increment();
connsInUse.incrementAndGet();

createConnection(cf, callerPromise, passport);
} else {
server.incrementSuccessiveConnectionFailureCount();
server.addToFailureCount();
server.decrementActiveRequestsCount();
createConnFailedCounter.increment();
callerPromise.setFailure(
new OriginConnectException(cf.cause().getMessage(), cf.cause(), OutboundErrorType.CONNECT_ERROR));
}
}

protected void updateServerStatsOnConnectCompletion(ChannelFuture cf) {
if (cf.isSuccess()) {
server.incrementOpenConnectionsCount();
} else {
server.incrementSuccessiveConnectionFailureCount();
server.addToFailureCount();
server.decrementActiveRequestsCount();
}
}

protected void createConnection(
ChannelFuture cf, Promise<PooledConnection> callerPromise, CurrentPassport passport) {
final PooledConnection conn = pooledConnectionFactory.create(cf.channel());
Expand Down

0 comments on commit 9b4eacb

Please sign in to comment.