Skip to content

Commit

Permalink
Add configurable thread-multiplier for executors
Browse files Browse the repository at this point in the history
  • Loading branch information
yma96 committed Dec 3, 2024
1 parent 47f9868 commit dac7f70
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ public interface PreSeedConfig

@WithName( "not-used-days-cleanup" )
Optional<Long> notUsedDaysCleanup();

@WithName( "thread-multiplier" )
Optional<Integer> threadMultiplier();
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,20 @@
@ApplicationScoped
public class ArchiveController
{
private final Logger logger = LoggerFactory.getLogger( getClass() );

public final static String EVENT_GENERATE_ARCHIVE = "generate-archive";

public final static String CONTENT_DIR = "/content";

public final static String ARCHIVE_DIR = "/archive";

private final Logger logger = LoggerFactory.getLogger( getClass() );

private final String ARCHIVE_SUFFIX = ".zip";

private final String PART_SUFFIX = ".part";

private final String PART_ARCHIVE_SUFFIX = PART_SUFFIX + ARCHIVE_SUFFIX;

private static final int threads = 4 * Runtime.getRuntime().availableProcessors();

private final ExecutorService generateExecutor =
Executors.newFixedThreadPool( threads, ( final Runnable r ) -> {
final Thread t = new Thread( r );
t.setName( "Generate-" + t.getName() );
t.setDaemon( true );
return t;
} );

private static final Set<String> CHECKSUMS = Collections.unmodifiableSet( new HashSet<String>()
{
{
Expand All @@ -117,7 +106,9 @@ public class ArchiveController
@Inject
ObjectMapper objectMapper;

private ExecutorService executorService;
private ExecutorService downloadExecutor;

private ExecutorService generateExecutor;

private CloseableHttpClient client;

Expand All @@ -131,17 +122,22 @@ public class ArchiveController
public void init()
throws IOException
{
int threads = 4 * Runtime.getRuntime().availableProcessors();
executorService = Executors.newFixedThreadPool( threads, ( final Runnable r ) -> {
int threads = preSeedConfig.threadMultiplier().orElse( 4 ) * Runtime.getRuntime().availableProcessors();
downloadExecutor = Executors.newFixedThreadPool( threads, ( final Runnable r ) -> {
final Thread t = new Thread( r );
t.setName( "Download-" + t.getName() );
t.setDaemon( true );
return t;
} );
generateExecutor = Executors.newFixedThreadPool( threads, ( final Runnable r ) -> {
final Thread t = new Thread( r );
t.setName( "Generate-" + t.getName() );
t.setDaemon( true );
return t;
} );

final PoolingHttpClientConnectionManager ccm = new PoolingHttpClientConnectionManager();
ccm.setMaxTotal( 500 );

RequestConfig rc = RequestConfig.custom().build();
client = HttpClients.custom().setConnectionManager( ccm ).setDefaultRequestConfig( rc ).build();

Expand Down Expand Up @@ -325,7 +321,7 @@ private void downloadArtifacts( final Map<String, HistoricalEntryDTO> entryDTOs,
throws InterruptedException, ExecutionException, IOException
{
BasicCookieStore cookieStore = new BasicCookieStore();
ExecutorCompletionService<Boolean> executor = new ExecutorCompletionService<>( executorService );
ExecutorCompletionService<Boolean> executor = new ExecutorCompletionService<>( downloadExecutor );

String contentBuildDir = String.format( "%s/%s", contentDir, content.getBuildConfigId() );
File dir = new File( contentBuildDir );
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ quarkus:
pre-seed:
main-indy: https://indy-gateway-master-devel.psi.redhat.com
storage-dir: data
not-used-days-cleanup: 10
not-used-days-cleanup: 10
thread-multiplier: 4
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ public Optional<Long> notUsedDaysCleanup()
return Optional.of( 365l );
}

@Override
public Optional<Integer> threadMultiplier()
{
return Optional.of( 4 );
}

}

0 comments on commit dac7f70

Please sign in to comment.