From ac672e11433d0d48c5f57d8542baf3a69c2c2e58 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 4 Jun 2024 15:40:22 +0200 Subject: [PATCH] feature: modified executors --- .../service/telemetry/TelemetryService.java | 15 ++++++++------- .../logging/state/LoggingStateService.java | 3 +-- .../scheduler/SchedulerConfigService.java | 11 ++++++----- .../vendor/git/github/GitGitHubVendorService.java | 7 +++++-- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/api-server/src/main/java/com/repoachiever/service/telemetry/TelemetryService.java b/api-server/src/main/java/com/repoachiever/service/telemetry/TelemetryService.java index cede1ba..535ab95 100644 --- a/api-server/src/main/java/com/repoachiever/service/telemetry/TelemetryService.java +++ b/api-server/src/main/java/com/repoachiever/service/telemetry/TelemetryService.java @@ -38,44 +38,45 @@ public class TelemetryService { private final ConcurrentLinkedQueue additionalContentUploadQueue = new ConcurrentLinkedQueue<>(); - private final static ScheduledExecutorService executorService = Executors.newScheduledThreadPool(6); + private final static ScheduledExecutorService scheduledExecutorService = + Executors.newScheduledThreadPool(0, Thread.ofVirtual().factory()); /** * Starts telemetries listener, which handles incoming telemetries to be processed in a sequential way. */ @PostConstruct private void configure() { - executorService.scheduleWithFixedDelay(() -> { + scheduledExecutorService.scheduleWithFixedDelay(() -> { if (!apiServerHealthCheckQueue.isEmpty()) { apiServerHealthCheckQueue.poll().run(); } }, 0, properties.getDiagnosticsScrapeDelay(), TimeUnit.MILLISECONDS); - executorService.scheduleWithFixedDelay(() -> { + scheduledExecutorService.scheduleWithFixedDelay(() -> { if (!clusterHealthCheckQueue.isEmpty()) { clusterHealthCheckQueue.poll().run(); } }, 0, properties.getDiagnosticsScrapeDelay(), TimeUnit.MILLISECONDS); - executorService.scheduleWithFixedDelay(() -> { + scheduledExecutorService.scheduleWithFixedDelay(() -> { if (!clusterStateQueue.isEmpty()) { clusterStateQueue.poll().run(); } }, 0, properties.getDiagnosticsScrapeDelay(), TimeUnit.MILLISECONDS); - executorService.scheduleWithFixedDelay(() -> { + scheduledExecutorService.scheduleWithFixedDelay(() -> { if (!clusterDownloadQueue.isEmpty()) { clusterDownloadQueue.poll().run(); } }, 0, properties.getDiagnosticsScrapeDelay(), TimeUnit.MILLISECONDS); - executorService.scheduleWithFixedDelay(() -> { + scheduledExecutorService.scheduleWithFixedDelay(() -> { if (!rawContentUploadQueue.isEmpty()) { rawContentUploadQueue.poll().run(); } }, 0, properties.getDiagnosticsScrapeDelay(), TimeUnit.MILLISECONDS); - executorService.scheduleWithFixedDelay(() -> { + scheduledExecutorService.scheduleWithFixedDelay(() -> { if (!additionalContentUploadQueue.isEmpty()) { additionalContentUploadQueue.poll().run(); } diff --git a/cluster/src/main/java/com/repoachiever/service/integration/logging/state/LoggingStateService.java b/cluster/src/main/java/com/repoachiever/service/integration/logging/state/LoggingStateService.java index b69e9b6..71caf16 100644 --- a/cluster/src/main/java/com/repoachiever/service/integration/logging/state/LoggingStateService.java +++ b/cluster/src/main/java/com/repoachiever/service/integration/logging/state/LoggingStateService.java @@ -21,8 +21,7 @@ public class LoggingStateService { @Autowired private PropertiesEntity properties; - private final ScheduledExecutorService scheduledExecutorService = - Executors.newScheduledThreadPool(0, Thread.ofVirtual().factory()); + private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); /** * Performs application exit if the required state has been changed. diff --git a/cluster/src/main/java/com/repoachiever/service/integration/scheduler/SchedulerConfigService.java b/cluster/src/main/java/com/repoachiever/service/integration/scheduler/SchedulerConfigService.java index ae7f96a..42e95da 100644 --- a/cluster/src/main/java/com/repoachiever/service/integration/scheduler/SchedulerConfigService.java +++ b/cluster/src/main/java/com/repoachiever/service/integration/scheduler/SchedulerConfigService.java @@ -34,11 +34,6 @@ public class SchedulerConfigService { @Autowired private ApiServerCommunicationResource apiServerCommunicationResource; - private final ExecutorService starterExecutorService = Executors.newVirtualThreadPerTaskExecutor(); - - private final ScheduledExecutorService operationScheduledExecutorService = - Executors.newScheduledThreadPool(0, Thread.ofVirtual().factory()); - /** * Performs configuration of RepoAchiever Cluster workers. * @@ -46,6 +41,12 @@ public class SchedulerConfigService { */ @PostConstruct private void process() throws SchedulerPeriodRetrievalFailureException { + ExecutorService starterExecutorService = + Executors.newFixedThreadPool(configService.getConfig().getContent().getLocations().size()); + + ScheduledExecutorService operationScheduledExecutorService = + Executors.newScheduledThreadPool(configService.getConfig().getContent().getLocations().size()); + Long period; try { diff --git a/cluster/src/main/java/com/repoachiever/service/vendor/git/github/GitGitHubVendorService.java b/cluster/src/main/java/com/repoachiever/service/vendor/git/github/GitGitHubVendorService.java index 3c4a3db..04fea2f 100644 --- a/cluster/src/main/java/com/repoachiever/service/vendor/git/github/GitGitHubVendorService.java +++ b/cluster/src/main/java/com/repoachiever/service/vendor/git/github/GitGitHubVendorService.java @@ -57,8 +57,7 @@ public class GitGitHubVendorService { private String document; - private final ScheduledExecutorService scheduledExecutorService = - Executors.newScheduledThreadPool(0, Thread.ofVirtual().factory()); + private ScheduledExecutorService scheduledExecutorService; /** * Performs initial GraphQL client and HTTP client configuration. @@ -67,6 +66,10 @@ public class GitGitHubVendorService { */ @PostConstruct private void configure() throws GitHubGraphQlClientDocumentNotFoundException { + scheduledExecutorService = + Executors.newScheduledThreadPool( + configService.getConfig().getContent().getLocations().size() * 2); + if (configService.getConfig().getService().getProvider() == ConfigEntity.Service.Provider.GIT_GITHUB) { WebClient client = WebClient.builder() .baseUrl(properties.getGraphQlClientGitHubUrl())