mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-20 07:18:05 +01:00
Instrument BlockingThreadPoolExecutor.
This commit is contained in:
committed by
Jon Chambers
parent
6f767a72a7
commit
c17cc07b73
@@ -56,7 +56,7 @@ public class PushSender implements Managed {
|
||||
this.apnSender = apnSender;
|
||||
this.webSocketSender = websocketSender;
|
||||
this.queueSize = queueSize;
|
||||
this.executor = new BlockingThreadPoolExecutor(50, queueSize);
|
||||
this.executor = new BlockingThreadPoolExecutor("pushSender", 50, queueSize);
|
||||
|
||||
SharedMetricRegistries.getOrCreate(Constants.METRICS_NAME)
|
||||
.register(name(PushSender.class, "send_queue_depth"),
|
||||
|
||||
@@ -1,22 +1,36 @@
|
||||
package org.whispersystems.textsecuregcm.util;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.codahale.metrics.SharedMetricRegistries;
|
||||
import com.codahale.metrics.Timer;
|
||||
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.codahale.metrics.MetricRegistry.name;
|
||||
|
||||
public class BlockingThreadPoolExecutor extends ThreadPoolExecutor {
|
||||
|
||||
private final Semaphore semaphore;
|
||||
private final Timer acquirePermitTimer;
|
||||
|
||||
public BlockingThreadPoolExecutor(int threads, int bound) {
|
||||
public BlockingThreadPoolExecutor(String name, int threads, int bound) {
|
||||
super(threads, threads, 1, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
|
||||
this.semaphore = new Semaphore(bound);
|
||||
|
||||
final MetricRegistry metricRegistry = SharedMetricRegistries.getOrCreate(Constants.METRICS_NAME);
|
||||
|
||||
this.acquirePermitTimer = metricRegistry.timer(name(getClass(), name, "acquirePermit"));
|
||||
metricRegistry.gauge(name(getClass(), name, "permitsAvailable"), () -> semaphore::availablePermits);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable task) {
|
||||
semaphore.acquireUninterruptibly();
|
||||
try (final Timer.Context ignored = acquirePermitTimer.time()) {
|
||||
semaphore.acquireUninterruptibly();
|
||||
}
|
||||
|
||||
try {
|
||||
super.execute(task);
|
||||
|
||||
Reference in New Issue
Block a user