Control threadpool behavior for indexing

For the Reindex command, use a new threadpool defaulting to the number
of available processors, under the assumption that the bulk of
indexing time is in CPU-intensive work like tree diffing. Modify
ChangeIndexer to return ListenableFutures so we can bound the size of
the work queue.

For the server, default to using the default work queue, but make this
configurable as index.threads to use a dedicated threadpool, with
non-positive values indicating the default.

Because we now have more non-Lucene-specific Guice logic, split that
out into its own module.

Change-Id: I55181e556a2d43b81c9032f53b74b690342ab62b
This commit is contained in:
Dave Borowitz
2013-05-29 15:03:12 -07:00
parent 20035a4dc9
commit c64399fe93
8 changed files with 244 additions and 69 deletions

View File

@@ -15,38 +15,26 @@
package com.google.gerrit.lucene;
import com.google.gerrit.lifecycle.LifecycleModule;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.index.ChangeIndex;
import com.google.gerrit.server.index.ChangeIndexer;
import com.google.gerrit.server.index.ChangeIndexerImpl;
import com.google.gerrit.server.query.change.IndexRewrite;
import com.google.gerrit.server.query.change.IndexRewriteImpl;
import com.google.inject.Injector;
import com.google.inject.Key;
import org.eclipse.jgit.lib.Config;
import com.google.gerrit.server.index.IndexModule;
public class LuceneIndexModule extends LifecycleModule {
public static boolean isEnabled(Injector injector) {
return injector.getInstance(Key.get(Config.class, GerritServerConfig.class))
.getBoolean("index", null, "enabled", false);
}
private final boolean checkVersion;
private final int threads;
public LuceneIndexModule() {
this(true);
this(true, 0);
}
public LuceneIndexModule(boolean checkVersion) {
public LuceneIndexModule(boolean checkVersion, int threads) {
this.checkVersion = checkVersion;
this.threads = threads;
}
@Override
protected void configure() {
install(new IndexModule(threads));
bind(ChangeIndex.Manager.class).to(LuceneChangeIndexManager.class);
bind(ChangeIndexer.class).to(ChangeIndexerImpl.class);
bind(IndexRewrite.class).to(IndexRewriteImpl.class);
listener().to(LuceneChangeIndexManager.class);
if (checkVersion) {
listener().to(IndexVersionCheck.class);