YARN-11332. [Federation] Improve FederationClientInterceptor#ThreadPool thread pool configuration. (#4982)
This commit is contained in:
parent
b1cd88c598
commit
070a2d4880
@ -4136,11 +4136,87 @@ public static boolean isAclEnabled(Configuration conf) {
|
|||||||
|
|
||||||
public static final String ROUTER_WEBAPP_PREFIX = ROUTER_PREFIX + "webapp.";
|
public static final String ROUTER_WEBAPP_PREFIX = ROUTER_PREFIX + "webapp.";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This configurable that controls the thread pool size of the threadpool of the interceptor.
|
||||||
|
* The corePoolSize(minimumPoolSize) and maximumPoolSize of the thread pool
|
||||||
|
* are controlled by this configurable.
|
||||||
|
* In order to control the thread pool more accurately, this parameter is deprecated.
|
||||||
|
*
|
||||||
|
* corePoolSize(minimumPoolSize) use
|
||||||
|
* {@link YarnConfiguration#ROUTER_USER_CLIENT_THREAD_POOL_MINIMUM_POOL_SIZE}
|
||||||
|
*
|
||||||
|
* maximumPoolSize use
|
||||||
|
* {@link YarnConfiguration#ROUTER_USER_CLIENT_THREAD_POOL_MAXIMUM_POOL_SIZE}
|
||||||
|
*
|
||||||
|
* This configurable will be deprecated.
|
||||||
|
*/
|
||||||
public static final String ROUTER_USER_CLIENT_THREADS_SIZE =
|
public static final String ROUTER_USER_CLIENT_THREADS_SIZE =
|
||||||
ROUTER_PREFIX + "interceptor.user.threadpool-size";
|
ROUTER_PREFIX + "interceptor.user.threadpool-size";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default value is 5.
|
||||||
|
* which means that the corePoolSize(minimumPoolSize) and maximumPoolSize
|
||||||
|
* of the thread pool are both 5s.
|
||||||
|
*
|
||||||
|
* corePoolSize(minimumPoolSize) default value use
|
||||||
|
* {@link YarnConfiguration#DEFAULT_ROUTER_USER_CLIENT_THREAD_POOL_MINIMUM_POOL_SIZE}
|
||||||
|
*
|
||||||
|
* maximumPoolSize default value use
|
||||||
|
* {@link YarnConfiguration#DEFAULT_ROUTER_USER_CLIENT_THREAD_POOL_MAXIMUM_POOL_SIZE}
|
||||||
|
*/
|
||||||
public static final int DEFAULT_ROUTER_USER_CLIENT_THREADS_SIZE = 5;
|
public static final int DEFAULT_ROUTER_USER_CLIENT_THREADS_SIZE = 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This configurable is used to set the corePoolSize(minimumPoolSize)
|
||||||
|
* of the thread pool of the interceptor.
|
||||||
|
*
|
||||||
|
* corePoolSize the number of threads to keep in the pool, even if they are idle.
|
||||||
|
*/
|
||||||
|
public static final String ROUTER_USER_CLIENT_THREAD_POOL_MINIMUM_POOL_SIZE =
|
||||||
|
ROUTER_PREFIX + "interceptor.user-thread-pool.minimum-pool-size";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This configuration is used to set the default value of corePoolSize (minimumPoolSize)
|
||||||
|
* of the thread pool of the interceptor.
|
||||||
|
*
|
||||||
|
* Default is 5.
|
||||||
|
*/
|
||||||
|
public static final int DEFAULT_ROUTER_USER_CLIENT_THREAD_POOL_MINIMUM_POOL_SIZE = 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This configurable is used to set the maximumPoolSize of the thread pool of the interceptor.
|
||||||
|
*
|
||||||
|
* maximumPoolSize the maximum number of threads to allow in the pool.
|
||||||
|
*/
|
||||||
|
public static final String ROUTER_USER_CLIENT_THREAD_POOL_MAXIMUM_POOL_SIZE =
|
||||||
|
ROUTER_PREFIX + "interceptor.user-thread-pool.maximum-pool-size";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This configuration is used to set the default value of maximumPoolSize
|
||||||
|
* of the thread pool of the interceptor.
|
||||||
|
*
|
||||||
|
* Default is 5.
|
||||||
|
*/
|
||||||
|
public static final int DEFAULT_ROUTER_USER_CLIENT_THREAD_POOL_MAXIMUM_POOL_SIZE = 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This configurable is used to set the keepAliveTime of the thread pool of the interceptor.
|
||||||
|
*
|
||||||
|
* keepAliveTime when the number of threads is greater than the core,
|
||||||
|
* this is the maximum time that excess idle threads will wait for new tasks before terminating.
|
||||||
|
*/
|
||||||
|
public static final String ROUTER_USER_CLIENT_THREAD_POOL_KEEP_ALIVE_TIME =
|
||||||
|
ROUTER_PREFIX + "interceptor.user-thread-pool.keep-alive-time";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This configurable is used to set the default time of keepAliveTime
|
||||||
|
* of the thread pool of the interceptor.
|
||||||
|
*
|
||||||
|
* the default value is 0s.
|
||||||
|
*/
|
||||||
|
public static final long DEFAULT_ROUTER_USER_CLIENT_THREAD_POOL_KEEP_ALIVE_TIME =
|
||||||
|
TimeUnit.SECONDS.toMillis(0); // 0s
|
||||||
|
|
||||||
/** The address of the Router web application. */
|
/** The address of the Router web application. */
|
||||||
public static final String ROUTER_WEBAPP_ADDRESS =
|
public static final String ROUTER_WEBAPP_ADDRESS =
|
||||||
ROUTER_WEBAPP_PREFIX + "address";
|
ROUTER_WEBAPP_PREFIX + "address";
|
||||||
|
@ -5047,6 +5047,35 @@
|
|||||||
</description>
|
</description>
|
||||||
</property>
|
</property>
|
||||||
|
|
||||||
|
<property>
|
||||||
|
<name>yarn.router.interceptor.user-thread-pool.minimum-pool-size</name>
|
||||||
|
<value>5</value>
|
||||||
|
<description>
|
||||||
|
This configurable is used to set the corePoolSize(minimumPoolSize)
|
||||||
|
of the thread pool of the interceptor.
|
||||||
|
Default is 5.
|
||||||
|
</description>
|
||||||
|
</property>
|
||||||
|
|
||||||
|
<property>
|
||||||
|
<name>yarn.router.interceptor.user-thread-pool.maximum-pool-size</name>
|
||||||
|
<value>5</value>
|
||||||
|
<description>
|
||||||
|
This configuration is used to set the default value of maximumPoolSize
|
||||||
|
of the thread pool of the interceptor.
|
||||||
|
Default is 5.
|
||||||
|
</description>
|
||||||
|
</property>
|
||||||
|
|
||||||
|
<property>
|
||||||
|
<name>yarn.router.interceptor.user-thread-pool.keep-alive-time</name>
|
||||||
|
<value>0s</value>
|
||||||
|
<description>
|
||||||
|
This configurable is used to set the keepAliveTime of the thread pool of the interceptor.
|
||||||
|
Default is 0s.
|
||||||
|
</description>
|
||||||
|
</property>
|
||||||
|
|
||||||
<property>
|
<property>
|
||||||
<name>yarn.router.submit.interval.time</name>
|
<name>yarn.router.submit.interval.time</name>
|
||||||
<value>10ms</value>
|
<value>10ms</value>
|
||||||
|
@ -187,15 +187,20 @@ public void init(String userName) {
|
|||||||
federationFacade = FederationStateStoreFacade.getInstance();
|
federationFacade = FederationStateStoreFacade.getInstance();
|
||||||
rand = new Random(System.currentTimeMillis());
|
rand = new Random(System.currentTimeMillis());
|
||||||
|
|
||||||
int numThreads = getConf().getInt(
|
int numMinThreads = getNumMinThreads(getConf());
|
||||||
YarnConfiguration.ROUTER_USER_CLIENT_THREADS_SIZE,
|
|
||||||
YarnConfiguration.DEFAULT_ROUTER_USER_CLIENT_THREADS_SIZE);
|
int numMaxThreads = getNumMaxThreads(getConf());
|
||||||
|
|
||||||
|
long keepAliveTime = getConf().getTimeDuration(
|
||||||
|
YarnConfiguration.ROUTER_USER_CLIENT_THREAD_POOL_KEEP_ALIVE_TIME,
|
||||||
|
YarnConfiguration.DEFAULT_ROUTER_USER_CLIENT_THREAD_POOL_KEEP_ALIVE_TIME, TimeUnit.SECONDS);
|
||||||
|
|
||||||
ThreadFactory threadFactory = new ThreadFactoryBuilder()
|
ThreadFactory threadFactory = new ThreadFactoryBuilder()
|
||||||
.setNameFormat("RPC Router Client-" + userName + "-%d ").build();
|
.setNameFormat("RPC Router Client-" + userName + "-%d ").build();
|
||||||
|
|
||||||
BlockingQueue workQueue = new LinkedBlockingQueue<>();
|
BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>();
|
||||||
this.executorService = new ThreadPoolExecutor(numThreads, numThreads,
|
this.executorService = new ThreadPoolExecutor(numMinThreads, numMaxThreads,
|
||||||
0L, TimeUnit.MILLISECONDS, workQueue, threadFactory);
|
keepAliveTime, TimeUnit.MILLISECONDS, workQueue, threadFactory);
|
||||||
|
|
||||||
final Configuration conf = this.getConf();
|
final Configuration conf = this.getConf();
|
||||||
|
|
||||||
@ -1949,6 +1954,46 @@ private void updateReservationHomeSubCluster(SubClusterId subClusterId,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected int getNumMinThreads(Configuration conf) {
|
||||||
|
|
||||||
|
String threadSize = conf.get(YarnConfiguration.ROUTER_USER_CLIENT_THREADS_SIZE);
|
||||||
|
|
||||||
|
// If the user configures YarnConfiguration.ROUTER_USER_CLIENT_THREADS_SIZE,
|
||||||
|
// we will still get the number of threads from this configuration.
|
||||||
|
if (StringUtils.isNotBlank(threadSize)) {
|
||||||
|
LOG.warn("{} is a deprecated property, " +
|
||||||
|
"please remove it, use {} to configure the minimum number of thread pool.",
|
||||||
|
YarnConfiguration.ROUTER_USER_CLIENT_THREADS_SIZE,
|
||||||
|
YarnConfiguration.ROUTER_USER_CLIENT_THREAD_POOL_MINIMUM_POOL_SIZE);
|
||||||
|
return Integer.parseInt(threadSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
int numMinThreads = conf.getInt(
|
||||||
|
YarnConfiguration.ROUTER_USER_CLIENT_THREAD_POOL_MINIMUM_POOL_SIZE,
|
||||||
|
YarnConfiguration.DEFAULT_ROUTER_USER_CLIENT_THREAD_POOL_MINIMUM_POOL_SIZE);
|
||||||
|
return numMinThreads;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getNumMaxThreads(Configuration conf) {
|
||||||
|
|
||||||
|
String threadSize = conf.get(YarnConfiguration.ROUTER_USER_CLIENT_THREADS_SIZE);
|
||||||
|
|
||||||
|
// If the user configures YarnConfiguration.ROUTER_USER_CLIENT_THREADS_SIZE,
|
||||||
|
// we will still get the number of threads from this configuration.
|
||||||
|
if (StringUtils.isNotBlank(threadSize)) {
|
||||||
|
LOG.warn("{} is a deprecated property, " +
|
||||||
|
"please remove it, use {} to configure the maximum number of thread pool.",
|
||||||
|
YarnConfiguration.ROUTER_USER_CLIENT_THREADS_SIZE,
|
||||||
|
YarnConfiguration.ROUTER_USER_CLIENT_THREAD_POOL_MAXIMUM_POOL_SIZE);
|
||||||
|
return Integer.parseInt(threadSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
int numMaxThreads = conf.getInt(
|
||||||
|
YarnConfiguration.ROUTER_USER_CLIENT_THREAD_POOL_MAXIMUM_POOL_SIZE,
|
||||||
|
YarnConfiguration.DEFAULT_ROUTER_USER_CLIENT_THREAD_POOL_MAXIMUM_POOL_SIZE);
|
||||||
|
return numMaxThreads;
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void setNumSubmitRetries(int numSubmitRetries) {
|
public void setNumSubmitRetries(int numSubmitRetries) {
|
||||||
this.numSubmitRetries = numSubmitRetries;
|
this.numSubmitRetries = numSubmitRetries;
|
||||||
|
@ -1520,4 +1520,34 @@ private ReservationDefinition createReservationDefinition(long arrival,
|
|||||||
return ReservationDefinition.newInstance(arrival, deadline,
|
return ReservationDefinition.newInstance(arrival, deadline,
|
||||||
requests, username, "0", Priority.UNDEFINED);
|
requests, username, "0", Priority.UNDEFINED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetNumMinThreads() {
|
||||||
|
// If we don't configure YarnConfiguration.ROUTER_USER_CLIENT_THREAD_POOL_MINIMUM_POOL_SIZE,
|
||||||
|
// we expect to get 5 threads
|
||||||
|
int minThreads = interceptor.getNumMinThreads(this.getConf());
|
||||||
|
Assert.assertEquals(5, minThreads);
|
||||||
|
|
||||||
|
// If we configure YarnConfiguration.ROUTER_USER_CLIENT_THREAD_POOL_MINIMUM_POOL_SIZE,
|
||||||
|
// we expect to get 3 threads
|
||||||
|
this.getConf().unset(YarnConfiguration.ROUTER_USER_CLIENT_THREADS_SIZE);
|
||||||
|
this.getConf().setInt(YarnConfiguration.ROUTER_USER_CLIENT_THREAD_POOL_MINIMUM_POOL_SIZE, 3);
|
||||||
|
int minThreads2 = interceptor.getNumMinThreads(this.getConf());
|
||||||
|
Assert.assertEquals(3, minThreads2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetNumMaxThreads() {
|
||||||
|
// If we don't configure YarnConfiguration.ROUTER_USER_CLIENT_THREAD_POOL_MAXIMUM_POOL_SIZE,
|
||||||
|
// we expect to get 5 threads
|
||||||
|
int minThreads = interceptor.getNumMaxThreads(this.getConf());
|
||||||
|
Assert.assertEquals(5, minThreads);
|
||||||
|
|
||||||
|
// If we configure YarnConfiguration.ROUTER_USER_CLIENT_THREAD_POOL_MAXIMUM_POOL_SIZE,
|
||||||
|
// we expect to get 8 threads
|
||||||
|
this.getConf().unset(YarnConfiguration.ROUTER_USER_CLIENT_THREADS_SIZE);
|
||||||
|
this.getConf().setInt(YarnConfiguration.ROUTER_USER_CLIENT_THREAD_POOL_MAXIMUM_POOL_SIZE, 8);
|
||||||
|
int minThreads2 = interceptor.getNumMaxThreads(this.getConf());
|
||||||
|
Assert.assertEquals(8, minThreads2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user