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

Refactor server stats updating on connection lifecycle hooks #1659

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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