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

@@ -0,0 +1,74 @@
// Copyright (C) 2013 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.package com.google.gerrit.server.git;
package com.google.gerrit.server.index;
import com.google.common.util.concurrent.ListeningScheduledExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.git.WorkQueue;
import com.google.gerrit.server.git.WorkQueue.Executor;
import com.google.gerrit.server.query.change.IndexRewrite;
import com.google.gerrit.server.query.change.IndexRewriteImpl;
import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import org.eclipse.jgit.lib.Config;
/**
* Module for non-indexer-specific secondary index setup.
* <p>
* This module should not be used directly except by specific secondary indexer
* implementations (e.g. Lucene).
*/
public class IndexModule extends AbstractModule {
public static boolean isEnabled(Injector injector) {
return injector.getInstance(Key.get(Config.class, GerritServerConfig.class))
.getBoolean("index", null, "enabled", false);
}
private final int threads;
public IndexModule(int threads) {
this.threads = threads;
}
@Override
protected void configure() {
bind(ChangeIndexer.class).to(ChangeIndexerImpl.class);
bind(IndexRewrite.class).to(IndexRewriteImpl.class);
}
@Provides
@Singleton
@IndexExecutor
ListeningScheduledExecutorService getIndexExecutor(
@GerritServerConfig Config config,
WorkQueue workQueue) {
int threads = this.threads;
if (threads <= 0) {
threads = config.getInt("index", null, "threads", 0);
}
Executor executor;
if (threads <= 0) {
executor = workQueue.getDefaultQueue();
} else {
executor = workQueue.createQueue(threads, "index");
}
return MoreExecutors.listeningDecorator(executor);
}
}