Skip to content

Commit 2059fd4

Browse files
authored
Improve CustomizeConfiguration by avoiding repeatedly resolve file config (#730)
1 parent fc86413 commit 2059fd4

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Release Notes.
1111
* Add witness class/method for resteasy-server plugin(v3/v4/v6)
1212
* Add async-profiler feature for performance analysis
1313
* Support db.instance tag,db.collection tag and AggregateOperation span for mongodb plugin(3.x/4.x)
14+
* Improve CustomizeConfiguration by avoiding repeatedly resolve file config
1415

1516
All issues and pull requests are [here](https://github.com/apache/skywalking/milestone/222?closed=1)
1617

apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/conf/CustomizeConfiguration.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Map;
2828
import java.util.Set;
2929
import java.util.concurrent.atomic.AtomicBoolean;
30+
import java.util.concurrent.locks.ReentrantLock;
3031
import javax.xml.parsers.DocumentBuilder;
3132
import javax.xml.parsers.DocumentBuilderFactory;
3233
import javax.xml.parsers.ParserConfigurationException;
@@ -67,6 +68,8 @@ public enum CustomizeConfiguration {
6768
private static final Map<String, ElementMatcher> CONTEXT_ENHANCE_CLASSES = new HashMap<>();
6869
private static final AtomicBoolean LOAD_FOR_CONFIGURATION = new AtomicBoolean(false);
6970

71+
private static volatile List<Map<String, Object>> RESOLVED_FILE_CONFIGURATIONS;
72+
private static final ReentrantLock RESOLVED_FILE_LOCK = new ReentrantLock();
7073
/**
7174
* The loadForEnhance method is resolver configuration file, and parse it
7275
*/
@@ -107,13 +110,26 @@ public synchronized void loadForConfiguration() {
107110
* @throws SAXException link {@link SAXException}
108111
*/
109112
private List<Map<String, Object>> resolver() throws ParserConfigurationException, IOException, SAXException {
110-
List<Map<String, Object>> customizeMethods = new ArrayList<Map<String, Object>>();
111-
File file = new File(CustomizePluginConfig.Plugin.Customize.ENHANCE_FILE);
112-
if (file.exists() && file.isFile()) {
113-
NodeList classNodeList = resolverFileClassDesc(file);
114-
resolverClassNodeList(classNodeList, customizeMethods);
113+
if (RESOLVED_FILE_CONFIGURATIONS != null) {
114+
return RESOLVED_FILE_CONFIGURATIONS;
115115
}
116-
return customizeMethods;
116+
117+
RESOLVED_FILE_LOCK.lock();
118+
try {
119+
if (RESOLVED_FILE_CONFIGURATIONS != null) {
120+
return RESOLVED_FILE_CONFIGURATIONS;
121+
}
122+
List<Map<String, Object>> customizeMethods = new ArrayList<Map<String, Object>>();
123+
File file = new File(CustomizePluginConfig.Plugin.Customize.ENHANCE_FILE);
124+
if (file.exists() && file.isFile()) {
125+
NodeList classNodeList = resolverFileClassDesc(file);
126+
resolverClassNodeList(classNodeList, customizeMethods);
127+
}
128+
RESOLVED_FILE_CONFIGURATIONS = customizeMethods;
129+
} finally {
130+
RESOLVED_FILE_LOCK.unlock();
131+
}
132+
return RESOLVED_FILE_CONFIGURATIONS;
117133
}
118134

119135
/**

0 commit comments

Comments
 (0)