From 895598867191317295946ae63102614ce8955e48 Mon Sep 17 00:00:00 2001 From: argha-c <007.argha@gmail.com> Date: Fri, 14 Jul 2023 13:10:13 -0700 Subject: [PATCH 1/2] default to a single thread for server list updates --- .../EurekaNotificationServerListUpdater.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/ribbon-eureka/src/main/java/com/netflix/niws/loadbalancer/EurekaNotificationServerListUpdater.java b/ribbon-eureka/src/main/java/com/netflix/niws/loadbalancer/EurekaNotificationServerListUpdater.java index 2b388db7c..138ddcc69 100644 --- a/ribbon-eureka/src/main/java/com/netflix/niws/loadbalancer/EurekaNotificationServerListUpdater.java +++ b/ribbon-eureka/src/main/java/com/netflix/niws/loadbalancer/EurekaNotificationServerListUpdater.java @@ -33,11 +33,13 @@ public class EurekaNotificationServerListUpdater implements ServerListUpdater { private static final Logger logger = LoggerFactory.getLogger(EurekaNotificationServerListUpdater.class); private static class LazyHolder { - private final static String CORE_THREAD = "EurekaNotificationServerListUpdater.ThreadPoolSize"; + private final static String CORE_THREADS = "EurekaNotificationServerListUpdater.ThreadPoolSize"; + private final static String MAX_THREADS = "EurekaNotificationServerListUpdater.ThreadPoolSize.Max"; private final static String QUEUE_SIZE = "EurekaNotificationServerListUpdater.queueSize"; private final static LazyHolder SINGLETON = new LazyHolder(); - private final DynamicIntProperty poolSizeProp = new DynamicIntProperty(CORE_THREAD, 2); + private final DynamicIntProperty poolSizeMin = new DynamicIntProperty(CORE_THREADS, 1); + private final DynamicIntProperty poolSizeMax = new DynamicIntProperty(MAX_THREADS, 1); private final DynamicIntProperty queueSizeProp = new DynamicIntProperty(QUEUE_SIZE, 1000); private final ThreadPoolExecutor defaultServerListUpdateExecutor; private final Thread shutdownThread; @@ -46,7 +48,7 @@ private LazyHolder() { int corePoolSize = getCorePoolSize(); defaultServerListUpdateExecutor = new ThreadPoolExecutor( corePoolSize, - corePoolSize * 5, + corePoolSize, 0, TimeUnit.NANOSECONDS, new ArrayBlockingQueue(queueSizeProp.get()), @@ -56,12 +58,11 @@ private LazyHolder() { .build() ); - poolSizeProp.addCallback(new Runnable() { + poolSizeMin.addCallback(new Runnable() { @Override public void run() { - int corePoolSize = getCorePoolSize(); - defaultServerListUpdateExecutor.setCorePoolSize(corePoolSize); - defaultServerListUpdateExecutor.setMaximumPoolSize(corePoolSize * 5); + defaultServerListUpdateExecutor.setCorePoolSize(getCorePoolSize()); + defaultServerListUpdateExecutor.setMaximumPoolSize(getCorePoolSizeMax()); } }); @@ -82,12 +83,19 @@ public void run() { } private int getCorePoolSize() { - int propSize = poolSizeProp.get(); + int propSize = poolSizeMin.get(); if (propSize > 0) { return propSize; } return 2; // default } + private int getCorePoolSizeMax() { + int propSize = poolSizeMax.get(); + if (propSize > 0) { + return propSize; + } + return getCorePoolSize(); // default to a single refresher thread + } } public static ExecutorService getDefaultRefreshExecutor() { From 8ab9a645717151aaad096e245309df8d5be59c0c Mon Sep 17 00:00:00 2001 From: argha-c <007.argha@gmail.com> Date: Fri, 14 Jul 2023 13:12:57 -0700 Subject: [PATCH 2/2] fix comment --- .../niws/loadbalancer/EurekaNotificationServerListUpdater.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ribbon-eureka/src/main/java/com/netflix/niws/loadbalancer/EurekaNotificationServerListUpdater.java b/ribbon-eureka/src/main/java/com/netflix/niws/loadbalancer/EurekaNotificationServerListUpdater.java index 138ddcc69..777af9d97 100644 --- a/ribbon-eureka/src/main/java/com/netflix/niws/loadbalancer/EurekaNotificationServerListUpdater.java +++ b/ribbon-eureka/src/main/java/com/netflix/niws/loadbalancer/EurekaNotificationServerListUpdater.java @@ -94,7 +94,7 @@ private int getCorePoolSizeMax() { if (propSize > 0) { return propSize; } - return getCorePoolSize(); // default to a single refresher thread + return getCorePoolSize(); // default to a fixed size thread pool } }