Skip to content

Commit 6086312

Browse files
lexprfuncallfacebook-github-bot
authored andcommitted
Allow overriding the default number of Thrift CPU and IO threads
Summary: This allows services to have a default value of their choosing that can still be overriden by a configuration loaded from configerator. Reviewed By: yfeldblum Differential Revision: D77241043 fbshipit-source-id: b2ea77c8303a4e47b6e3385694d6b745c0a909a2
1 parent 56a1065 commit 6086312

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

third-party/thrift/src/thrift/lib/cpp2/server/ThriftServerConfig.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ void ThriftServerConfig::resetNumIOWorkerThreads(AttributeSource source) {
343343
resetStaticAttribute(nWorkers_, source);
344344
}
345345

346+
void ThriftServerConfig::setDefaultNumIOWorkerThreads(
347+
size_t numIOWorkerThreads) {
348+
nWorkers_.setDefault(numIOWorkerThreads);
349+
}
350+
346351
void ThriftServerConfig::setNumCPUWorkerThreads(
347352
size_t numCPUWorkerThreads, AttributeSource source) {
348353
setStaticAttribute(nPoolThreads_, std::move(numCPUWorkerThreads), source);
@@ -352,6 +357,11 @@ void ThriftServerConfig::resetNumCPUWorkerThreads(AttributeSource source) {
352357
resetStaticAttribute(nPoolThreads_, source);
353358
}
354359

360+
void ThriftServerConfig::setDefaultNumCPUWorkerThreads(
361+
size_t numCPUWorkerThreads) {
362+
nPoolThreads_.setDefault(numCPUWorkerThreads);
363+
}
364+
355365
void ThriftServerConfig::setListenBacklog(
356366
int listenBacklog, AttributeSource source) {
357367
setStaticAttribute(listenBacklog_, std::move(listenBacklog), source);

third-party/thrift/src/thrift/lib/cpp2/server/ThriftServerConfig.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ class ThriftServerConfig {
348348
void resetNumIOWorkerThreads(
349349
AttributeSource source = AttributeSource::OVERRIDE);
350350

351+
void setDefaultNumIOWorkerThreads(size_t numIOWorkerThreads);
352+
351353
/**
352354
* Set the number of CPU (pool) threads.
353355
* Won't be effective if using customized ResourcePool.
@@ -363,6 +365,8 @@ class ThriftServerConfig {
363365
void resetNumCPUWorkerThreads(
364366
AttributeSource source = AttributeSource::OVERRIDE);
365367

368+
void setDefaultNumCPUWorkerThreads(size_t numCPUWorkerThreads);
369+
366370
/**
367371
* Set the maximum memory usage by each debug payload.
368372
*/
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <gtest/gtest.h>
18+
19+
#include <thrift/lib/cpp2/server/ThriftServerConfig.h>
20+
21+
using namespace ::testing;
22+
using namespace ::apache::thrift;
23+
24+
TEST(ThriftServerConfigTest, UpdateConfigValueHavingDefault) {
25+
ThriftServerConfig config;
26+
27+
// Zero should be an impossible value
28+
EXPECT_NE(config.getNumIOWorkerThreads(), 0);
29+
30+
config.setDefaultNumIOWorkerThreads(0);
31+
EXPECT_EQ(config.getNumIOWorkerThreads(), 0);
32+
33+
// No baseline value should be present
34+
EXPECT_FALSE(config.getBaselineNumIOWorkerThreads().has_value());
35+
36+
// Set a baseline value and ensure its return by the getter
37+
config.setNumIOWorkerThreads(1, AttributeSource::BASELINE);
38+
ASSERT_TRUE(config.getBaselineNumIOWorkerThreads().has_value());
39+
EXPECT_EQ(config.getNumIOWorkerThreads(), 1);
40+
41+
// Reset the baseline, the getter should return the default
42+
config.resetNumIOWorkerThreads(AttributeSource::BASELINE);
43+
EXPECT_EQ(config.getNumIOWorkerThreads(), 0);
44+
}

0 commit comments

Comments
 (0)