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

Allow configuring the maximum number of computation scheduler threads #2580

Merged
merged 3 commits into from
Feb 11, 2015
Merged
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
21 changes: 19 additions & 2 deletions src/main/java/rx/schedulers/EventLoopsScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,24 @@
/** Manages a fixed number of workers. */
private static final String THREAD_NAME_PREFIX = "RxComputationThreadPool-";
private static final RxThreadFactory THREAD_FACTORY = new RxThreadFactory(THREAD_NAME_PREFIX);

/**
* Key to setting the maximum number of computation scheduler threads.
* Zero or less is interpreted as use available. Capped by available.
*/
static final String KEY_MAX_THREADS = "rx.scheduler.max-computation-threads";
/** The maximum number of computation scheduler threads. */
static final int MAX_THREADS;
static {
int maxThreads = Integer.getInteger(KEY_MAX_THREADS, 0);
int ncpu = Runtime.getRuntime().availableProcessors();
int max;
if (maxThreads <= 0 || maxThreads > ncpu) {
max = ncpu;
} else {
max = maxThreads;
}
MAX_THREADS = max;
}
static final class FixedSchedulerPool {
final int cores;

Expand All @@ -40,7 +57,7 @@ static final class FixedSchedulerPool {

FixedSchedulerPool() {
// initialize event loops
this.cores = Runtime.getRuntime().availableProcessors();
this.cores = MAX_THREADS;
this.eventLoops = new PoolWorker[cores];
for (int i = 0; i < cores; i++) {
this.eventLoops[i] = new PoolWorker(THREAD_FACTORY);
Expand Down