Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default to single thread for server list updates #514

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,7 +48,7 @@ private LazyHolder() {
int corePoolSize = getCorePoolSize();
defaultServerListUpdateExecutor = new ThreadPoolExecutor(
corePoolSize,
corePoolSize * 5,
corePoolSize,
0,
TimeUnit.NANOSECONDS,
new ArrayBlockingQueue<Runnable>(queueSizeProp.get()),
Expand All @@ -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());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, in JDK9, they added more error checking when you call setCorePoolSize, so if you attempt to resize higher than the maximum pool size, it'll error out. We found this within Hystrix as well : Netflix/Hystrix#1874 (comment)

Generally, you can just flip them, but then the inverse is true if you try to resize the max lower. Not sure if we need to accommodate that, but something to be aware of.

defaultServerListUpdateExecutor.setMaximumPoolSize(getCorePoolSizeMax());
}
});

Expand All @@ -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 fixed size thread pool
}
}

public static ExecutorService getDefaultRefreshExecutor() {
Expand Down