This is an automated email from the ASF dual-hosted git repository.
zhongqiangchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-celeborn.git
The following commit(s) were added to refs/heads/main by this push:
new 5769c3fdc [CELEBORN-552] Add HeartBeat between the client and worker
to keep alive (#1457)
5769c3fdc is described below
commit 5769c3fdc7eebd7701c40be364c83374ff7ea03b
Author: zhongqiangchen <[email protected]>
AuthorDate: Wed May 10 19:35:51 2023 +0800
[CELEBORN-552] Add HeartBeat between the client and worker to keep alive
(#1457)
---
.../plugin/flink/network/MessageDecoderExt.java | 3 +
.../flink/readclient/FlinkShuffleClientImpl.java | 6 +
.../apache/celeborn/client/ShuffleClientImpl.java | 5 +
.../celeborn/common/network/TransportContext.java | 30 +++-
.../common/network/protocol/Heartbeat.java | 40 ++++++
.../celeborn/common/network/protocol/Message.java | 8 +-
.../network/server/TransportChannelHandler.java | 41 +++++-
.../common/network/util/TransportConf.java | 4 +
.../common/network/util/TransportFrameDecoder.java | 7 +-
.../org/apache/celeborn/common/CelebornConf.scala | 28 +++-
.../network/TransportClientFactorySuiteJ.java | 2 +-
docs/configuration/client.md | 1 +
docs/configuration/worker.md | 3 +
.../celeborn/tests/flink/HeartbeatTest.scala | 52 +++++++
.../celeborn/tests/spark/HeartbeatTest.scala | 59 ++++++++
.../deploy/worker/memory/MemoryManager.java | 6 +
.../celeborn/service/deploy/worker/Worker.scala | 23 +++-
.../network/RequestTimeoutIntegrationSuiteJ.java | 6 +-
.../celeborn/service/deploy/HeartbeatFeature.scala | 152 +++++++++++++++++++++
.../service/deploy/MiniClusterFeature.scala | 5 +-
20 files changed, 459 insertions(+), 22 deletions(-)
diff --git
a/client-flink/common/src/main/java/org/apache/celeborn/plugin/flink/network/MessageDecoderExt.java
b/client-flink/common/src/main/java/org/apache/celeborn/plugin/flink/network/MessageDecoderExt.java
index 58e62f1cb..cecc0b807 100644
---
a/client-flink/common/src/main/java/org/apache/celeborn/plugin/flink/network/MessageDecoderExt.java
+++
b/client-flink/common/src/main/java/org/apache/celeborn/plugin/flink/network/MessageDecoderExt.java
@@ -86,6 +86,9 @@ public class MessageDecoderExt {
in.readBytes(errorBytes);
return new TransportableError(streamId, errorBytes);
+ case HEARTBEAT:
+ return new Heartbeat();
+
default:
throw new IllegalArgumentException("Unexpected message type: " + type);
}
diff --git
a/client-flink/common/src/main/java/org/apache/celeborn/plugin/flink/readclient/FlinkShuffleClientImpl.java
b/client-flink/common/src/main/java/org/apache/celeborn/plugin/flink/readclient/FlinkShuffleClientImpl.java
index 2fc155eef..e1b62eb1c 100644
---
a/client-flink/common/src/main/java/org/apache/celeborn/plugin/flink/readclient/FlinkShuffleClientImpl.java
+++
b/client-flink/common/src/main/java/org/apache/celeborn/plugin/flink/readclient/FlinkShuffleClientImpl.java
@@ -26,6 +26,7 @@ import java.util.concurrent.TimeoutException;
import scala.reflect.ClassTag$;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.util.concurrent.Uninterruptibles;
import io.netty.buffer.ByteBuf;
import org.slf4j.Logger;
@@ -560,4 +561,9 @@ public class FlinkShuffleClientImpl extends
ShuffleClientImpl {
public void setDataClientFactory(TransportClientFactory dataClientFactory) {
this.dataClientFactory = dataClientFactory;
}
+
+ @VisibleForTesting
+ public TransportClientFactory getDataClientFactory() {
+ return flinkTransportClientFactory;
+ }
}
diff --git
a/client/src/main/java/org/apache/celeborn/client/ShuffleClientImpl.java
b/client/src/main/java/org/apache/celeborn/client/ShuffleClientImpl.java
index 745f04a8b..8862a0d3f 100644
--- a/client/src/main/java/org/apache/celeborn/client/ShuffleClientImpl.java
+++ b/client/src/main/java/org/apache/celeborn/client/ShuffleClientImpl.java
@@ -1558,4 +1558,9 @@ public class ShuffleClientImpl extends ShuffleClient {
|| (message.equals("Connection reset by peer"))
|| (message.startsWith("Failed to send RPC "));
}
+
+ @VisibleForTesting
+ public TransportClientFactory getDataClientFactory() {
+ return dataClientFactory;
+ }
}
diff --git
a/common/src/main/java/org/apache/celeborn/common/network/TransportContext.java
b/common/src/main/java/org/apache/celeborn/common/network/TransportContext.java
index 1fab94ac9..a6cf41e05 100644
---
a/common/src/main/java/org/apache/celeborn/common/network/TransportContext.java
+++
b/common/src/main/java/org/apache/celeborn/common/network/TransportContext.java
@@ -54,6 +54,7 @@ public class TransportContext {
private final BaseMessageHandler msgHandler;
private final ChannelDuplexHandler channelsLimiter;
private final boolean closeIdleConnections;
+ private final boolean enableHeartbeat;
private static final MessageEncoder ENCODER = MessageEncoder.INSTANCE;
@@ -61,20 +62,30 @@ public class TransportContext {
TransportConf conf,
BaseMessageHandler msgHandler,
boolean closeIdleConnections,
- ChannelDuplexHandler channelsLimiter) {
+ ChannelDuplexHandler channelsLimiter,
+ boolean enableHeartbeat) {
this.conf = conf;
this.msgHandler = msgHandler;
this.closeIdleConnections = closeIdleConnections;
this.channelsLimiter = channelsLimiter;
+ this.enableHeartbeat = enableHeartbeat;
+ }
+
+ public TransportContext(
+ TransportConf conf,
+ BaseMessageHandler msgHandler,
+ boolean closeIdleConnections,
+ boolean enableHeartbeat) {
+ this(conf, msgHandler, closeIdleConnections, null, enableHeartbeat);
}
public TransportContext(
TransportConf conf, BaseMessageHandler msgHandler, boolean
closeIdleConnections) {
- this(conf, msgHandler, closeIdleConnections, null);
+ this(conf, msgHandler, closeIdleConnections, null, false);
}
public TransportContext(TransportConf conf, BaseMessageHandler msgHandler) {
- this(conf, msgHandler, false);
+ this(conf, msgHandler, false, false);
}
public TransportClientFactory createClientFactory() {
@@ -111,7 +122,10 @@ public class TransportContext {
.addLast("encoder", ENCODER)
.addLast(FrameDecoder.HANDLER_NAME, decoder)
.addLast(
- "idleStateHandler", new IdleStateHandler(0, 0,
conf.connectionTimeoutMs() / 1000))
+ "idleStateHandler",
+ enableHeartbeat
+ ? new IdleStateHandler(conf.connectionTimeoutMs() / 1000, 0,
0)
+ : new IdleStateHandler(0, 0, conf.connectionTimeoutMs() /
1000))
.addLast("handler", channelHandler);
return channelHandler;
} catch (RuntimeException e) {
@@ -127,7 +141,13 @@ public class TransportContext {
TransportRequestHandler requestHandler =
new TransportRequestHandler(channel, client, msgHandler);
return new TransportChannelHandler(
- client, responseHandler, requestHandler, conf.connectionTimeoutMs(),
closeIdleConnections);
+ client,
+ responseHandler,
+ requestHandler,
+ conf.connectionTimeoutMs(),
+ closeIdleConnections,
+ enableHeartbeat,
+ conf.clientHearbeatInterval());
}
public TransportConf getConf() {
diff --git
a/common/src/main/java/org/apache/celeborn/common/network/protocol/Heartbeat.java
b/common/src/main/java/org/apache/celeborn/common/network/protocol/Heartbeat.java
new file mode 100644
index 000000000..8554f3a91
--- /dev/null
+++
b/common/src/main/java/org/apache/celeborn/common/network/protocol/Heartbeat.java
@@ -0,0 +1,40 @@
+/*
+ * 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.celeborn.common.network.protocol;
+
+import io.netty.buffer.ByteBuf;
+
+public class Heartbeat extends RequestMessage {
+
+ @Override
+ public int encodedLength() {
+ return 0;
+ }
+
+ @Override
+ public void encode(ByteBuf buf) {}
+
+ public static Message decode(ByteBuf buffer) {
+ return new Heartbeat();
+ }
+
+ @Override
+ public Type type() {
+ return Type.HEARTBEAT;
+ }
+}
diff --git
a/common/src/main/java/org/apache/celeborn/common/network/protocol/Message.java
b/common/src/main/java/org/apache/celeborn/common/network/protocol/Message.java
index 1450ab931..989c40e50 100644
---
a/common/src/main/java/org/apache/celeborn/common/network/protocol/Message.java
+++
b/common/src/main/java/org/apache/celeborn/common/network/protocol/Message.java
@@ -90,7 +90,8 @@ public abstract class Message implements Encodable {
OPEN_STREAM_WITH_CREDIT(18),
BACKLOG_ANNOUNCEMENT(19),
TRANSPORTABLE_ERROR(20),
- BUFFER_STREAM_END(21);
+ BUFFER_STREAM_END(21),
+ HEARTBEAT(22);
private final byte id;
Type(int id) {
@@ -160,6 +161,8 @@ public abstract class Message implements Encodable {
return TRANSPORTABLE_ERROR;
case 21:
return BUFFER_STREAM_END;
+ case 22:
+ return HEARTBEAT;
case -1:
throw new IllegalArgumentException("User type messages cannot be
decoded.");
default:
@@ -230,6 +233,9 @@ public abstract class Message implements Encodable {
case BUFFER_STREAM_END:
return BufferStreamEnd.decode(in);
+ case HEARTBEAT:
+ return new Heartbeat();
+
default:
throw new IllegalArgumentException("Unexpected message type: " +
msgType);
}
diff --git
a/common/src/main/java/org/apache/celeborn/common/network/server/TransportChannelHandler.java
b/common/src/main/java/org/apache/celeborn/common/network/server/TransportChannelHandler.java
index 12f1bcb84..b7c119afd 100644
---
a/common/src/main/java/org/apache/celeborn/common/network/server/TransportChannelHandler.java
+++
b/common/src/main/java/org/apache/celeborn/common/network/server/TransportChannelHandler.java
@@ -17,6 +17,9 @@
package org.apache.celeborn.common.network.server;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleState;
@@ -26,6 +29,7 @@ import org.slf4j.LoggerFactory;
import org.apache.celeborn.common.network.client.TransportClient;
import org.apache.celeborn.common.network.client.TransportResponseHandler;
+import org.apache.celeborn.common.network.protocol.Heartbeat;
import org.apache.celeborn.common.network.protocol.RequestMessage;
import org.apache.celeborn.common.network.protocol.ResponseMessage;
import org.apache.celeborn.common.network.util.NettyUtils;
@@ -54,17 +58,25 @@ public class TransportChannelHandler extends
ChannelInboundHandlerAdapter {
private final TransportRequestHandler requestHandler;
private final long requestTimeoutNs;
private final boolean closeIdleConnections;
+ private final long heartbeatInterval;
+ private ScheduledFuture<?> heartbeatFuture;
+ private boolean heartbeatFutureCanceled = false;
+ private boolean enableHeartbeat;
public TransportChannelHandler(
TransportClient client,
TransportResponseHandler responseHandler,
TransportRequestHandler requestHandler,
long requestTimeoutMs,
- boolean closeIdleConnections) {
+ boolean closeIdleConnections,
+ boolean enableHeartbeat,
+ long heartbeatInterval) {
this.client = client;
this.responseHandler = responseHandler;
this.requestHandler = requestHandler;
this.requestTimeoutNs = requestTimeoutMs * 1000L * 1000;
+ this.enableHeartbeat = enableHeartbeat;
+ this.heartbeatInterval = heartbeatInterval;
this.closeIdleConnections = closeIdleConnections;
}
@@ -76,13 +88,34 @@ public class TransportChannelHandler extends
ChannelInboundHandlerAdapter {
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
throws Exception {
logger.warn(
"Exception in connection from " +
NettyUtils.getRemoteAddress(ctx.channel()), cause);
+ closeHeartbeat();
requestHandler.exceptionCaught(cause);
responseHandler.exceptionCaught(cause);
ctx.close();
}
+ private void closeHeartbeat() {
+ if (heartbeatFuture != null && !heartbeatFutureCanceled) {
+ heartbeatFuture.cancel(true);
+ heartbeatFutureCanceled = true;
+ }
+ }
+
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
+ if (enableHeartbeat) {
+ heartbeatFuture =
+ ctx.executor()
+ .scheduleAtFixedRate(
+ () -> {
+ logger.debug("send heartbeat");
+ ctx.writeAndFlush(new Heartbeat());
+ },
+ 0,
+ heartbeatInterval,
+ TimeUnit.MILLISECONDS);
+ }
+
try {
requestHandler.channelActive();
} catch (RuntimeException e) {
@@ -98,6 +131,7 @@ public class TransportChannelHandler extends
ChannelInboundHandlerAdapter {
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
+ closeHeartbeat();
try {
requestHandler.channelInactive();
} catch (RuntimeException e) {
@@ -113,7 +147,7 @@ public class TransportChannelHandler extends
ChannelInboundHandlerAdapter {
@Override
public void channelRead(ChannelHandlerContext ctx, Object request) throws
Exception {
- if (request instanceof RequestMessage) {
+ if (request instanceof RequestMessage && !(request instanceof Heartbeat)) {
requestHandler.handle((RequestMessage) request);
} else if (request instanceof ResponseMessage) {
responseHandler.handle((ResponseMessage) request);
@@ -130,7 +164,8 @@ public class TransportChannelHandler extends
ChannelInboundHandlerAdapter {
synchronized (this) {
boolean isActuallyOverdue =
System.nanoTime() - responseHandler.getTimeOfLastRequestNs() >
requestTimeoutNs;
- if (e.state() == IdleState.ALL_IDLE && isActuallyOverdue) {
+ if (e.state() == (enableHeartbeat ? IdleState.READER_IDLE :
IdleState.ALL_IDLE)
+ && isActuallyOverdue) {
if (responseHandler.numOutstandingRequests() > 0) {
String address = NettyUtils.getRemoteAddress(ctx.channel());
logger.error(
diff --git
a/common/src/main/java/org/apache/celeborn/common/network/util/TransportConf.java
b/common/src/main/java/org/apache/celeborn/common/network/util/TransportConf.java
index ffdf23744..1e863a2b3 100644
---
a/common/src/main/java/org/apache/celeborn/common/network/util/TransportConf.java
+++
b/common/src/main/java/org/apache/celeborn/common/network/util/TransportConf.java
@@ -152,4 +152,8 @@ public class TransportConf {
public long pushDataTimeoutCheckIntervalMs() {
return celebornConf.pushTimeoutCheckInterval();
}
+
+ public long clientHearbeatInterval() {
+ return celebornConf.clientHeartbeatInterval();
+ }
}
diff --git
a/common/src/main/java/org/apache/celeborn/common/network/util/TransportFrameDecoder.java
b/common/src/main/java/org/apache/celeborn/common/network/util/TransportFrameDecoder.java
index feeed2e09..a0a49d369 100644
---
a/common/src/main/java/org/apache/celeborn/common/network/util/TransportFrameDecoder.java
+++
b/common/src/main/java/org/apache/celeborn/common/network/util/TransportFrameDecoder.java
@@ -99,7 +99,9 @@ public class TransportFrameDecoder extends
ChannelInboundHandlerAdapter implemen
bodySize = first.readInt();
nextFrameSize = msgSize + bodySize;
totalSize -= HEADER_SIZE;
- if (!first.isReadable()) {
+ // The msgsize and bodysize of some messages e.g. HEARTBEAT are both 0,
so buffers can't be
+ // released
+ if (!first.isReadable() && nextFrameSize != 0) {
buffers.removeFirst().release();
}
return nextFrameSize;
@@ -130,9 +132,8 @@ public class TransportFrameDecoder extends
ChannelInboundHandlerAdapter implemen
// Reset size for next frame.
nextFrameSize = UNKNOWN_FRAME_SIZE;
-
Preconditions.checkArgument(frameSize < MAX_FRAME_SIZE, "Too large frame:
%s", frameSize);
- Preconditions.checkArgument(frameSize > 0, "Frame length should be
positive: %s", frameSize);
+ Preconditions.checkArgument(frameSize >= 0, "Frame length should be >= 0:
%s", frameSize);
// If the first buffer holds the entire frame, return it.
int remaining = (int) frameSize;
diff --git
a/common/src/main/scala/org/apache/celeborn/common/CelebornConf.scala
b/common/src/main/scala/org/apache/celeborn/common/CelebornConf.scala
index 299dcaadb..975e5851b 100644
--- a/common/src/main/scala/org/apache/celeborn/common/CelebornConf.scala
+++ b/common/src/main/scala/org/apache/celeborn/common/CelebornConf.scala
@@ -515,6 +515,8 @@ class CelebornConf(loadDefaults: Boolean) extends Cloneable
with Logging with Se
get(PARTITION_SORTER_PER_PARTITION_RESERVED_MEMORY)
def partitionSorterThreads: Int =
get(PARTITION_SORTER_THREADS).getOrElse(Runtime.getRuntime.availableProcessors)
+ def workerPushHeartbeatEnabled: Boolean = get(WORKER_PUSH_HEARTBEAT_ENABLED)
+ def workerFetchHeartbeatEnabled: Boolean =
get(WORKER_FETCH_HEARTBEAT_ENABLED)
// //////////////////////////////////////////////////////
// Client //
@@ -541,7 +543,7 @@ class CelebornConf(loadDefaults: Boolean) extends Cloneable
with Logging with Se
def shufflePartitionType: PartitionType =
PartitionType.valueOf(get(SHUFFLE_PARTITION_TYPE))
def requestCommitFilesMaxRetries: Int = get(COMMIT_FILE_REQUEST_MAX_RETRY)
def shuffleClientPushBlacklistEnabled: Boolean =
get(SHUFFLE_CLIENT_PUSH_BLACKLIST_ENABLED)
-
+ def clientHeartbeatInterval: Long = get(CLIENT_HEARTBEAT_INTERVAL)
// //////////////////////////////////////////////////////
// Shuffle Compression //
// //////////////////////////////////////////////////////
@@ -3214,4 +3216,28 @@ object CelebornConf extends Logging {
labels => labels.map(_ =>
Try(Utils.parseMetricLabels(_))).forall(_.isSuccess),
"Allowed pattern is:
`<label1_key>:<label1_value>[,<label2_key>:<label2_value>]*`")
.createWithDefault(Seq.empty)
+
+ val WORKER_PUSH_HEARTBEAT_ENABLED: ConfigEntry[Boolean] =
+ buildConf("celeborn.worker.push.heartbeat.enabled")
+ .categories("worker")
+ .version("0.3.0")
+ .doc("enable the heartbeat from worker to client when pushing data")
+ .booleanConf
+ .createWithDefault(true)
+
+ val WORKER_FETCH_HEARTBEAT_ENABLED: ConfigEntry[Boolean] =
+ buildConf("celeborn.worker.fetch.heartbeat.enabled")
+ .categories("worker")
+ .version("0.3.0")
+ .doc("enable the heartbeat from worker to client when fetching data")
+ .booleanConf
+ .createWithDefault(true)
+
+ val CLIENT_HEARTBEAT_INTERVAL: ConfigEntry[Long] =
+ buildConf("celeborn.client.heartbeat.interval")
+ .categories("client", "worker")
+ .version("0.3.0")
+ .doc("the heartbeat interval between worker and client")
+ .timeConf(TimeUnit.MILLISECONDS)
+ .createWithDefaultString("60s")
}
diff --git
a/common/src/test/java/org/apache/celeborn/common/network/TransportClientFactorySuiteJ.java
b/common/src/test/java/org/apache/celeborn/common/network/TransportClientFactorySuiteJ.java
index 89db68998..5b8f54293 100644
---
a/common/src/test/java/org/apache/celeborn/common/network/TransportClientFactorySuiteJ.java
+++
b/common/src/test/java/org/apache/celeborn/common/network/TransportClientFactorySuiteJ.java
@@ -177,7 +177,7 @@ public class TransportClientFactorySuiteJ {
CelebornConf _conf = new CelebornConf();
_conf.set("celeborn.shuffle.io.connectionTimeout", "1s");
TransportConf conf = new TransportConf("shuffle", _conf);
- TransportContext context = new TransportContext(conf, new
BaseMessageHandler(), true);
+ TransportContext context = new TransportContext(conf, new
BaseMessageHandler(), true, false);
try (TransportClientFactory factory = context.createClientFactory()) {
TransportClient c1 = factory.createClient(getLocalHost(),
server1.getPort());
assertTrue(c1.isActive());
diff --git a/docs/configuration/client.md b/docs/configuration/client.md
index 24671d666..9dc9417de 100644
--- a/docs/configuration/client.md
+++ b/docs/configuration/client.md
@@ -23,6 +23,7 @@ license: |
| celeborn.application.heartbeatInterval | 10s | Interval for client to send
heartbeat message to master. | 0.2.0 |
| celeborn.client.blacklistSlave.enabled | true | When true, Celeborn will add
partition's peer worker into blacklist when push data to slave failed. | 0.3.0
|
| celeborn.client.closeIdleConnections | true | Whether client will close idle
connections. | 0.3.0 |
+| celeborn.client.heartbeat.interval | 60s | the heartbeat interval between
worker and client | 0.3.0 |
| celeborn.client.maxRetries | 15 | Max retry times for client to connect
master endpoint | 0.2.0 |
| celeborn.fetch.maxReqsInFlight | 3 | Amount of in-flight chunk fetch
request. | 0.2.0 |
| celeborn.fetch.maxRetriesForEachReplica | 3 | Max retry times of fetch chunk
on each replica | 0.2.0 |
diff --git a/docs/configuration/worker.md b/docs/configuration/worker.md
index 3bb60efd1..a86cacf3c 100644
--- a/docs/configuration/worker.md
+++ b/docs/configuration/worker.md
@@ -19,6 +19,7 @@ license: |
<!--begin-include-->
| Key | Default | Description | Since |
| --- | ------- | ----------- | ----- |
+| celeborn.client.heartbeat.interval | 60s | the heartbeat interval between
worker and client | 0.3.0 |
| celeborn.client.maxRetries | 15 | Max retry times for client to connect
master endpoint | 0.2.0 |
| celeborn.master.endpoints | <localhost>:9097 | Endpoints of master
nodes for celeborn client to connect, allowed pattern is:
`<host1>:<port1>[,<host2>:<port2>]*`, e.g. `clb1:9097,clb2:9098,clb3:9099`. If
the port is omitted, 9097 will be used. | 0.2.0 |
| celeborn.metrics.capacity | 4096 | The maximum number of metrics which a
source can use to generate output strings. | 0.2.0 |
@@ -51,6 +52,7 @@ license: |
| celeborn.worker.disk.checkFileClean.timeout | 1000ms | The wait time per
retry for a worker to check if the working directory is cleaned up before
registering with the master. | 0.2.0 |
| celeborn.worker.disk.reserve.size | 5G | Celeborn worker reserved space for
each disk. | 0.2.0 |
| celeborn.worker.diskTime.slidingWindow.size | 20 | The size of sliding
windows used to calculate statistics about flushed time and count. | 0.2.1 |
+| celeborn.worker.fetch.heartbeat.enabled | true | enable the heartbeat from
worker to client when fetching data | 0.3.0 |
| celeborn.worker.fetch.io.threads | <undefined> | Netty IO thread
number of worker to handle client fetch data. The default threads number is the
number of flush thread. | 0.2.0 |
| celeborn.worker.fetch.port | 0 | Server port for Worker to receive fetch
data request from ShuffleClient. | 0.2.0 |
| celeborn.worker.flusher.buffer.size | 256k | Size of buffer used by a single
flusher. | 0.2.0 |
@@ -85,6 +87,7 @@ license: |
| celeborn.worker.partitionSorter.reservedMemoryPerPartition | 1mb | Reserved
memory when sorting a shuffle file off-heap. | 0.2.0 |
| celeborn.worker.partitionSorter.sort.timeout | 220s | Timeout for a shuffle
file to sort. | 0.2.0 |
| celeborn.worker.partitionSorter.threads | <undefined> |
PartitionSorter's thread counts. | 0.3.0 |
+| celeborn.worker.push.heartbeat.enabled | true | enable the heartbeat from
worker to client when pushing data | 0.3.0 |
| celeborn.worker.push.io.threads | <undefined> | Netty IO thread number
of worker to handle client push data. The default threads number is the number
of flush thread. | 0.2.0 |
| celeborn.worker.push.port | 0 | Server port for Worker to receive push data
request from ShuffleClient. | 0.2.0 |
| celeborn.worker.readBuffer.allocationWait | 50ms | The time to wait when
buffer dispatcher can not allocate a buffer. | 0.3.0 |
diff --git
a/tests/flink-it/src/test/scala/org/apache/celeborn/tests/flink/HeartbeatTest.scala
b/tests/flink-it/src/test/scala/org/apache/celeborn/tests/flink/HeartbeatTest.scala
new file mode 100644
index 000000000..6e20effe3
--- /dev/null
+++
b/tests/flink-it/src/test/scala/org/apache/celeborn/tests/flink/HeartbeatTest.scala
@@ -0,0 +1,52 @@
+/*
+ * 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.celeborn.tests.flink
+
+import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
+import org.scalatest.funsuite.AnyFunSuite
+
+import org.apache.celeborn.common.identity.UserIdentifier
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.plugin.flink.readclient.FlinkShuffleClientImpl
+import org.apache.celeborn.service.deploy.{HeartbeatFeature,
MiniClusterFeature}
+import org.apache.celeborn.service.deploy.worker.memory.MemoryManager;
+
+class HeartbeatTest extends AnyFunSuite with Logging with MiniClusterFeature
with HeartbeatFeature
+ with BeforeAndAfterAll with BeforeAndAfterEach {
+
+ test("celeborn flink hearbeat test - client <- worker") {
+ val (_, clientConf) = getTestHeartbeatFromWorker2ClientConf()
+ val flinkShuffleClientImpl =
+ new FlinkShuffleClientImpl("", 0, clientConf, new UserIdentifier("1",
"1"))
+ testHeartbeatFromWorker2Client(flinkShuffleClientImpl.getDataClientFactory)
+ }
+
+ test("celeborn flink hearbeat test - client <- worker no heartbeat") {
+ val (_, clientConf) =
getTestHeartbeatFromWorker2ClientWithNoHeartbeatConf()
+ val flinkShuffleClientImpl =
+ new FlinkShuffleClientImpl("", 0, clientConf, new UserIdentifier("1",
"1"))
+
testHeartbeatFromWorker2ClientWithNoHeartbeat(flinkShuffleClientImpl.getDataClientFactory)
+ }
+
+ test("celeborn flink hearbeat test - client <- worker timeout") {
+ val (_, clientConf) =
getTestHeartbeatFromWorker2ClientWithCloseChannelConf()
+ val flinkShuffleClientImpl =
+ new FlinkShuffleClientImpl("", 0, clientConf, new UserIdentifier("1",
"1"))
+
testHeartbeatFromWorker2ClientWithCloseChannel(flinkShuffleClientImpl.getDataClientFactory)
+ }
+}
diff --git
a/tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/HeartbeatTest.scala
b/tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/HeartbeatTest.scala
new file mode 100644
index 000000000..23c278c42
--- /dev/null
+++
b/tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/HeartbeatTest.scala
@@ -0,0 +1,59 @@
+/*
+ * 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.celeborn.tests.spark
+
+import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
+import org.scalatest.funsuite.AnyFunSuite
+
+import org.apache.celeborn.client.{ShuffleClient, ShuffleClientImpl}
+import org.apache.celeborn.common.identity.UserIdentifier
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.service.deploy.{HeartbeatFeature,
MiniClusterFeature};
+
+class HeartbeatTest extends AnyFunSuite with Logging with MiniClusterFeature
with HeartbeatFeature
+ with BeforeAndAfterAll with BeforeAndAfterEach {
+
+ override def beforeEach(): Unit = {
+ ShuffleClient.reset()
+ }
+
+ override def afterEach(): Unit = {
+ System.gc()
+ }
+
+ test("celeborn spark heartbeat test - client <- worker") {
+ val (_, clientConf) = getTestHeartbeatFromWorker2ClientConf()
+ val shuffleClientImpl =
+ new ShuffleClientImpl(clientConf, new UserIdentifier("1", "1"))
+ testHeartbeatFromWorker2Client(shuffleClientImpl.getDataClientFactory)
+ }
+
+ test("celeborn spark heartbeat test - client <- worker on heartbeat") {
+ val (_, clientConf) =
getTestHeartbeatFromWorker2ClientWithNoHeartbeatConf()
+ val shuffleClientImpl =
+ new ShuffleClientImpl(clientConf, new UserIdentifier("1", "1"))
+
testHeartbeatFromWorker2ClientWithNoHeartbeat(shuffleClientImpl.getDataClientFactory)
+ }
+
+ test("celeborn spark heartbeat test - client <- worker timeout") {
+ val (_, clientConf) =
getTestHeartbeatFromWorker2ClientWithCloseChannelConf()
+ val shuffleClientImpl =
+ new ShuffleClientImpl(clientConf, new UserIdentifier("1", "1"))
+
testHeartbeatFromWorker2ClientWithCloseChannel(shuffleClientImpl.getDataClientFactory)
+ }
+}
diff --git
a/worker/src/main/java/org/apache/celeborn/service/deploy/worker/memory/MemoryManager.java
b/worker/src/main/java/org/apache/celeborn/service/deploy/worker/memory/MemoryManager.java
index 35718a8b5..b709cc568 100644
---
a/worker/src/main/java/org/apache/celeborn/service/deploy/worker/memory/MemoryManager.java
+++
b/worker/src/main/java/org/apache/celeborn/service/deploy/worker/memory/MemoryManager.java
@@ -29,6 +29,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAdder;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.util.internal.PlatformDependent;
@@ -428,6 +429,11 @@ public class MemoryManager {
readBufferDispatcher.close();
}
+ @VisibleForTesting
+ public static void reset() {
+ _INSTANCE = null;
+ }
+
public interface MemoryPressureListener {
void onPause(String moduleName);
diff --git
a/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/Worker.scala
b/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/Worker.scala
index c07953195..fceb56c3d 100644
---
a/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/Worker.scala
+++
b/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/Worker.scala
@@ -117,7 +117,12 @@ private[celeborn] class Worker(
Utils.fromCelebornConf(conf, TransportModuleConstants.PUSH_MODULE,
numThreads)
val pushServerLimiter = new
ChannelsLimiter(TransportModuleConstants.PUSH_MODULE, conf)
val transportContext: TransportContext =
- new TransportContext(transportConf, pushDataHandler,
closeIdleConnections, pushServerLimiter)
+ new TransportContext(
+ transportConf,
+ pushDataHandler,
+ closeIdleConnections,
+ pushServerLimiter,
+ conf.workerPushHeartbeatEnabled)
(
transportContext.createServer(conf.workerPushPort),
transportContext.createClientFactory())
@@ -132,7 +137,12 @@ private[celeborn] class Worker(
Utils.fromCelebornConf(conf, TransportModuleConstants.REPLICATE_MODULE,
numThreads)
val replicateLimiter = new
ChannelsLimiter(TransportModuleConstants.REPLICATE_MODULE, conf)
val transportContext: TransportContext =
- new TransportContext(transportConf, replicateHandler,
closeIdleConnections, replicateLimiter)
+ new TransportContext(
+ transportConf,
+ replicateHandler,
+ closeIdleConnections,
+ replicateLimiter,
+ false)
transportContext.createServer(conf.workerReplicatePort)
}
@@ -144,7 +154,11 @@ private[celeborn] class Worker(
Utils.fromCelebornConf(conf, TransportModuleConstants.FETCH_MODULE,
numThreads)
fetchHandler = new FetchHandler(transportConf)
val transportContext: TransportContext =
- new TransportContext(transportConf, fetchHandler, closeIdleConnections)
+ new TransportContext(
+ transportConf,
+ fetchHandler,
+ closeIdleConnections,
+ conf.workerFetchHeartbeatEnabled)
transportContext.createServer(conf.workerFetchPort)
}
@@ -542,6 +556,9 @@ private[celeborn] class Worker(
}
}),
WORKER_SHUTDOWN_PRIORITY)
+
+ @VisibleForTesting
+ def getPushFetchServerPort: (Int, Int) = (pushPort, fetchPort)
}
private[deploy] object Worker extends Logging {
diff --git
a/worker/src/test/java/org/apache/celeborn/service/deploy/worker/network/RequestTimeoutIntegrationSuiteJ.java
b/worker/src/test/java/org/apache/celeborn/service/deploy/worker/network/RequestTimeoutIntegrationSuiteJ.java
index 56f7e49e5..5adc6e549 100644
---
a/worker/src/test/java/org/apache/celeborn/service/deploy/worker/network/RequestTimeoutIntegrationSuiteJ.java
+++
b/worker/src/test/java/org/apache/celeborn/service/deploy/worker/network/RequestTimeoutIntegrationSuiteJ.java
@@ -107,7 +107,7 @@ public class RequestTimeoutIntegrationSuiteJ {
}
};
- TransportContext context = new TransportContext(conf, handler, true);
+ TransportContext context = new TransportContext(conf, handler, true,
false);
server = context.createServer();
clientFactory = context.createClientFactory();
TransportClient client = clientFactory.createClient(getLocalHost(),
server.getPort());
@@ -157,7 +157,7 @@ public class RequestTimeoutIntegrationSuiteJ {
}
};
- TransportContext context = new TransportContext(conf, handler, true);
+ TransportContext context = new TransportContext(conf, handler, true,
false);
server = context.createServer();
clientFactory = context.createClientFactory();
@@ -208,7 +208,7 @@ public class RequestTimeoutIntegrationSuiteJ {
}
};
- TransportContext context = new TransportContext(conf, handler, true);
+ TransportContext context = new TransportContext(conf, handler, true,
false);
server = context.createServer();
clientFactory = context.createClientFactory();
TransportClient client = clientFactory.createClient(getLocalHost(),
server.getPort());
diff --git
a/worker/src/test/scala/org/apache/celeborn/service/deploy/HeartbeatFeature.scala
b/worker/src/test/scala/org/apache/celeborn/service/deploy/HeartbeatFeature.scala
new file mode 100644
index 000000000..7120362fd
--- /dev/null
+++
b/worker/src/test/scala/org/apache/celeborn/service/deploy/HeartbeatFeature.scala
@@ -0,0 +1,152 @@
+/*
+ * 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.celeborn.service.deploy
+
+import org.junit.Assert
+
+import org.apache.celeborn.common.CelebornConf
+import org.apache.celeborn.common.network.client.{TransportClient,
TransportClientFactory}
+import org.apache.celeborn.common.util.Utils
+import org.apache.celeborn.service.deploy.master.Master
+import org.apache.celeborn.service.deploy.worker.Worker
+
+trait HeartbeatFeature extends MiniClusterFeature {
+
+ def testCore(
+ workerConf: Map[String, String],
+ dataClientFactory: TransportClientFactory,
+ assertFunc: (TransportClient, TransportClient) => Unit): Unit = {
+ logInfo("test initialized , setup rss mini cluster")
+ val masterConf = Map(
+ "celeborn.master.host" -> "localhost",
+ "celeborn.master.port" -> "9097")
+ var master: Master = null
+ var workers: collection.Set[Worker] = null
+ try {
+ val (_master, _workers) = setUpMiniCluster(masterConf, workerConf,
workerNum = 1)
+ master = _master
+ workers = _workers
+ workers.map(w => {
+ val (pushPort, fetchPort) = w.getPushFetchServerPort
+ logInfo(s"worker port1:$pushPort $fetchPort")
+ val clientPush =
+ dataClientFactory.createClient(Utils.localHostName, pushPort, 0)
+ val clientFetch =
+ dataClientFactory.createClient(
+ Utils.localHostName,
+ fetchPort,
+ 0)
+ logInfo(s"worker port2:$clientPush $clientFetch")
+ // At Beggining, the client is active
+ Assert.assertTrue(clientPush.isActive)
+ Assert.assertTrue(clientFetch.isActive)
+ assertFunc(clientPush, clientFetch)
+ })
+ } finally {
+ if (master != null && workers != null)
+ shutdownMiniCluster()
+ }
+ }
+
+ def getTestHeartbeatFromWorker2ClientConf(): (Map[String, String],
CelebornConf) = {
+ val workerConf = Map(
+ "celeborn.master.endpoints" -> "localhost:9097",
+ "celeborn.client.heartbeat.interval" -> "4s")
+ val clientConf = new CelebornConf()
+ clientConf.set("celeborn.data.io.connectionTimeout", "6s")
+ clientConf.set("celeborn.client.heartbeat.interval", "3s")
+ (workerConf, clientConf)
+ }
+ def testHeartbeatFromWorker2Client(dataClientFactory:
TransportClientFactory): Unit = {
+ val (workerConf, _) = getTestHeartbeatFromWorker2ClientConf()
+ // client <- worker:default client do not send heartbeat to worker, and
worker sends hearbeat to client
+ // client active: after connection timeout, the channel still be active
+ testCore(
+ workerConf,
+ dataClientFactory,
+ (pushClient, fetchClient) => {
+ Thread.sleep(7 * 1000)
+ Assert.assertTrue(fetchClient.isActive)
+ // because worker don't send heartbeat when pushdata, so client's
channel is false
+ Assert.assertTrue(pushClient.isActive)
+ })
+ }
+
+ def getTestHeartbeatFromWorker2ClientWithNoHeartbeatConf()
+ : (Map[String, String], CelebornConf) = {
+ val workerConf = Map(
+ "celeborn.master.endpoints" -> "localhost:9097",
+ "celeborn.client.heartbeat.interval" -> "4s",
+ "celeborn.worker.push.heartbeat.enabled" -> "false",
+ "celeborn.worker.fetch.heartbeat.enabled" -> "false")
+ val clientConf = new CelebornConf()
+ clientConf.set("celeborn.data.io.connectionTimeout", "6s")
+ (workerConf, clientConf)
+ }
+
+ def testHeartbeatFromWorker2ClientWithNoHeartbeat(dataClientFactory:
TransportClientFactory)
+ : Unit = {
+ val (workerConf, _) =
getTestHeartbeatFromWorker2ClientWithNoHeartbeatConf()
+
+ // client <- worker:default client do not send heartbeat to worker, and
worker sends hearbeat to client
+ // client active: after connection timeout, the channel still be active
+ testCore(
+ workerConf,
+ dataClientFactory,
+ (pushClient, fetchClient) => {
+ Thread.sleep(7 * 1000)
+ Assert.assertFalse(fetchClient.isActive)
+ // because worker don't send heartbeat when pushdata, so client's
channel is false
+ Assert.assertFalse(pushClient.isActive)
+ })
+ }
+
+ def getTestHeartbeatFromWorker2ClientWithCloseChannelConf()
+ : (Map[String, String], CelebornConf) = {
+ val workerConf = Map(
+ "celeborn.master.endpoints" -> "localhost:9097",
+ "celeborn.fetch.io.connectionTimeout" -> "9s",
+ "celeborn.push.io.connectionTimeout" -> "9s",
+ "celeborn.client.heartbeat.interval" -> "4s",
+ "celeborn.worker.closeIdleConnections" -> "true")
+ val clientConf = new CelebornConf()
+ clientConf.set("celeborn.data.io.connectionTimeout", "6s")
+ (workerConf, clientConf)
+ }
+
+ def testHeartbeatFromWorker2ClientWithCloseChannel(dataClientFactory:
TransportClientFactory)
+ : Unit = {
+ val (workerConf, _) = getTestHeartbeatFromWorker2ClientWithCloseChannelConf
+
+ // client <- worker:default client do not send heartbeat to worker, and
worker sends hearbeat to client
+ // client inactive: after client connection timeout, client still be
active(because worker send heartbeat to client);
+ // but after worker connectionTimeout, worker will close the channel, then
client will be inactive
+ testCore(
+ workerConf,
+ dataClientFactory,
+ (pushClient, fetchClient) => {
+ Thread.sleep(7 * 1000)
+ Assert.assertTrue(fetchClient.isActive)
+ Assert.assertTrue(pushClient.isActive)
+
+ Thread.sleep(4 * 1000)
+ Assert.assertFalse(fetchClient.isActive)
+ Assert.assertFalse(pushClient.isActive)
+ })
+ }
+}
diff --git
a/worker/src/test/scala/org/apache/celeborn/service/deploy/MiniClusterFeature.scala
b/worker/src/test/scala/org/apache/celeborn/service/deploy/MiniClusterFeature.scala
index ebb0998d4..40f5760b4 100644
---
a/worker/src/test/scala/org/apache/celeborn/service/deploy/MiniClusterFeature.scala
+++
b/worker/src/test/scala/org/apache/celeborn/service/deploy/MiniClusterFeature.scala
@@ -27,6 +27,7 @@ import org.apache.celeborn.common.internal.Logging
import org.apache.celeborn.common.util.Utils
import org.apache.celeborn.service.deploy.master.{Master, MasterArguments}
import org.apache.celeborn.service.deploy.worker.{Worker, WorkerArguments}
+import org.apache.celeborn.service.deploy.worker.memory.MemoryManager
trait MiniClusterFeature extends Logging {
val workerPrometheusPort = new AtomicInteger(12378)
@@ -104,7 +105,6 @@ trait MiniClusterFeature extends Logging {
masterThread.start()
masterInfo = (master, masterThread)
Thread.sleep(5000L)
-
for (_ <- 1 to workerNum) {
val worker = createWorker(workerConfs)
val workerThread = runnerWrap(worker.initialize())
@@ -137,7 +137,8 @@ trait MiniClusterFeature extends Logging {
case (_, thread) =>
thread.interrupt()
}
-
+ workerInfos.clear()
masterInfo._2.interrupt()
+ MemoryManager.reset()
}
}