Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NCL-6205] make pnc-parallelism-threshold configurable #282

Merged
merged 4 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ Build Finder version. The options are as follows:
-o, --output-directory=FILE
Set output directory.
Default: .
--pnc-num-threads=LONG Set Pnc thread number.
Default: 10
--pnc-partition-size=INT
Set Pnc partition size.
Default: 18
Expand Down Expand Up @@ -193,6 +195,7 @@ file, `config.json`, is as follows.
"koji-multicall-size" : 8,
"koji-num-threads" : 12,
"output-directory" : ".",
"pnc-num-threads" : 10,
"pnc-partition-size" : 18,
"use-builds-file" : false,
"use-checksums-file" : false
Expand Down Expand Up @@ -240,6 +243,9 @@ The `koji-num-threads` option sets the number of Koji threads.
The `koji-hub-url` and `koji-web-url` options must be set to valid URLs
for your particular network.

The `pnc-num-threads` signifies how many threads will be used to
communicate with PNC when finding builds.

The `pnc-partition-size` option sets the Pnc partition size.

The `pnc-url` option must be set to a valid URL for your particular
Expand Down
7 changes: 7 additions & 0 deletions cli/src/main/java/org/jboss/pnc/build/finder/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ public final class Main implements Callable<Void> {
@Option(names = { "-o", "--output-directory" }, paramLabel = "FILE", description = "Set output directory.")
private File outputDirectory = new File(ConfigDefaults.OUTPUT_DIR);

@Option(names = "--pnc-num-threads", paramLabel = "LONG", description = "Set Pnc thread number.")
private Long pncNumThreads = ConfigDefaults.PNC_NUM_THREADS;

@Option(names = "--pnc-partition-size", paramLabel = "INT", description = "Set Pnc partition size.")
private Integer pncPartitionSize = ConfigDefaults.PNC_PARTITION_SIZE;

Expand Down Expand Up @@ -389,6 +392,10 @@ private BuildConfig setupBuildConfig() throws IOException {
LOGGER.debug("Read Kerberos password");
}

if (commandSpec.commandLine().getParseResult().hasMatchedOption("--pnc-num-threads")) {
config.setPncNumThreads(pncNumThreads);
}

if (commandSpec.commandLine().getParseResult().hasMatchedOption("--pnc-partition-size")) {
config.setPncPartitionSize(pncPartitionSize);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void verifyParsing(@TempDir File folder) throws IOException {
String krbPassword = "test";
String krbPrincipal = "[email protected]";
String krbService = "testService";
Long pncNumThreads = 10L;

String[] args = {
"-o",
Expand Down Expand Up @@ -131,6 +132,8 @@ void verifyParsing(@TempDir File folder) throws IOException {
krbService,
"--krb-password",
krbPassword,
"--pnc-num-threads",
String.valueOf(pncNumThreads),
inputFile.toString() };

ParseResult parseResult = parseCommandLine(new Main(), args);
Expand Down Expand Up @@ -164,6 +167,7 @@ void verifyParsing(@TempDir File folder) throws IOException {
assertThat(parseResult.matchedOption("--krb-password").getValue(), is(krbPassword));
assertThat(parseResult.matchedOption("--krb-principal").getValue(), is(krbPrincipal));
assertThat(parseResult.matchedOption("--krb-service").getValue(), is(krbService));
assertThat(parseResult.matchedOption("--pnc-num-threads").getValue(), is(pncNumThreads));
}

@ExpectSystemExitWithStatus(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public class BuildConfig {
@JsonAlias("output-directory")
private String outputDirectory;

@JsonAlias("pnc-num-threads")
private Long pncNumThreads;

@JsonAlias("pnc-partition-size")
private Integer pncPartitionSize;

Expand Down Expand Up @@ -334,6 +337,18 @@ public Integer getPncPartitionSize() {
return pncPartitionSize;
}

public Long getPncNumThreads() {
if (pncNumThreads == null) {
pncNumThreads = ConfigDefaults.PNC_NUM_THREADS;
}

return pncNumThreads;
}

public void setPncNumThreads(Long pncNumThreads) {
this.pncNumThreads = pncNumThreads;
}

public void setPncPartitionSize(Integer pncPartitionSize) {
this.pncPartitionSize = pncPartitionSize;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public BuildFinder(
this.allKojiBuilds = new HashMap<>();

this.buildFinderUtils = new BuildFinderUtils(config, analyzer, session);
this.pncBuildFinder = new PncBuildFinder(pncclient, buildFinderUtils);
this.pncBuildFinder = new PncBuildFinder(pncclient, buildFinderUtils, config);

if (cacheManager != null) {
this.buildCache = cacheManager.getCache("builds");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public abstract class ConfigDefaults {
public static final Integer KOJI_NUM_THREADS = 12;
public static final URL KOJI_WEB_URL = null;
public static final String OUTPUT_DIR = ".";
public static final Long PNC_NUM_THREADS = 10L;
public static final Integer PNC_PARTITION_SIZE = 18;
public static final URL PNC_URL = null;
public static final Boolean USE_BUILDS_FILE = Boolean.FALSE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@
public class PncBuildFinder {
private static final Logger LOGGER = LoggerFactory.getLogger(PncBuildFinder.class);

// TODO: make the parallelismThreashold configurable
private static final long CONCURRENT_MAP_PARALLELISM_THRESHOLD = 10L;
private final long concurrentMapParallelismThreshold;

private final PncClient pncClient;

private final BuildFinderUtils buildFinderUtils;

private BuildFinderListener listener;

public PncBuildFinder(PncClient pncClient, BuildFinderUtils buildFinderUtils) {
public PncBuildFinder(PncClient pncClient, BuildFinderUtils buildFinderUtils, BuildConfig configuration) {
this.pncClient = pncClient;
this.buildFinderUtils = buildFinderUtils;
this.concurrentMapParallelismThreshold = configuration.getPncNumThreads();
}

public FindBuildsResult findBuildsPnc(Map<Checksum, Collection<String>> checksumTable)
Expand Down Expand Up @@ -105,7 +105,7 @@ private void populatePncBuildsMetadata(ConcurrentHashMap<String, PncBuild> pncBu
throws RemoteResourceException {
RemoteResourceExceptionWrapper exceptionWrapper = new RemoteResourceExceptionWrapper();

pncBuilds.forEach(CONCURRENT_MAP_PARALLELISM_THRESHOLD, (buildId, pncBuild) -> {
pncBuilds.forEach(concurrentMapParallelismThreshold, (buildId, pncBuild) -> {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
"Parallel execution of populatePncBuildsMetadata using thread {} of build {}",
Expand Down Expand Up @@ -147,7 +147,7 @@ private Set<EnhancedArtifact> lookupArtifactsInPnc(ConcurrentHashMap<Checksum, C
Set<EnhancedArtifact> artifacts = new ConcurrentHashSet<>();
RemoteResourceExceptionWrapper exceptionWrapper = new RemoteResourceExceptionWrapper();

checksumTable.forEach(CONCURRENT_MAP_PARALLELISM_THRESHOLD, (checksum, fileNames) -> {
checksumTable.forEach(concurrentMapParallelismThreshold, (checksum, fileNames) -> {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
"Parallel execution of lookupArtifactsInPnc using thread {} of an artifact with checksum {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ void verifyCopyConfig() throws IOException {
assertThat(base.getArchiveExtensions(), is(equalTo(baseExtension)));

// when

List<String> updatedExtensions = Arrays.asList("jar", "zip");
List<String> types = Arrays.asList("good", "bad", "ugly");

Expand Down Expand Up @@ -105,6 +104,7 @@ void verifyDefaults() throws JsonProcessingException {
assertThat(bc.getKojiNumThreads(), is(ConfigDefaults.KOJI_NUM_THREADS));
assertThat(bc.getKojiWebURL(), is(ConfigDefaults.KOJI_WEB_URL));
assertThat(bc.getOutputDirectory(), is(ConfigDefaults.OUTPUT_DIR));
assertThat(bc.getPncNumThreads(), is(ConfigDefaults.PNC_NUM_THREADS));
assertThat(bc.getPncPartitionSize(), is(ConfigDefaults.PNC_PARTITION_SIZE));
assertThat(bc.getPncURL(), is(ConfigDefaults.PNC_URL));
assertThat(bc.getUseBuildsFile(), is(ConfigDefaults.USE_BUILDS_FILE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void shouldReturnEmptyResult() throws RemoteResourceException {
// given
PncClient pncClient = Mockito.mock(PncClient.class);
BuildFinderUtils buildFinderUtils = new BuildFinderUtils(buildConfig, null, kojiClientSession);
PncBuildFinder pncBuildFinder = new PncBuildFinder(pncClient, buildFinderUtils);
PncBuildFinder pncBuildFinder = new PncBuildFinder(pncClient, buildFinderUtils, buildConfig);

// when
FindBuildsResult findBuildsResult = pncBuildFinder.findBuildsPnc(new HashMap<>());
Expand Down Expand Up @@ -125,7 +125,7 @@ void shouldFindOneBuildInPnc() throws RemoteResourceException {
.thenThrow(new RemoteResourceNotFoundException(new ClientErrorException(Response.Status.NOT_FOUND)));

BuildFinderUtils buildFinderUtils = new BuildFinderUtils(buildConfig, null, kojiClientSession);
PncBuildFinder pncBuildFinder = new PncBuildFinder(pncClient, buildFinderUtils);
PncBuildFinder pncBuildFinder = new PncBuildFinder(pncClient, buildFinderUtils, buildConfig);

// when
Map<Checksum, Collection<String>> requestMap = Collections
Expand Down Expand Up @@ -155,7 +155,7 @@ void shouldNotFindABuildInPnc() throws RemoteResourceException {
when(pncClient.getArtifactsByMd5(givenMd5)).thenReturn(createArtifactsRemoteCollection());

BuildFinderUtils buildFinderUtils = new BuildFinderUtils(buildConfig, null, kojiClientSession);
PncBuildFinder pncBuildFinder = new PncBuildFinder(pncClient, buildFinderUtils);
PncBuildFinder pncBuildFinder = new PncBuildFinder(pncClient, buildFinderUtils, buildConfig);

// when
Map<Checksum, Collection<String>> requestMap = Collections
Expand Down