mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: optimize thread pool config
This commit is contained in:
parent
d531bf3a22
commit
2db0f05feb
@ -1,5 +1,7 @@
|
|||||||
package tech.powerjob.server.core.instance;
|
package tech.powerjob.server.core.instance;
|
||||||
|
|
||||||
|
import org.springframework.core.task.AsyncTaskExecutor;
|
||||||
|
import org.springframework.core.task.TaskExecutor;
|
||||||
import tech.powerjob.common.enums.LogLevel;
|
import tech.powerjob.common.enums.LogLevel;
|
||||||
import tech.powerjob.common.OmsConstant;
|
import tech.powerjob.common.OmsConstant;
|
||||||
import tech.powerjob.common.enums.TimeExpressionType;
|
import tech.powerjob.common.enums.TimeExpressionType;
|
||||||
@ -68,7 +70,9 @@ public class InstanceLogService {
|
|||||||
* 本地维护了在线日志的任务实例ID
|
* 本地维护了在线日志的任务实例ID
|
||||||
*/
|
*/
|
||||||
private final Map<Long, Long> instanceId2LastReportTime = Maps.newConcurrentMap();
|
private final Map<Long, Long> instanceId2LastReportTime = Maps.newConcurrentMap();
|
||||||
private final ExecutorService workerPool;
|
|
||||||
|
@Resource(name = PJThreadPool.BACKGROUND_POOL)
|
||||||
|
private AsyncTaskExecutor powerJobBackgroundPool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分段锁
|
* 分段锁
|
||||||
@ -88,11 +92,6 @@ public class InstanceLogService {
|
|||||||
*/
|
*/
|
||||||
private static final long EXPIRE_INTERVAL_MS = 60000;
|
private static final long EXPIRE_INTERVAL_MS = 60000;
|
||||||
|
|
||||||
public InstanceLogService() {
|
|
||||||
int coreSize = Runtime.getRuntime().availableProcessors();
|
|
||||||
workerPool = new ThreadPoolExecutor(coreSize, coreSize, 1, TimeUnit.MINUTES, Queues.newLinkedBlockingQueue());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提交日志记录,持久化到本地数据库中
|
* 提交日志记录,持久化到本地数据库中
|
||||||
* @param workerAddress 上报机器地址
|
* @param workerAddress 上报机器地址
|
||||||
@ -192,7 +191,7 @@ public class InstanceLogService {
|
|||||||
* @return 异步结果
|
* @return 异步结果
|
||||||
*/
|
*/
|
||||||
private Future<File> prepareLogFile(long instanceId) {
|
private Future<File> prepareLogFile(long instanceId) {
|
||||||
return workerPool.submit(() -> {
|
return powerJobBackgroundPool.submit(() -> {
|
||||||
// 在线日志还在不断更新,需要使用本地数据库中的数据
|
// 在线日志还在不断更新,需要使用本地数据库中的数据
|
||||||
if (instanceId2LastReportTime.containsKey(instanceId)) {
|
if (instanceId2LastReportTime.containsKey(instanceId)) {
|
||||||
return genTemporaryLogFile(instanceId);
|
return genTemporaryLogFile(instanceId);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package tech.powerjob.server.config;
|
package tech.powerjob.server.config;
|
||||||
|
|
||||||
|
import org.springframework.core.task.AsyncTaskExecutor;
|
||||||
import org.springframework.core.task.TaskExecutor;
|
import org.springframework.core.task.TaskExecutor;
|
||||||
import tech.powerjob.server.common.RejectedExecutionHandlerFactory;
|
import tech.powerjob.server.common.RejectedExecutionHandlerFactory;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -25,7 +26,7 @@ import java.util.concurrent.*;
|
|||||||
public class ThreadPoolConfig {
|
public class ThreadPoolConfig {
|
||||||
|
|
||||||
@Bean(PJThreadPool.TIMING_POOL)
|
@Bean(PJThreadPool.TIMING_POOL)
|
||||||
public Executor getTimingPool() {
|
public TaskExecutor getTimingPool() {
|
||||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||||
executor.setCorePoolSize(Runtime.getRuntime().availableProcessors());
|
executor.setCorePoolSize(Runtime.getRuntime().availableProcessors());
|
||||||
executor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() * 4);
|
executor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() * 4);
|
||||||
@ -38,7 +39,7 @@ public class ThreadPoolConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean(PJThreadPool.BACKGROUND_POOL)
|
@Bean(PJThreadPool.BACKGROUND_POOL)
|
||||||
public Executor initBackgroundPool() {
|
public AsyncTaskExecutor initBackgroundPool() {
|
||||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||||
executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 8);
|
executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 8);
|
||||||
executor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() * 16);
|
executor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() * 16);
|
||||||
@ -50,7 +51,7 @@ public class ThreadPoolConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean(PJThreadPool.LOCAL_DB_POOL)
|
@Bean(PJThreadPool.LOCAL_DB_POOL)
|
||||||
public Executor initOmsLocalDbPool() {
|
public TaskExecutor initOmsLocalDbPool() {
|
||||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||||
executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() / 2);
|
executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() / 2);
|
||||||
executor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() / 2);
|
executor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() / 2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user