-
Notifications
You must be signed in to change notification settings - Fork 15
Borrow WC variants of executor views to reduce thread count and increase reuse #4877
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,17 +23,12 @@ | |
import java.util.Set; | ||
import java.util.UUID; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.SynchronousQueue; | ||
import java.util.concurrent.ThreadFactory; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
|
||
import org.immutables.value.Value; | ||
|
||
import com.codahale.metrics.InstrumentedExecutorService; | ||
import com.codahale.metrics.MetricRegistry; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.google.common.collect.Iterables; | ||
|
@@ -49,7 +44,6 @@ | |
import com.palantir.atlasdb.http.NotCurrentLeaderExceptionMapper; | ||
import com.palantir.atlasdb.util.AtlasDbMetrics; | ||
import com.palantir.atlasdb.util.MetricsManager; | ||
import com.palantir.common.concurrent.NamedThreadFactory; | ||
import com.palantir.common.concurrent.PTExecutors; | ||
import com.palantir.common.streams.KeyedStream; | ||
import com.palantir.conjure.java.api.config.service.UserAgent; | ||
|
@@ -59,7 +53,6 @@ | |
import com.palantir.leader.LeaderElectionServiceBuilder; | ||
import com.palantir.leader.LeadershipObserver; | ||
import com.palantir.leader.LocalPingableLeader; | ||
import com.palantir.leader.PaxosLeaderElectionService; | ||
import com.palantir.leader.PaxosLeadershipEventRecorder; | ||
import com.palantir.leader.PingableLeader; | ||
import com.palantir.paxos.ImmutableLeaderPingerContext; | ||
|
@@ -239,20 +232,7 @@ private static <T> Map<T, ExecutorService> createExecutorsForService( | |
// TODO (jkong): Make the limits configurable. | ||
// Current use cases tend to have not more than 10 (<< 100) inflight tasks under normal circumstances. | ||
private static ExecutorService createExecutor(MetricsManager metricsManager, String useCase, int corePoolSize) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this is private so we could probably remove the unused corepoolsize parameter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iirc it's passed through several methods and I wanted to keep the code churn to a minimum. |
||
return new InstrumentedExecutorService( | ||
PTExecutors.newThreadPoolExecutor( | ||
corePoolSize, | ||
100, | ||
5000, | ||
TimeUnit.MILLISECONDS, | ||
new SynchronousQueue<>(), | ||
daemonThreadFactory("atlas-leaders-election-" + useCase)), | ||
metricsManager.getRegistry(), | ||
MetricRegistry.name(PaxosLeaderElectionService.class, useCase, "executor")); | ||
} | ||
|
||
private static ThreadFactory daemonThreadFactory(String name) { | ||
return new NamedThreadFactory(name, true); | ||
return PTExecutors.newCachedThreadPoolWithMaxThreads(100, "atlas-leaders-election-" + useCase); | ||
} | ||
|
||
public static <T> List<T> createProxyAndLocalList( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
changes: | ||
- type: improvement | ||
improvement: | ||
description: |- | ||
PTExecutors simple cached and fixed executor factories (those which don't consume a ThreadFactory) use views | ||
over a shared executor service to reduce total thread count and promote resource reuse. | ||
links: | ||
- https://github.com/palantir/atlasdb/pull/4877 | ||
- type: break | ||
break: | ||
description: |- | ||
`PTExecutors.newFixedThreadPool` overloads return `ExecutorService` instead of the concrete `ThreadPoolExecutor` type. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: will cause breaks in large internal product. Can confirm not used by the common AtlasDB supporting libraries. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm planning to fix the internal product once this is available. |
||
links: | ||
- https://github.com/palantir/atlasdb/pull/4877 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This executor configuration is highly suspect. At a glance I believe it will only ever have a single thread unless we manage to fill the LinkedBlockingQueue with Integer.MAX_VALUE elements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We looked at metrics-platform and it turns out this executor is basically unused in practice...