Skip to content

Commit

Permalink
perf: file-gateway调度逻辑优化 TencentBlueKing#2977
Browse files Browse the repository at this point in the history
处理Review意见。
  • Loading branch information
jsonwan committed May 15, 2024
1 parent 1119b1b commit ce777ed
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class DispatchServiceImpl implements DispatchService {
private final FileWorkerDAO fileWorkerDAO;
private final FileWorkerService fileWorkerService;

private final AtomicLong dispatchCount = new AtomicLong(0);
private final AtomicLong roundRobinCount = new AtomicLong(0);

@Autowired
public DispatchServiceImpl(FileWorkerDAO fileWorkerDAO,
Expand Down Expand Up @@ -153,7 +153,6 @@ public FileWorkerDTO findBestFileWorker(FileSourceDTO fileSourceDTO, String requ
} catch (Exception e) {
log.warn("Fail to findBestFileWorker", e);
} finally {
dispatchCount.incrementAndGet();
long nanoSeconds = sample.stop(
meterRegistry.timer(
MetricsConstants.NAME_FILE_GATEWAY_DISPATCH_TIME,
Expand Down Expand Up @@ -189,7 +188,7 @@ private FileWorkerDTO findWorkerByAuto(FileSourceDTO fileSourceDTO) {
String workerSelectScope = fileSourceDTO.getWorkerSelectScope();
List<String> abilityTagList = abilityTagService.getAbilityTagList(fileSourceDTO);
List<FileWorkerDTO> fileWorkerDTOList;
if (abilityTagList == null || abilityTagList.size() == 0) {
if (abilityTagList == null || abilityTagList.isEmpty()) {
// 无能力标签要求,任选一个FileWorker
fileWorkerDTOList = getFileWorkerByScope(fileSourceDTO.getAppId(), workerSelectScope);
if (fileWorkerDTOList.isEmpty()) {
Expand Down Expand Up @@ -229,7 +228,7 @@ private FileWorkerDTO findWorkerByAuto(FileSourceDTO fileSourceDTO) {
}).collect(Collectors.toList());
if (!fileWorkerDTOList.isEmpty()) {
// 按策略调度:RoundRobin
int index = (int) (dispatchCount.get() % fileWorkerDTOList.size());
int index = (int) (roundRobinCount.getAndIncrement() % fileWorkerDTOList.size());
fileWorkerDTO = fileWorkerDTOList.get(index);
} else {
log.error("Cannot find available file worker, abilityTagList={}", abilityTagList);
Expand Down

0 comments on commit ce777ed

Please sign in to comment.