Add a separate queue for non-interactive users

A new internal user group, "Non-Interactive Users" is added. members
of this group are not expected to perform interactive operations on
the gerrit web frontend.

However, sometimes such a user may need a separate thread pool in
order to prevent it from grabbing threads from the interactive users.

This change introduces a second thread pool, which separates
operations from the non-interactive users from the interactive ones.
This ensures that the interactive users can keep working when
resources are tight.

Change-Id: I16334dd84ec50e1a6ca894e635c8beea9bd42115
This commit is contained in:
Nico Sallembien
2010-05-18 16:40:10 -07:00
parent 8ef3b69f35
commit fc53f7fd7a
12 changed files with 224 additions and 37 deletions

View File

@@ -15,6 +15,7 @@
package com.google.gerrit.pgm.http.jetty;
import static com.google.gerrit.server.config.ConfigUtil.getTimeUnit;
import static com.google.inject.Scopes.SINGLETON;
import static java.util.concurrent.TimeUnit.MINUTES;
import static javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE;
@@ -23,7 +24,8 @@ import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.git.WorkQueue;
import com.google.gerrit.server.git.WorkQueue.CancelableRunnable;
import com.google.gerrit.sshd.CommandExecutor;
import com.google.gerrit.sshd.CommandExecutorQueueProvider;
import com.google.gerrit.sshd.QueueProvider;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
@@ -73,33 +75,28 @@ public class ProjectQoSFilter implements Filter {
private static final Pattern URI_PATTERN = Pattern.compile(FILTER_RE);
public static class Module extends ServletModule {
private final WorkQueue.Executor executor;
@Inject
Module(@CommandExecutor final WorkQueue.Executor executor) {
this.executor = executor;
}
@Override
protected void configureServlets() {
bind(WorkQueue.Executor.class).annotatedWith(CommandExecutor.class)
.toInstance(executor);
bind(QueueProvider.class).to(CommandExecutorQueueProvider.class)
.in(SINGLETON);
filterRegex(FILTER_RE).through(ProjectQoSFilter.class);
}
}
private final Provider<CurrentUser> userProvider;
private final WorkQueue.Executor executor;
private final QueueProvider queue;
private final ServletContext context;
private final long maxWait;
@SuppressWarnings("unchecked")
@Inject
ProjectQoSFilter(final Provider<CurrentUser> userProvider,
@CommandExecutor final WorkQueue.Executor executor,
final ServletContext context, @GerritServerConfig final Config cfg) {
QueueProvider queue, final ServletContext context,
@GerritServerConfig final Config cfg) {
this.userProvider = userProvider;
this.executor = executor;
this.queue = queue;
this.context = context;
this.maxWait = getTimeUnit(cfg, "httpd", null, "maxwait", 5, MINUTES);
}
@@ -111,6 +108,8 @@ public class ProjectQoSFilter implements Filter {
final HttpServletResponse rsp = (HttpServletResponse) response;
final Continuation cont = ContinuationSupport.getContinuation(req);
WorkQueue.Executor executor = getExecutor();
if (cont.isInitial()) {
TaskThunk task = new TaskThunk(cont, req);
if (maxWait > 0) {
@@ -143,6 +142,16 @@ public class ProjectQoSFilter implements Filter {
}
}
private WorkQueue.Executor getExecutor() {
WorkQueue.Executor executor;
if (userProvider.get().isBatchUser()) {
executor = queue.getBatchQueue();
} else {
executor = queue.getInteractiveQueue();
}
return executor;
}
@Override
public void init(FilterConfig config) {
}
@@ -210,6 +219,7 @@ public class ProjectQoSFilter implements Filter {
@Override
public void onTimeout(Continuation self) {
WorkQueue.Executor executor = getExecutor();
executor.remove(this);
}