Run ReceiveCommits in a shared thread pool

Since the work ReceiveCommits may take a long, potentially unbounded
amount of time, we would like to have it run in the background so it
can be monitored for timeouts and cancelled, and have stalls reported
to the user from the main thread.

Wraps ReceiveCommits in a new PreReceiveHook, AsyncReceiveCommits,
that runs its delegated ReceiveCommits in a WorkQueue.Executor.

The default implementation sizes the thread pool to the number of
available processors, under the assumption that most database and pack
operations are essentially CPU-bound. This is after reading the pack
from the wire, indexing it, and storing it locally, so there is no I/O
to the client involved, and available CPUs is a pretty good estimate.
Since it may not be in some cases, for example if threads block on
slow database I/O, the pool size is configurable.

Change-Id: I5769944b49ead4224a1855ba72ee359de26e7bf8
This commit is contained in:
Dave Borowitz
2012-03-01 14:22:29 -08:00
parent 227fe30f2a
commit 234734a5f5
10 changed files with 248 additions and 17 deletions

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.sshd.commands;
import com.google.gerrit.common.data.Capable;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.git.AsyncReceiveCommits;
import com.google.gerrit.server.git.ReceiveCommits;
import com.google.gerrit.server.git.TransferConfig;
import com.google.gerrit.server.git.VisibleRefFilter;
@@ -39,7 +40,7 @@ import java.util.Set;
/** Receives change upload over SSH using the Git receive-pack protocol. */
final class Receive extends AbstractGitCommand {
@Inject
private ReceiveCommits.Factory factory;
private AsyncReceiveCommits.Factory factory;
@Inject
private IdentifiedUser currentUser;
@@ -69,7 +70,8 @@ final class Receive extends AbstractGitCommand {
throw new Failure(1, "fatal: receive-pack not permitted on this server");
}
final ReceiveCommits receive = factory.create(projectControl, repo);
final ReceiveCommits receive = factory.create(projectControl, repo)
.getReceiveCommits();
Capable r = receive.canUpload();
if (r != Capable.OK) {