Skip to content

Commit bfeaf49

Browse files
author
‘niuerzhuang’
committed
feature: config pool.
1 parent 27bacc4 commit bfeaf49

File tree

4 files changed

+86
-13
lines changed

4 files changed

+86
-13
lines changed

dongtai-agent/src/main/java/io/dongtai/iast/agent/IastProperties.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public class IastProperties {
3434
put("uuid_path", PropertyConstant.PROPERTY_UUID_PATH);
3535
put("disabled_plugins", PropertyConstant.PROPERTY_DISABLED_PLUGINS);
3636
put("disabled_features", PropertyConstant.PROPERTY_DISABLED_FEATURES);
37+
put("pool_capacity", PropertyConstant.PROPERTY_POOL_CAPACITY);
38+
put("pool_size", PropertyConstant.PROPERTY_POOL_SIZE);
39+
put("pool_max_size", PropertyConstant.PROPERTY_POOL_MAX_SIZE);
40+
put("pool_keepalive", PropertyConstant.PROPERTY_POOL_KEEPALIVE);
3741
}};
3842

3943
private static IastProperties instance;

dongtai-common/src/main/java/io/dongtai/iast/common/constants/PropertyConstant.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@ public class PropertyConstant {
3333
public static final String PROPERTY_DISABLED_PLUGINS = "dongtai.disabled.plugins";
3434
public static final String PROPERTY_DISABLED_FEATURES = "dongtai.disabled.features";
3535
public static final String PROPERTY_TAINT_LENGTH = "dongtai.taint.length";
36+
public static final String PROPERTY_POOL_CAPACITY = "dongtai.pool.capacity";
37+
public static final String PROPERTY_POOL_SIZE = "dongtai.pool.size";
38+
public static final String PROPERTY_POOL_MAX_SIZE = "dongtai.pool.max.size";
39+
public static final String PROPERTY_POOL_KEEPALIVE = "dongtai.pool.keepalive";
3640
}

dongtai-core/src/main/java/io/dongtai/iast/core/service/ThreadPools.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.dongtai.iast.common.constants.AgentConstant;
44
import io.dongtai.iast.core.replay.HttpRequestReplay;
5+
import io.dongtai.iast.core.utils.PropertyUtils;
56

67
import java.util.concurrent.*;
78

