|
@@ -116,6 +116,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
* @param runMode run mode
|
|
* @param runMode run mode
|
|
* @param timeout timeout
|
|
* @param timeout timeout
|
|
* @param startParams the global param values which pass to new process instance
|
|
* @param startParams the global param values which pass to new process instance
|
|
|
|
+ * @param expectedParallelismNumber the expected parallelism number when execute complement in parallel mode
|
|
* @return execute process instance code
|
|
* @return execute process instance code
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
@@ -125,7 +126,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
TaskDependType taskDependType, WarningType warningType, int warningGroupId,
|
|
TaskDependType taskDependType, WarningType warningType, int warningGroupId,
|
|
RunMode runMode,
|
|
RunMode runMode,
|
|
Priority processInstancePriority, String workerGroup, Integer timeout,
|
|
Priority processInstancePriority, String workerGroup, Integer timeout,
|
|
- Map<String, String> startParams) {
|
|
|
|
|
|
+ Map<String, String> startParams, Integer expectedParallelismNumber) {
|
|
Map<String, Object> result = new HashMap<>();
|
|
Map<String, Object> result = new HashMap<>();
|
|
// timeout is invalid
|
|
// timeout is invalid
|
|
if (timeout <= 0 || timeout > MAX_TASK_TIMEOUT) {
|
|
if (timeout <= 0 || timeout > MAX_TASK_TIMEOUT) {
|
|
@@ -162,7 +163,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
*/
|
|
*/
|
|
int create = this.createCommand(commandType, processDefinitionId,
|
|
int create = this.createCommand(commandType, processDefinitionId,
|
|
taskDependType, failureStrategy, startNodeList, cronTime, warningType, loginUser.getId(),
|
|
taskDependType, failureStrategy, startNodeList, cronTime, warningType, loginUser.getId(),
|
|
- warningGroupId, runMode, processInstancePriority, workerGroup, startParams);
|
|
|
|
|
|
+ warningGroupId, runMode, processInstancePriority, workerGroup, startParams, expectedParallelismNumber);
|
|
|
|
|
|
if (create > 0) {
|
|
if (create > 0) {
|
|
processDefinition.setWarningGroupId(warningGroupId);
|
|
processDefinition.setWarningGroupId(warningGroupId);
|
|
@@ -392,10 +393,10 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
/**
|
|
/**
|
|
* insert command, used in the implementation of the page, re run, recovery (pause / failure) execution
|
|
* insert command, used in the implementation of the page, re run, recovery (pause / failure) execution
|
|
*
|
|
*
|
|
- * @param loginUser login user
|
|
|
|
- * @param instanceId instance id
|
|
|
|
|
|
+ * @param loginUser login user
|
|
|
|
+ * @param instanceId instance id
|
|
* @param processDefinitionId process definition id
|
|
* @param processDefinitionId process definition id
|
|
- * @param commandType command type
|
|
|
|
|
|
+ * @param commandType command type
|
|
* @return insert result code
|
|
* @return insert result code
|
|
*/
|
|
*/
|
|
private Map<String, Object> insertCommand(User loginUser, Integer instanceId, Integer processDefinitionId, CommandType commandType, String startParams) {
|
|
private Map<String, Object> insertCommand(User loginUser, Integer instanceId, Integer processDefinitionId, CommandType commandType, String startParams) {
|
|
@@ -489,7 +490,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
String startNodeList, String schedule, WarningType warningType,
|
|
String startNodeList, String schedule, WarningType warningType,
|
|
int executorId, int warningGroupId,
|
|
int executorId, int warningGroupId,
|
|
RunMode runMode, Priority processInstancePriority, String workerGroup,
|
|
RunMode runMode, Priority processInstancePriority, String workerGroup,
|
|
- Map<String, String> startParams) {
|
|
|
|
|
|
+ Map<String, String> startParams, Integer expectedParallelismNumber) {
|
|
|
|
|
|
/**
|
|
/**
|
|
* instantiate command schedule instance
|
|
* instantiate command schedule instance
|
|
@@ -534,7 +535,6 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
end = DateUtils.getScheduleDate(interval[1]);
|
|
end = DateUtils.getScheduleDate(interval[1]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
// determine whether to complement
|
|
// determine whether to complement
|
|
if (commandType == CommandType.COMPLEMENT_DATA) {
|
|
if (commandType == CommandType.COMPLEMENT_DATA) {
|
|
runMode = (runMode == null) ? RunMode.RUN_MODE_SERIAL : runMode;
|
|
runMode = (runMode == null) ? RunMode.RUN_MODE_SERIAL : runMode;
|
|
@@ -546,21 +546,31 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
return processService.createCommand(command);
|
|
return processService.createCommand(command);
|
|
} else if (runMode == RunMode.RUN_MODE_PARALLEL) {
|
|
} else if (runMode == RunMode.RUN_MODE_PARALLEL) {
|
|
List<Schedule> schedules = processService.queryReleaseSchedulerListByProcessDefinitionId(processDefineId);
|
|
List<Schedule> schedules = processService.queryReleaseSchedulerListByProcessDefinitionId(processDefineId);
|
|
- List<Date> listDate = new LinkedList<>();
|
|
|
|
|
|
+ LinkedList<Date> listDate = new LinkedList<>();
|
|
if (!CollectionUtils.isEmpty(schedules)) {
|
|
if (!CollectionUtils.isEmpty(schedules)) {
|
|
for (Schedule item : schedules) {
|
|
for (Schedule item : schedules) {
|
|
listDate.addAll(CronUtils.getSelfFireDateList(start, end, item.getCrontab()));
|
|
listDate.addAll(CronUtils.getSelfFireDateList(start, end, item.getCrontab()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!CollectionUtils.isEmpty(listDate)) {
|
|
if (!CollectionUtils.isEmpty(listDate)) {
|
|
- // loop by schedule date
|
|
|
|
- for (Date date : listDate) {
|
|
|
|
- cmdParam.put(CMDPARAM_COMPLEMENT_DATA_START_DATE, DateUtils.dateToString(date));
|
|
|
|
- cmdParam.put(CMDPARAM_COMPLEMENT_DATA_END_DATE, DateUtils.dateToString(date));
|
|
|
|
|
|
+ int effectThreadsCount = expectedParallelismNumber == null ? listDate.size() : Math.min(listDate.size(), expectedParallelismNumber);
|
|
|
|
+ logger.info("In parallel mode, current expectedParallelismNumber:{}", effectThreadsCount);
|
|
|
|
+
|
|
|
|
+ int chunkSize = listDate.size() / effectThreadsCount;
|
|
|
|
+ listDate.addFirst(start);
|
|
|
|
+ listDate.addLast(end);
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < effectThreadsCount; i++) {
|
|
|
|
+ int rangeStart = i == 0 ? i : (i * chunkSize);
|
|
|
|
+ int rangeEnd = i == effectThreadsCount - 1 ? listDate.size() - 1
|
|
|
|
+ : rangeStart + chunkSize + 1;
|
|
|
|
+ cmdParam.put(CMDPARAM_COMPLEMENT_DATA_START_DATE, DateUtils.dateToString(listDate.get(rangeStart)));
|
|
|
|
+ cmdParam.put(CMDPARAM_COMPLEMENT_DATA_END_DATE, DateUtils.dateToString(listDate.get(rangeEnd)));
|
|
command.setCommandParam(JSONUtils.toJsonString(cmdParam));
|
|
command.setCommandParam(JSONUtils.toJsonString(cmdParam));
|
|
processService.createCommand(command);
|
|
processService.createCommand(command);
|
|
}
|
|
}
|
|
- return listDate.size();
|
|
|
|
|
|
+
|
|
|
|
+ return effectThreadsCount;
|
|
} else {
|
|
} else {
|
|
// loop by day
|
|
// loop by day
|
|
int runCunt = 0;
|
|
int runCunt = 0;
|