From a88b30bf099e07e367da786b4bca5f664d9e16a8 Mon Sep 17 00:00:00 2001 From: awazalwar Date: Mon, 29 Feb 2016 15:00:50 -0500 Subject: [PATCH 1/3] #1109 MetricJsonListener queue size can be configured by passing additional queueSize= parameter in stream query --- .../HystrixMetricsStreamServlet.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsStreamServlet.java b/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsStreamServlet.java index eb798eb06..7f301a81f 100644 --- a/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsStreamServlet.java +++ b/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsStreamServlet.java @@ -135,7 +135,17 @@ private void handleRequest(HttpServletRequest request, HttpServletResponse respo response.setHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate"); response.setHeader("Pragma", "no-cache"); - MetricJsonListener jsonListener = new MetricJsonListener(); + int queueSize = 1000; + try { + String q = request.getParameter("queueSize"); + if (q != null) { + queueSize = Math.max(Integer.parseInt(q), queueSize); + } + } catch (Exception e) { + // ignore if it's not a number + } + + MetricJsonListener jsonListener = new MetricJsonListener(queueSize); poller = new HystrixMetricsPoller(jsonListener, delay); // start polling and it will write directly to the output stream poller.start(); @@ -207,7 +217,11 @@ private static class MetricJsonListener implements HystrixMetricsPoller.MetricsA *

* This is a safety check against a runaway poller causing memory leaks. */ - private final LinkedBlockingQueue jsonMetrics = new LinkedBlockingQueue(1000); + private LinkedBlockingQueue jsonMetrics; + + public MetricJsonListener(int queueSize) { + jsonMetrics = new LinkedBlockingQueue(queueSize); + } /** * Store JSON messages in a queue. From 1410bee12e9555453e16fbbe9f27eafefd48fa4c Mon Sep 17 00:00:00 2001 From: awazalwar Date: Wed, 2 Mar 2016 11:47:39 -0500 Subject: [PATCH 2/3] #1109 Make default metric listener queue size configurable by property hystrix.stream.defaultMetricListenerQueueSize (still defaults to 1000 if unspecified) --- .../metrics/eventstream/HystrixMetricsStreamServlet.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsStreamServlet.java b/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsStreamServlet.java index 7f301a81f..caaa77a79 100644 --- a/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsStreamServlet.java +++ b/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsStreamServlet.java @@ -62,6 +62,7 @@ public class HystrixMetricsStreamServlet extends HttpServlet { /* used to track number of connections and throttle */ private static AtomicInteger concurrentConnections = new AtomicInteger(0); private static DynamicIntProperty maxConcurrentConnections = DynamicPropertyFactory.getInstance().getIntProperty("hystrix.stream.maxConcurrentConnections", 5); + private static DynamicIntProperty defaultMetricListenerQueueSize = DynamicPropertyFactory.getInstance().getIntProperty("hystrix.stream.defaultMetricListenerQueueSize", 1000); private static volatile boolean isDestroyed = false; @@ -135,11 +136,11 @@ private void handleRequest(HttpServletRequest request, HttpServletResponse respo response.setHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate"); response.setHeader("Pragma", "no-cache"); - int queueSize = 1000; + int queueSize = defaultMetricListenerQueueSize.get(); try { String q = request.getParameter("queueSize"); if (q != null) { - queueSize = Math.max(Integer.parseInt(q), queueSize); + queueSize = Integer.parseInt(q); } } catch (Exception e) { // ignore if it's not a number From ee6c90ac937f5e8a27fa17fdfb78cf333ad983cd Mon Sep 17 00:00:00 2001 From: awazalwar Date: Fri, 11 Mar 2016 16:37:16 -0500 Subject: [PATCH 3/3] #1109 Rolling back request parameter support for setting queueSize --- .../HystrixMetricsStreamServlet.java | 28 ++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsStreamServlet.java b/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsStreamServlet.java index caaa77a79..6dd8c07a8 100644 --- a/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsStreamServlet.java +++ b/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsStreamServlet.java @@ -15,22 +15,20 @@ */ package com.netflix.hystrix.contrib.metrics.eventstream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.atomic.AtomicInteger; +import com.netflix.config.DynamicIntProperty; +import com.netflix.config.DynamicPropertyFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.netflix.config.DynamicIntProperty; -import com.netflix.config.DynamicPropertyFactory; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.atomic.AtomicInteger; /** * Streams Hystrix metrics in text/event-stream format. @@ -137,14 +135,6 @@ private void handleRequest(HttpServletRequest request, HttpServletResponse respo response.setHeader("Pragma", "no-cache"); int queueSize = defaultMetricListenerQueueSize.get(); - try { - String q = request.getParameter("queueSize"); - if (q != null) { - queueSize = Integer.parseInt(q); - } - } catch (Exception e) { - // ignore if it's not a number - } MetricJsonListener jsonListener = new MetricJsonListener(queueSize); poller = new HystrixMetricsPoller(jsonListener, delay);