zipkin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <>
Subject [GitHub] [incubator-zipkin] adriancole commented on a change in pull request #2502: Adding storage-throttle module to address "over capacity" issues
Date Mon, 06 May 2019 23:36:01 GMT
adriancole commented on a change in pull request #2502: Adding storage-throttle module to address
"over capacity" issues

 File path: zipkin-server/src/main/java/zipkin2/server/internal/throttle/
 @@ -0,0 +1,179 @@
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ *
+ *
+ * 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 zipkin2.server.internal.throttle;
+import io.micrometer.core.instrument.MeterRegistry;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+ * Delegating implementation that limits requests to the {@link #spanConsumer()} of another
+ * {@link StorageComponent}.  The theory here is that this class can be used to:
+ * <ul>
+ * <li>Prevent spamming the storage engine with excessive, spike requests when they
come in; thus preserving it's life.</li>
+ * <li>Optionally act as a buffer so that a fixed number requests can be queued for
execution when the throttle allows
+ *     for it.  This optional queue must be bounded in order to avoid running out of memory
from infinitely queueing.</li>
+ * </ul>
+ *
+ * @see ThrottledSpanConsumer
+ */
+public final class ThrottledStorageComponent extends StorageComponent {
+  final StorageComponent delegate;
+  final AbstractLimiter<Void> limiter;
+  final ThreadPoolExecutor executor;
+  public ThrottledStorageComponent(StorageComponent delegate,
+                                   MeterRegistry registry,
+                                   int minConcurrency,
+                                   int maxConcurrency,
+                                   int maxQueueSize) {
+    this.delegate = Objects.requireNonNull(delegate);
+    Limit limit = Gradient2Limit.newBuilder()
+        .minLimit(minConcurrency)
+        .initialLimit(minConcurrency) // Limiter will trend towards min until otherwise necessary
so may as well start there
+        .maxConcurrency(maxConcurrency)
+        .queueSize(0)
+        .build();
+    this.limiter = new Builder().limit(limit).build();
+    this.executor = new ThreadPoolExecutor(limit.getLimit(),
+                                           limit.getLimit(),
+                                           0,
+                                           TimeUnit.DAYS,
+                                           createQueue(maxQueueSize),
+                                           new ThottledThreadFactory(),
+                                           new ThreadPoolExecutor.AbortPolicy());
+    limit.notifyOnChange(new ThreadPoolExecutorResizer(executor));
+    if (registry != null) {
 Review comment:
   Usually when something is disabled.. if it is also injected a bunch of places, that tool
makes a no-op variant so that call sites don't need to inject anything. As this is our server,
I don't anticipate us disabiling meters, and if we did and that would produce null, it would
also break our other code.
   One reason we don't support custom servers is to allow simpler decisions on topics like

This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:

With regards,
Apache Git Services

View raw message