|
15 | 15 | */
|
16 | 16 | package com.netflix.hystrix.contrib.metrics.eventstream;
|
17 | 17 |
|
18 |
| -import java.io.IOException; |
19 |
| -import java.util.ArrayList; |
20 |
| -import java.util.List; |
21 |
| -import java.util.concurrent.LinkedBlockingQueue; |
22 |
| -import java.util.concurrent.atomic.AtomicInteger; |
| 18 | +import com.netflix.config.DynamicIntProperty; |
| 19 | +import com.netflix.config.DynamicPropertyFactory; |
| 20 | +import org.slf4j.Logger; |
| 21 | +import org.slf4j.LoggerFactory; |
23 | 22 |
|
24 | 23 | import javax.servlet.ServletException;
|
25 | 24 | import javax.servlet.http.HttpServlet;
|
26 | 25 | import javax.servlet.http.HttpServletRequest;
|
27 | 26 | import javax.servlet.http.HttpServletResponse;
|
28 |
| - |
29 |
| -import org.slf4j.Logger; |
30 |
| -import org.slf4j.LoggerFactory; |
31 |
| - |
32 |
| -import com.netflix.config.DynamicIntProperty; |
33 |
| -import com.netflix.config.DynamicPropertyFactory; |
| 27 | +import java.io.IOException; |
| 28 | +import java.util.ArrayList; |
| 29 | +import java.util.List; |
| 30 | +import java.util.concurrent.LinkedBlockingQueue; |
| 31 | +import java.util.concurrent.atomic.AtomicInteger; |
34 | 32 |
|
35 | 33 | /**
|
36 | 34 | * Streams Hystrix metrics in text/event-stream format.
|
@@ -62,6 +60,7 @@ public class HystrixMetricsStreamServlet extends HttpServlet {
|
62 | 60 | /* used to track number of connections and throttle */
|
63 | 61 | private static AtomicInteger concurrentConnections = new AtomicInteger(0);
|
64 | 62 | private static DynamicIntProperty maxConcurrentConnections = DynamicPropertyFactory.getInstance().getIntProperty("hystrix.stream.maxConcurrentConnections", 5);
|
| 63 | + private static DynamicIntProperty defaultMetricListenerQueueSize = DynamicPropertyFactory.getInstance().getIntProperty("hystrix.stream.defaultMetricListenerQueueSize", 1000); |
65 | 64 |
|
66 | 65 | private static volatile boolean isDestroyed = false;
|
67 | 66 |
|
@@ -135,7 +134,9 @@ private void handleRequest(HttpServletRequest request, HttpServletResponse respo
|
135 | 134 | response.setHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");
|
136 | 135 | response.setHeader("Pragma", "no-cache");
|
137 | 136 |
|
138 |
| - MetricJsonListener jsonListener = new MetricJsonListener(); |
| 137 | + int queueSize = defaultMetricListenerQueueSize.get(); |
| 138 | + |
| 139 | + MetricJsonListener jsonListener = new MetricJsonListener(queueSize); |
139 | 140 | poller = new HystrixMetricsPoller(jsonListener, delay);
|
140 | 141 | // start polling and it will write directly to the output stream
|
141 | 142 | poller.start();
|
@@ -207,7 +208,11 @@ private static class MetricJsonListener implements HystrixMetricsPoller.MetricsA
|
207 | 208 | * <p>
|
208 | 209 | * This is a safety check against a runaway poller causing memory leaks.
|
209 | 210 | */
|
210 |
| - private final LinkedBlockingQueue<String> jsonMetrics = new LinkedBlockingQueue<String>(1000); |
| 211 | + private LinkedBlockingQueue<String> jsonMetrics; |
| 212 | + |
| 213 | + public MetricJsonListener(int queueSize) { |
| 214 | + jsonMetrics = new LinkedBlockingQueue<String>(queueSize); |
| 215 | + } |
211 | 216 |
|
212 | 217 | /**
|
213 | 218 | * Store JSON messages in a queue.
|
|
0 commit comments