Skip to content

Commit b36bfbe

Browse files
authored
[INLONG-11995][Agent] The Agent supports parallel creation of Sender connections to the DataProxy, improving creation efficiency (#11996)
1 parent 5deaf63 commit b36bfbe

File tree

1 file changed

+30
-15
lines changed
  • inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/sinks/dataproxy

1 file changed

+30
-15
lines changed

inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/sinks/dataproxy/Sender.java

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
import java.util.HashMap;
4848
import java.util.List;
4949
import java.util.Map;
50+
import java.util.concurrent.CountDownLatch;
51+
import java.util.concurrent.ExecutorService;
52+
import java.util.concurrent.Executors;
5053
import java.util.concurrent.LinkedBlockingQueue;
5154
import java.util.concurrent.SynchronousQueue;
5255
import java.util.concurrent.ThreadFactory;
@@ -214,23 +217,33 @@ private void createMessageSender() throws Exception {
214217
proxyClientConfig.setEnableDataCompress(isCompress);
215218
SHARED_FACTORY = new DefaultThreadFactory("agent-sender-manager-" + sourcePath,
216219
Thread.currentThread().isDaemon());
217-
boolean hasError = false;
218-
ProcessResult procResult = null;
220+
int ioThreadNum = 100;
221+
ExecutorService createExecutor = Executors.newFixedThreadPool(ioThreadNum);
222+
CountDownLatch latch = new CountDownLatch(maxSenderPerGroup);
219223
for (int i = 0; i < maxSenderPerGroup; i++) {
220-
InLongTcpMsgSender sender = new InLongTcpMsgSender(proxyClientConfig, SHARED_FACTORY);
221-
procResult = new ProcessResult();
222-
if (!sender.start(procResult)) {
223-
hasError = true;
224-
break;
225-
}
226-
senders.add(sender);
227-
}
228-
if (hasError) {
229-
senders.forEach(sender -> {
230-
sender.close();
224+
createExecutor.execute(new Runnable() {
225+
226+
@Override
227+
public void run() {
228+
try {
229+
InLongTcpMsgSender sender = new InLongTcpMsgSender(proxyClientConfig, SHARED_FACTORY);
230+
ProcessResult procResult = new ProcessResult();
231+
if (!sender.start(procResult)) {
232+
return;
233+
}
234+
synchronized (senders) {
235+
senders.add(sender);
236+
}
237+
} catch (Throwable t) {
238+
LOGGER.error(t.getMessage(), t);
239+
} finally {
240+
latch.countDown();
241+
}
242+
}
231243
});
232-
throw new ProxySdkException("Start sender failure, " + procResult);
233244
}
245+
latch.await();
246+
createExecutor.shutdown();
234247
}
235248

236249
public void sendBatch(SenderMessage message) {
@@ -361,6 +374,7 @@ private class AgentSenderCallback implements MsgSendCallback {
361374
private final int retry;
362375
private final SenderMessage message;
363376
private final int msgCnt;
377+
private final long sendTime = System.currentTimeMillis();
364378

365379
AgentSenderCallback(SenderMessage message, int retry) {
366380
this.message = message;
@@ -386,7 +400,8 @@ public void onMessageAck(ProcessResult result) {
386400
AgentStatusManager.sendDataLen.addAndGet(message.getTotalSize());
387401
} else {
388402
LOGGER.error("send groupId {}, streamId {}, taskId {}, instanceId {}, dataTime {} fail with times {}, "
389-
+ "error {}", groupId, streamId, taskId, instanceId, dataTime, retry, result);
403+
+ "error {},duration:{},msgCnt:{},msgSize:{}", groupId, streamId, taskId, instanceId, dataTime,
404+
retry, result, (System.currentTimeMillis() - sendTime), msgCnt, message.getTotalSize());
390405
getMetricItem(groupId, streamId).pluginSendFailCount.addAndGet(msgCnt);
391406
putInResendQueue(new AgentSenderCallback(message, retry));
392407
AuditUtils.add(AuditUtils.AUDIT_ID_AGENT_SEND_FAILED, groupId, streamId,

0 commit comments

Comments
 (0)