@@ -10,39 +11,37 @@
1011
*/
1112
public class ThreadPools {
1213

13-
private static final ExecutorService METHOD_REPORT_THREAD = new ThreadPoolExecutor(0, 5, 10L, TimeUnit.SECONDS,
14-
new LinkedBlockingQueue<Runnable>(5120), new ThreadFactory() {
14+
private static final PropertyUtils propertyUtils = PropertyUtils.getInstance();
15+
private static final Integer poolSize = propertyUtils.getPoolSize();
16+
private static final Integer poolMaxSize = propertyUtils.getPoolMaxSize();
17+
private static final Integer poolKeepAlive = propertyUtils.getPoolKeepalive();
18+
private static final Integer poolCapacity = propertyUtils.getPoolCapacity();
19+
20+
private static final ExecutorService METHOD_REPORT_THREAD = new ThreadPoolExecutor(poolSize, poolMaxSize, poolKeepAlive, TimeUnit.SECONDS,
21+
new LinkedBlockingQueue<>(poolCapacity), new ThreadFactory() {
1522
@Override
1623
public Thread newThread(Runnable r) {
1724
return new Thread(r, AgentConstant.THREAD_NAME_PREFIX_CORE + "VulReport-" + r.hashCode());
1825
}
1926
});
2027

2128
private static final ExecutorService COMMON_REPORT_THREAD = new ThreadPoolExecutor(0, 5, 10L, TimeUnit.SECONDS,
22-
new LinkedBlockingQueue<Runnable>(10000), new ThreadFactory() {
29+
new LinkedBlockingQueue<>(1024), new ThreadFactory() {
2330
@Override
2431
public Thread newThread(Runnable r) {
2532
return new Thread(r, AgentConstant.THREAD_NAME_PREFIX_CORE + "Report-" + r.hashCode());
2633
}
2734
});
2835

2936
private static final ExecutorService REPLAY_REQUEST_THREAD = new ThreadPoolExecutor(0, 1, 10L, TimeUnit.SECONDS,
30-
new LinkedBlockingQueue<Runnable>(1024), new ThreadFactory() {
37+
new LinkedBlockingQueue<>(1024), new ThreadFactory() {
3138
@Override
3239
public Thread newThread(Runnable r) {
3340
return new Thread(r, AgentConstant.THREAD_NAME_PREFIX_CORE + "VulReplay-" + r.hashCode());
3441
}
3542

3643
});
3744

38-
private static final ExecutorService LIMIT_REPORT_THREAD = new ThreadPoolExecutor(0, 5, 10L, TimeUnit.SECONDS,
39-
new LinkedBlockingQueue<Runnable>(5120), new ThreadFactory() {
40-
@Override
41-
public Thread newThread(Runnable r) {
42-
return new Thread(r, AgentConstant.THREAD_NAME_PREFIX_CORE + "LimitReport-" + r.hashCode());
43-
}
44-
});
45-
4645

4746
public static void execute(Runnable r) {
4847
COMMON_REPORT_THREAD.execute(r);

dongtai-core/src/main/java/io/dongtai/iast/core/utils/PropertyUtils.java

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,17 @@ public class PropertyUtils {
3636
private final String propertiesFilePath;
3737

3838
public static final Integer DEFAULT_TAINT_TO_STRING_CHAR_LIMIT = 1024;
39+
public static final Integer DEFAULT_POOL_CAPACITY = 4096;
40+
public static final Integer DEFAULT_POOL_SIZE = 0;
41+
public static final Integer DEFAULT_POOL_MAX_SIZE = 10;
42+
public static final Integer DEFAULT_POOL_KEEPALIVE = 10;
3943

4044
// 污点转换为字符串的时候字符数长度限制
4145
private Integer taintToStringCharLimit = DEFAULT_TAINT_TO_STRING_CHAR_LIMIT;
46+
private Integer poolCapacity;
47+
private Integer poolSize;
48+
private Integer poolMaxSize;
49+
private Integer poolKeepalive;
4250

4351
public static PropertyUtils getInstance(String propertiesFilePath) throws DongTaiPropertyConfigException, DongTaiEnvConfigException {
4452
if (null == instance) {
@@ -78,7 +86,7 @@ private void init() throws DongTaiPropertyConfigException, DongTaiEnvConfigExcep
7886

7987
// 初始化一些参数
8088
this.initTaintToStringCharLimit();
81-
89+
this.initPool();
8290
}
8391

8492
public static String getTmpDir() {
@@ -244,6 +252,34 @@ public static Integer getTaintToStringCharLimit() {
244252
return instance.taintToStringCharLimit;
245253
}
246254

255+
public Integer getPoolCapacity() {
256+
if (instance == null) {
257+
return DEFAULT_POOL_CAPACITY;
258+
}
259+
return instance.poolCapacity;
260+
}
261+
262+
public Integer getPoolSize() {
263+
if (instance == null) {
264+
return DEFAULT_POOL_SIZE;
265+
}
266+
return instance.poolSize;
267+
}
268+
269+
public Integer getPoolMaxSize() {
270+
if (instance == null) {
271+
return DEFAULT_POOL_MAX_SIZE;
272+
}
273+
return instance.poolMaxSize;
274+
}
275+
276+
public Integer getPoolKeepalive() {
277+
if (instance == null) {
278+
return DEFAULT_POOL_KEEPALIVE;
279+
}
280+
return instance.poolKeepalive;
281+
}
282+
247283
/**
248284
* 初始化taintToStringCharLimit参数的值
249285
*
@@ -274,6 +310,36 @@ public void initTaintToStringCharLimit() throws DongTaiPropertyConfigException,
274310

275311
}
276312

313+
private void initPool() throws DongTaiPropertyConfigException, DongTaiEnvConfigException {
314+
this.poolCapacity = parseAndSetProperty(PropertyConstant.PROPERTY_POOL_CAPACITY, DEFAULT_POOL_CAPACITY);
315+
this.poolSize = parseAndSetProperty(PropertyConstant.PROPERTY_POOL_SIZE, DEFAULT_POOL_SIZE);
316+
this.poolMaxSize = parseAndSetProperty(PropertyConstant.PROPERTY_POOL_MAX_SIZE, DEFAULT_POOL_MAX_SIZE);
317+
this.poolKeepalive = parseAndSetProperty(PropertyConstant.PROPERTY_POOL_KEEPALIVE, DEFAULT_POOL_KEEPALIVE);
318+
}
319+
320+
private Integer parseAndSetProperty(String propertyKey,Integer defaultValue) throws DongTaiPropertyConfigException, DongTaiEnvConfigException {
321+
String propertyStr = cfg.getProperty(propertyKey);
322+
Integer value = defaultValue;
323+
if (!StringUtils.isBlank(propertyStr)) {
324+
value = Integer.parseInt(propertyStr.trim());
325+
if (value <= 0) {
326+
throw new DongTaiPropertyConfigException("The value of parameter " + propertyKey
327+
+ " value " + propertyStr + " in your configuration file " + this.propertiesFilePath + " is illegal, such as passing a number greater than 1");
328+
}
329+
}
330+
331+
// 2. 然后从环境变量中读取
332+
propertyStr = System.getProperty(propertyKey);
333+
if (!StringUtils.isBlank(propertyStr)) {
334+
value = Integer.parseInt(propertyStr.trim());
335+
if (value <= 0) {
336+
throw new DongTaiEnvConfigException("The value of this parameter " + propertyKey
337+
+ " value " + propertyStr + " in your environment variables is illegal, such as passing an number greater than 1");
338+
}
339+
}
340+
return value;
341+
}
342+
277343
/**
278344
* Property文件配置错误
279345
*/

0 commit comments

Comments
 (0)