This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 88119243f99 HDDS-17357. Initialize Netty in background when Ozone
client is created (#11726)
88119243f99 is described below
commit 88119243f9904ad5686015a2d49de09b8d8847fc
Author: Andrey Yarovoy <[email protected]>
AuthorDate: Sun Oct 25 12:42:31 2026 -0400
HDDS-17357. Initialize Netty in background when Ozone client is created
(#11726)
---
.../org/apache/hadoop/hdds/scm/NettyWarmUp.java | 75 ++++++++++++++++++++
.../apache/hadoop/hdds/scm/OzoneClientConfig.java | 18 +++++
.../hadoop/hdds/scm/XceiverClientCreator.java | 9 ++-
.../apache/hadoop/hdds/scm/TestNettyWarmUp.java | 79 ++++++++++++++++++++++
.../hadoop/hdds/scm/TestOzoneClientConfig.java | 9 +++
5 files changed, 189 insertions(+), 1 deletion(-)
diff --git
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/NettyWarmUp.java
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/NettyWarmUp.java
new file mode 100644
index 00000000000..cf251afef95
--- /dev/null
+++
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/NettyWarmUp.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hdds.scm;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.ratis.thirdparty.io.netty.buffer.PooledByteBufAllocator;
+import org.apache.ratis.thirdparty.io.netty.handler.ssl.OpenSsl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Initializes Netty, and for TLS netty-tcnative (BoringSSL), on a background
thread, so that a client's first
+ * datanode connection finds them ready instead of initializing them itself
(about 0.1 s in a cold JVM).
+ */
+final class NettyWarmUp {
+ private static final Logger LOG = LoggerFactory.getLogger(NettyWarmUp.class);
+ private static final AtomicBoolean STARTED = new AtomicBoolean();
+
+ private NettyWarmUp() {
+ }
+
+ /**
+ * Starts the warm-up, at most once per JVM.
+ *
+ * @param tls whether to also load and initialize netty-tcnative
+ * @return the warm-up thread, or null if the warm-up was started before
+ */
+ static Thread start(boolean tls) {
+ if (!STARTED.compareAndSet(false, true)) {
+ return null;
+ }
+ final Thread thread = new Thread(() -> warmUp(tls),
"ozone-client-netty-warm-up");
+ thread.setDaemon(true);
+ thread.start();
+ return thread;
+ }
+
+ static void warmUp(boolean tls) {
+ try {
+ PooledByteBufAllocator.DEFAULT.directBuffer(1).release();
+ if (tls) {
+ OpenSsl.isAvailable();
+ }
+ } catch (Throwable t) {
+ // the first connection initializes whatever is missing, as without the
warm-up
+ LOG.debug("Netty warm-up failed", t);
+ }
+ }
+
+ @VisibleForTesting
+ static boolean isStarted() {
+ return STARTED.get();
+ }
+
+ @VisibleForTesting
+ static void reset() {
+ STARTED.set(false);
+ }
+}
diff --git
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/OzoneClientConfig.java
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/OzoneClientConfig.java
index 6044e53efda..435478d1ac7 100644
---
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/OzoneClientConfig.java
+++
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/OzoneClientConfig.java
@@ -380,6 +380,16 @@ public class OzoneClientConfig {
description = "Timeout for receiving streaming read responses.")
private Duration streamReadTimeout = Duration.ofSeconds(10);
+ @Config(key = "ozone.client.netty.warmup.enabled",
+ defaultValue = "true",
+ type = ConfigType.BOOLEAN,
+ tags = {ConfigTag.CLIENT},
+ description = "When the client is created, initialize Netty, and
netty-tcnative (BoringSSL) if gRPC TLS is " +
+ "enabled, on a background thread, so the first datanode connection
does not wait for them. This takes " +
+ "about 0.1 s in a new JVM, so it matters for short-lived clients
such as YARN containers and CLI " +
+ "commands. It needs a spare CPU core to help.")
+ private boolean nettyWarmUpEnabled = true;
+
@PostConstruct
public void validate() {
Preconditions.checkState(streamBufferSize > 0);
@@ -473,6 +483,14 @@ public boolean isShortCircuitEnabled() {
return shortCircuitEnabled;
}
+ public boolean isNettyWarmUpEnabled() {
+ return nettyWarmUpEnabled;
+ }
+
+ public void setNettyWarmUpEnabled(boolean nettyWarmUpEnabled) {
+ this.nettyWarmUpEnabled = nettyWarmUpEnabled;
+ }
+
public void setShortCircuit(boolean enabled) {
shortCircuitEnabled = enabled;
}
diff --git
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientCreator.java
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientCreator.java
index d68836bd3fe..f3810d0783e 100644
---
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientCreator.java
+++
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientCreator.java
@@ -17,6 +17,9 @@
package org.apache.hadoop.hdds.scm;
+import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_GRPC_TLS_ENABLED;
+import static
org.apache.hadoop.hdds.HddsConfigKeys.HDDS_GRPC_TLS_ENABLED_DEFAULT;
+
import java.io.IOException;
import java.util.Objects;
import org.apache.hadoop.hdds.conf.ConfigurationSource;
@@ -55,7 +58,11 @@ public XceiverClientCreator(ConfigurationSource conf,
ClientTrustManager trustMa
if (securityEnabled) {
Objects.requireNonNull(trustManager, "trustManager == null");
}
- shortCircuitEnabled =
conf.getObject(OzoneClientConfig.class).isShortCircuitEnabled();
+ final OzoneClientConfig clientConfig =
conf.getObject(OzoneClientConfig.class);
+ if (clientConfig.isNettyWarmUpEnabled()) {
+ NettyWarmUp.start(securityEnabled &&
conf.getBoolean(HDDS_GRPC_TLS_ENABLED, HDDS_GRPC_TLS_ENABLED_DEFAULT));
+ }
+ shortCircuitEnabled = clientConfig.isShortCircuitEnabled();
if (shortCircuitEnabled) {
domainSocketFactory = DomainSocketFactory.getInstance(conf);
}
diff --git
a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/TestNettyWarmUp.java
b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/TestNettyWarmUp.java
new file mode 100644
index 00000000000..1b2543bc25c
--- /dev/null
+++
b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/TestNettyWarmUp.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hdds.scm;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link NettyWarmUp} and that {@link XceiverClientCreator} starts it.
+ */
+class TestNettyWarmUp {
+
+ @BeforeEach
+ void reset() {
+ NettyWarmUp.reset();
+ }
+
+ @AfterEach
+ void cleanup() {
+ NettyWarmUp.reset();
+ }
+
+ @Test
+ void startsAtMostOncePerJvm() throws InterruptedException {
+ Thread thread = NettyWarmUp.start(false);
+ assertNotNull(thread);
+ assertTrue(thread.isDaemon());
+ thread.join(30_000);
+ assertFalse(thread.isAlive(), "The warm-up should finish");
+
+ assertNull(NettyWarmUp.start(true), "The warm-up should start only once
per JVM");
+ }
+
+ @Test
+ void warmsUpTls() throws InterruptedException {
+ Thread thread = NettyWarmUp.start(true);
+ assertNotNull(thread);
+ thread.join(30_000);
+ assertFalse(thread.isAlive(), "The TLS warm-up should finish, whether or
not netty-tcnative is available");
+ }
+
+ @Test
+ void creatorStartsWarmUpByDefault() {
+ try (XceiverClientCreator ignored = new XceiverClientCreator(new
OzoneConfiguration())) {
+ assertTrue(NettyWarmUp.isStarted());
+ }
+ }
+
+ @Test
+ void creatorSkipsWarmUpWhenDisabled() {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.setBoolean("ozone.client.netty.warmup.enabled", false);
+ try (XceiverClientCreator ignored = new XceiverClientCreator(conf)) {
+ assertFalse(NettyWarmUp.isStarted());
+ }
+ }
+}
diff --git
a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/TestOzoneClientConfig.java
b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/TestOzoneClientConfig.java
index 9fed189dc88..3ba468dee77 100644
---
a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/TestOzoneClientConfig.java
+++
b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/TestOzoneClientConfig.java
@@ -118,4 +118,13 @@ void testDatastreamPutBlockWithoutRaftConfigParsing() {
assertTrue(subject.isDatastreamPutBlockWithoutRaftEnabled());
}
+
+ @Test
+ void testNettyWarmUpEnabledByDefault() {
+ assertTrue(new
OzoneConfiguration().getObject(OzoneClientConfig.class).isNettyWarmUpEnabled());
+
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.setBoolean("ozone.client.netty.warmup.enabled", false);
+
assertFalse(conf.getObject(OzoneClientConfig.class).isNettyWarmUpEnabled());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]