From 543b2d44613249c3a75785138c2dd8f0cec9d944 Mon Sep 17 00:00:00 2001 From: wusheng Date: Wed, 19 Jul 2017 22:54:57 +0800 Subject: [PATCH] Support empty operation name, and add buffer size of dictionary for avoiding out of memory. --- .../java/org/skywalking/apm/agent/core/conf/Config.java | 9 +++++++++ .../apm/agent/core/dictionary/ApplicationDictionary.java | 6 +++++- .../agent/core/dictionary/OperationNameDictionary.java | 9 ++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/Config.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/Config.java index 9fa5cbb78..affced6f7 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/Config.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/Config.java @@ -73,6 +73,15 @@ public class Config { public static int BUFFER_SIZE = 300; } + public static class Dictionary { + /** + * The buffer size of application codes and peer + */ + public static int APPLICATION_CODE_BUFFER_SIZE = 10 * 10000; + + public static int OPERATION_NAME_BUFFER_SIZE = 1000 * 10000; + } + public static class Logging { /** * Log file name. diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/ApplicationDictionary.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/ApplicationDictionary.java index 295f4476d..016a607dd 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/ApplicationDictionary.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/ApplicationDictionary.java @@ -9,6 +9,8 @@ import org.skywalking.apm.network.proto.ApplicationMapping; import org.skywalking.apm.network.proto.ApplicationRegisterServiceGrpc; import org.skywalking.apm.network.proto.KeyWithIntegerValue; +import static org.skywalking.apm.agent.core.conf.Config.Dictionary.APPLICATION_CODE_BUFFER_SIZE; + /** * Map of application id to application code, which is from the collector side. * @@ -24,7 +26,9 @@ public enum ApplicationDictionary { if (applicationId != null) { return new Found(applicationId); } else { - unRegisterApplications.add(applicationCode); + if (applicationDictionary.size() + unRegisterApplications.size() < APPLICATION_CODE_BUFFER_SIZE) { + unRegisterApplications.add(applicationCode); + } return new NotFound(); } } diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/OperationNameDictionary.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/OperationNameDictionary.java index 9f575b50a..2abd18cb5 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/OperationNameDictionary.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/OperationNameDictionary.java @@ -10,6 +10,8 @@ import org.skywalking.apm.network.proto.ServiceNameElement; import org.skywalking.apm.network.proto.ServiceNameMappingCollection; import org.skywalking.apm.network.proto.ServiceNameMappingElement; +import static org.skywalking.apm.agent.core.conf.Config.Dictionary.OPERATION_NAME_BUFFER_SIZE; + /** * @author wusheng */ @@ -19,12 +21,17 @@ public enum OperationNameDictionary { private Set unRegisterOperationNames = new ConcurrentSet(); public PossibleFound find(int applicationId, String operationName) { + if (operationName == null || operationName.length() == 0) { + return new NotFound(); + } OperationNameKey key = new OperationNameKey(applicationId, operationName); Integer operationId = operationNameDictionary.get(key); if (operationId != null) { return new Found(applicationId); } else { - unRegisterOperationNames.add(key); + if (operationNameDictionary.size() + unRegisterOperationNames.size() < OPERATION_NAME_BUFFER_SIZE) { + unRegisterOperationNames.add(key); + } return new NotFound(); } }