SSH show-queue: option to group output by queue and print queue info
When the new option --by-queue is used the output of the show-queue
command is grouped by the work queue. Queue name is printed on top of
the tasks list and the number of worker threads assigned to that thread
pool is printed in the summary line. This option should help Gerrit admins
to identify which thread pools need to be adjusted.
For comparison, here is an example output without the new --by-queue option:
Task State StartTime Command
------------------------------------------------------------------------------
9d51b721 16:29:14.750 git-upload-pack '/gerrit' (admin)
18fr4561 16:29:14.750 git-upload-pack '/gerrit' (admin)
ad52b823 16:29:14.750 git-upload-pack '/gerrit' (admin)
bd51bbcc 16:29:14.750 git-upload-pack '/gerrit' (admin)
11223344 16:29:14.750 git-upload-pack '/gerrit' (admin)
3d120b5c 17:28:20.169 16:28:20.169 Log File Compressor
------------------------------------------------------------------------------
6 tasks
With the --by-queue option the output looks like:
$ ssh -p29418 admin@localhost gerrit show-queue -w --by-queue
Task State StartTime Command
------------------------------------------------------------------------------
Queue: SSH-Interactive-Worker
9d51b721 16:29:14.750 git-upload-pack '/gerrit' (admin)
18fr4561 16:29:14.750 git-upload-pack '/gerrit' (admin)
ad52b823 16:29:14.750 git-upload-pack '/gerrit' (admin)
bd51bbcc 16:29:14.750 git-upload-pack '/gerrit' (admin)
11223344 16:29:14.750 git-upload-pack '/gerrit' (admin)
------------------------------------------------------------------------------
5 tasks, 14 worker threads
Queue: WorkQueue
3d120b5c 17:28:20.169 16:28:20.169 Log File Compressor
------------------------------------------------------------------------------
1 tasks, 1 worker threads
Change-Id: If82bdb50702f2001f887fe5004b0d80b61131a90
This commit is contained in:
@@ -113,6 +113,7 @@ public class ListTasks implements RestReadView<ConfigResource> {
|
||||
public String command;
|
||||
public String remoteName;
|
||||
public String projectName;
|
||||
public String queueName;
|
||||
|
||||
public TaskInfo(Task<?> task) {
|
||||
this.id = IdGenerator.format(task.getTaskId());
|
||||
@@ -120,6 +121,7 @@ public class ListTasks implements RestReadView<ConfigResource> {
|
||||
this.startTime = new Timestamp(task.getStartTime().getTime());
|
||||
this.delay = task.getDelay(TimeUnit.MILLISECONDS);
|
||||
this.command = task.toString();
|
||||
this.queueName = task.getQueueName();
|
||||
|
||||
if (task instanceof ProjectTask) {
|
||||
ProjectTask<?> projectTask = ((ProjectTask<?>) task);
|
||||
|
||||
@@ -152,6 +152,15 @@ public class WorkQueue {
|
||||
return result;
|
||||
}
|
||||
|
||||
public Executor getExecutor(String queueName) {
|
||||
for (Executor e : queues) {
|
||||
if (e.queueName.equals(queueName)) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void stop() {
|
||||
for (final Executor p : queues) {
|
||||
p.shutdown();
|
||||
@@ -170,8 +179,9 @@ public class WorkQueue {
|
||||
/** An isolated queue. */
|
||||
public class Executor extends ScheduledThreadPoolExecutor {
|
||||
private final ConcurrentHashMap<Integer, Task<?>> all;
|
||||
private final String queueName;
|
||||
|
||||
Executor(final int corePoolSize, final String prefix) {
|
||||
Executor(int corePoolSize, final String prefix) {
|
||||
super(corePoolSize, new ThreadFactory() {
|
||||
private final ThreadFactory parent = Executors.defaultThreadFactory();
|
||||
private final AtomicInteger tid = new AtomicInteger(1);
|
||||
@@ -190,6 +200,7 @@ public class WorkQueue {
|
||||
0.75f, // load factor
|
||||
corePoolSize + 4 // concurrency level
|
||||
);
|
||||
queueName = prefix;
|
||||
}
|
||||
|
||||
public void unregisterWorkQueue() {
|
||||
@@ -325,6 +336,10 @@ public class WorkQueue {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public String getQueueName() {
|
||||
return executor.queueName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cancel(boolean mayInterruptIfRunning) {
|
||||
if (task.cancel(mayInterruptIfRunning)) {
|
||||
|
||||
Reference in New Issue
Block a user