From 2f31b96666ce705e18d7216771f18c83f0dce0c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20St=C3=A4ber?= Date: Thu, 19 May 2022 23:30:03 +0200 Subject: [PATCH] Reduce number of core threads in HTTPServer to one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabian Stäber --- .../prometheus/client/exporter/HTTPServer.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/simpleclient_httpserver/src/main/java/io/prometheus/client/exporter/HTTPServer.java b/simpleclient_httpserver/src/main/java/io/prometheus/client/exporter/HTTPServer.java index b7188a95c..ffb591ab8 100644 --- a/simpleclient_httpserver/src/main/java/io/prometheus/client/exporter/HTTPServer.java +++ b/simpleclient_httpserver/src/main/java/io/prometheus/client/exporter/HTTPServer.java @@ -1,10 +1,15 @@ package io.prometheus.client.exporter; +import com.sun.net.httpserver.Authenticator; +import com.sun.net.httpserver.HttpContext; +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpServer; import com.sun.net.httpserver.HttpsConfigurator; import com.sun.net.httpserver.HttpsServer; import io.prometheus.client.CollectorRegistry; -import io.prometheus.client.SampleNameFilter; import io.prometheus.client.Predicate; +import io.prometheus.client.SampleNameFilter; import io.prometheus.client.Supplier; import io.prometheus.client.exporter.common.TextFormat; @@ -25,15 +30,10 @@ import java.util.concurrent.Executors; import java.util.concurrent.FutureTask; import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.atomic.AtomicInteger; import java.util.zip.GZIPOutputStream; -import com.sun.net.httpserver.Authenticator; -import com.sun.net.httpserver.HttpContext; -import com.sun.net.httpserver.HttpExchange; -import com.sun.net.httpserver.HttpHandler; -import com.sun.net.httpserver.HttpServer; - /** * Expose Prometheus metrics using a plain Java HttpServer. *

@@ -452,7 +452,9 @@ private HTTPServer(ExecutorService executorService, HttpServer httpServer, Colle if (executorService != null) { this.executorService = executorService; } else { - this.executorService = Executors.newFixedThreadPool(5, NamedDaemonThreadFactory.defaultThreadFactory(daemon)); + ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(5, NamedDaemonThreadFactory.defaultThreadFactory(daemon)); + executor.setCorePoolSize(1); + this.executorService = executor; } server.setExecutor(this.executorService); start(daemon);