Skip to content

Commit a2c8e9c

Browse files
Fix redundant connection profile instantiations (#95332)
Creating the default connection profile is very expensive (takes ~100s of CPU time for the server:internalClusterTests goal alone). We can just use the default profile overload to avoid this cost without changing behavior.
1 parent 82220b4 commit a2c8e9c

File tree

5 files changed

+7
-9
lines changed

5 files changed

+7
-9
lines changed

server/src/main/java/org/elasticsearch/cluster/coordination/CoordinationDiagnosticsService.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.elasticsearch.core.TimeValue;
3838
import org.elasticsearch.threadpool.Scheduler;
3939
import org.elasticsearch.threadpool.ThreadPool;
40-
import org.elasticsearch.transport.ConnectionProfile;
4140
import org.elasticsearch.transport.TransportRequestOptions;
4241
import org.elasticsearch.transport.TransportService;
4342

@@ -1156,7 +1155,6 @@ public void run() {
11561155
transportService.connectToNode(
11571156
// Note: This connection must be explicitly closed in the connectionListener
11581157
masterEligibleNode,
1159-
ConnectionProfile.buildDefaultConnectionProfile(clusterService.getSettings()),
11601158
connectionListener
11611159
);
11621160
}

server/src/main/java/org/elasticsearch/cluster/coordination/MasterHistoryService.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.elasticsearch.core.Releasables;
2323
import org.elasticsearch.core.TimeValue;
2424
import org.elasticsearch.threadpool.ThreadPool;
25-
import org.elasticsearch.transport.ConnectionProfile;
2625
import org.elasticsearch.transport.TransportRequestOptions;
2726
import org.elasticsearch.transport.TransportService;
2827

@@ -36,7 +35,6 @@
3635
public class MasterHistoryService {
3736
private final TransportService transportService;
3837
private final MasterHistory localMasterHistory;
39-
private final ClusterService clusterService;
4038
private final LongSupplier currentTimeMillisSupplier;
4139
private final TimeValue acceptableRemoteHistoryAge;
4240
/*
@@ -62,7 +60,6 @@ public class MasterHistoryService {
6260
public MasterHistoryService(TransportService transportService, ThreadPool threadPool, ClusterService clusterService) {
6361
this.transportService = transportService;
6462
this.localMasterHistory = new MasterHistory(threadPool, clusterService);
65-
this.clusterService = clusterService;
6663
this.currentTimeMillisSupplier = threadPool::relativeTimeInMillis;
6764
this.acceptableRemoteHistoryAge = REMOTE_HISTORY_TIME_TO_LIVE_SETTING.get(clusterService.getSettings());
6865
}
@@ -128,7 +125,6 @@ public void refreshRemoteMasterHistory(DiscoveryNode node) {
128125
transportService.connectToNode(
129126
// Note: This connection must be explicitly closed below
130127
node,
131-
ConnectionProfile.buildDefaultConnectionProfile(clusterService.getSettings()),
132128
new ActionListener<>() {
133129
@Override
134130
public void onResponse(Releasable releasable) {

server/src/main/java/org/elasticsearch/transport/ConnectionManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import org.elasticsearch.action.ActionListener;
1212
import org.elasticsearch.cluster.node.DiscoveryNode;
13+
import org.elasticsearch.core.Nullable;
1314
import org.elasticsearch.core.Releasable;
1415

1516
import java.io.Closeable;
@@ -26,7 +27,7 @@ public interface ConnectionManager extends Closeable {
2627

2728
void connectToNode(
2829
DiscoveryNode node,
29-
ConnectionProfile connectionProfile,
30+
@Nullable ConnectionProfile connectionProfile,
3031
ConnectionValidator connectionValidator,
3132
ActionListener<Releasable> listener
3233
) throws ConnectTransportException;

server/src/main/java/org/elasticsearch/transport/TransportService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,11 @@ public void connectToNode(DiscoveryNode node, ActionListener<Releasable> listene
465465
* @param connectionProfile the connection profile to use when connecting to this node
466466
* @param listener the action listener to notify
467467
*/
468-
public void connectToNode(final DiscoveryNode node, ConnectionProfile connectionProfile, ActionListener<Releasable> listener) {
468+
public void connectToNode(
469+
final DiscoveryNode node,
470+
@Nullable ConnectionProfile connectionProfile,
471+
ActionListener<Releasable> listener
472+
) {
469473
if (isLocalNode(node)) {
470474
listener.onResponse(null);
471475
return;

server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,6 @@ private void startCluster() {
13131313
.forEach(
13141314
n -> n.transportService.connectToNode(
13151315
node.node,
1316-
null,
13171316
ActionTestUtils.assertNoFailureListener(c -> logger.info("--> Connected [{}] to [{}]", n.node, node.node))
13181317
)
13191318
)

0 commit comments

Comments
 (0)