Skip to content

Commit 0fe7edd

Browse files
committed
Make a bounded thread pool the default executor
Each client's default executorCreateFn now creates a PooledThreadExecutor sized to std::thread::hardware_concurrency(), at least one thread, instead of a thread per task. DefaultExecutor is renamed UnboundedExecutor. DefaultExecutor.h keeps a deprecated alias, so existing code compiles with a warning. Executor gains a virtual GetUserAgentName() ("custom" unless overridden; "pooled", "unbounded" and "same-thread" for the SDK's executors), and each request's user agent carries md/executor#<name> right after md/aws-crt, so it follows lang/ like the other additional metadata in the UA 2.0 grammar. Smithy clients create the executor before the user agent and pick it up from the configuration. Legacy clients create it in init(), after the AWSClient base builds the user agent, so init() now calls AWSClient::SetUserAgentExecutor(). The same init() block called executorCreateFn() once to check it and again to keep the result. With a pooled default, that started and joined a full pool on every client construction. It now checks the std::function and fails initialization if the factory is missing or returns null. The change is in the three init templates and the 441 generated legacy clients.
1 parent 4988e7f commit 0fe7edd

467 files changed

Lines changed: 3368 additions & 2765 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "breaking-change",
3+
"category": "aws-cpp-sdk-core",
4+
"contributor": "sbiscigl",
5+
"description": "Each client's default executor is now a PooledThreadExecutor sized to the machine's hardware threads, instead of a new thread for every async call. The thread-per-call executor is renamed UnboundedExecutor, and DefaultExecutor still compiles as a deprecated alias. Set the client configuration's executor to an UnboundedExecutor to keep a thread per call. Each request's user agent now names the executor its client runs on."
6+
}

‎generated/protocol-tests/test-clients/aws-cpp-sdk-ec2-protocol/source/EC2ProtocolClient.cpp‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,15 @@ std::shared_ptr<EC2ProtocolEndpointProviderBase>& EC2ProtocolClient::accessEndpo
143143

144144
void EC2ProtocolClient::init(const EC2Protocol::EC2ProtocolClientConfiguration& config) {
145145
AWSClient::SetServiceClientName("EC2 Protocol");
146-
if (!m_clientConfiguration.executor) {
147-
if (!m_clientConfiguration.configFactories.executorCreateFn()) {
148-
AWS_LOGSTREAM_FATAL(ALLOCATION_TAG, "Failed to initialize client: config is missing Executor or executorCreateFn");
149-
m_isInitialized = false;
150-
return;
151-
}
146+
if (!m_clientConfiguration.executor && m_clientConfiguration.configFactories.executorCreateFn) {
152147
m_clientConfiguration.executor = m_clientConfiguration.configFactories.executorCreateFn();
153148
}
149+
if (!m_clientConfiguration.executor) {
150+
AWS_LOGSTREAM_FATAL(ALLOCATION_TAG, "Failed to initialize client: config is missing Executor or executorCreateFn");
151+
m_isInitialized = false;
152+
return;
153+
}
154+
AWSClient::SetUserAgentExecutor(*m_clientConfiguration.executor);
154155
AWS_CHECK_PTR(SERVICE_NAME, m_endpointProvider);
155156
m_endpointProvider->InitBuiltInParameters(config, "ec2query");
156157
}

‎generated/protocol-tests/test-clients/aws-cpp-sdk-json-protocol/source/JsonProtocolClient.cpp‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,15 @@ std::shared_ptr<JsonProtocolEndpointProviderBase>& JsonProtocolClient::accessEnd
137137

138138
void JsonProtocolClient::init(const JsonProtocol::JsonProtocolClientConfiguration& config) {
139139
AWSClient::SetServiceClientName("Json Protocol");
140-
if (!m_clientConfiguration.executor) {
141-
if (!m_clientConfiguration.configFactories.executorCreateFn()) {
142-
AWS_LOGSTREAM_FATAL(ALLOCATION_TAG, "Failed to initialize client: config is missing Executor or executorCreateFn");
143-
m_isInitialized = false;
144-
return;
145-
}
140+
if (!m_clientConfiguration.executor && m_clientConfiguration.configFactories.executorCreateFn) {
146141
m_clientConfiguration.executor = m_clientConfiguration.configFactories.executorCreateFn();
147142
}
143+
if (!m_clientConfiguration.executor) {
144+
AWS_LOGSTREAM_FATAL(ALLOCATION_TAG, "Failed to initialize client: config is missing Executor or executorCreateFn");
145+
m_isInitialized = false;
146+
return;
147+
}
148+
AWSClient::SetUserAgentExecutor(*m_clientConfiguration.executor);
148149
AWS_CHECK_PTR(SERVICE_NAME, m_endpointProvider);
149150
m_endpointProvider->InitBuiltInParameters(config, "jsonprotocol");
150151
}

‎generated/protocol-tests/test-clients/aws-cpp-sdk-json-rpc-10/source/JSONRPC10Client.cpp‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,15 @@ std::shared_ptr<JSONRPC10EndpointProviderBase>& JSONRPC10Client::accessEndpointP
130130

131131
void JSONRPC10Client::init(const JSONRPC10::JSONRPC10ClientConfiguration& config) {
132132
AWSClient::SetServiceClientName("JSON RPC 10");
133-
if (!m_clientConfiguration.executor) {
134-
if (!m_clientConfiguration.configFactories.executorCreateFn()) {
135-
AWS_LOGSTREAM_FATAL(ALLOCATION_TAG, "Failed to initialize client: config is missing Executor or executorCreateFn");
136-
m_isInitialized = false;
137-
return;
138-
}
133+
if (!m_clientConfiguration.executor && m_clientConfiguration.configFactories.executorCreateFn) {
139134
m_clientConfiguration.executor = m_clientConfiguration.configFactories.executorCreateFn();
140135
}
136+
if (!m_clientConfiguration.executor) {
137+
AWS_LOGSTREAM_FATAL(ALLOCATION_TAG, "Failed to initialize client: config is missing Executor or executorCreateFn");
138+
m_isInitialized = false;
139+
return;
140+
}
141+
AWSClient::SetUserAgentExecutor(*m_clientConfiguration.executor);
141142
AWS_CHECK_PTR(SERVICE_NAME, m_endpointProvider);
142143
m_endpointProvider->InitBuiltInParameters(config, "jsonrpc10");
143144
}

‎generated/protocol-tests/test-clients/aws-cpp-sdk-non-query-compatible-rpcv2-protocol/source/NonQueryCompatibleRpcV2ProtocolClient.cpp‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,15 @@ std::shared_ptr<NonQueryCompatibleRpcV2ProtocolEndpointProviderBase>& NonQueryCo
129129
void NonQueryCompatibleRpcV2ProtocolClient::init(
130130
const NonQueryCompatibleRpcV2Protocol::NonQueryCompatibleRpcV2ProtocolClientConfiguration& config) {
131131
AWSClient::SetServiceClientName("Non Query Compatible RpcV2 Protocol");
132-
if (!m_clientConfiguration.executor) {
133-
if (!m_clientConfiguration.configFactories.executorCreateFn()) {
134-
AWS_LOGSTREAM_FATAL(ALLOCATION_TAG, "Failed to initialize client: config is missing Executor or executorCreateFn");
135-
m_isInitialized = false;
136-
return;
137-
}
132+
if (!m_clientConfiguration.executor && m_clientConfiguration.configFactories.executorCreateFn) {
138133
m_clientConfiguration.executor = m_clientConfiguration.configFactories.executorCreateFn();
139134
}
135+
if (!m_clientConfiguration.executor) {
136+
AWS_LOGSTREAM_FATAL(ALLOCATION_TAG, "Failed to initialize client: config is missing Executor or executorCreateFn");
137+
m_isInitialized = false;
138+
return;
139+
}
140+
AWSClient::SetUserAgentExecutor(*m_clientConfiguration.executor);
140141
AWS_CHECK_PTR(SERVICE_NAME, m_endpointProvider);
141142
m_endpointProvider->InitBuiltInParameters(config, "nonquerycompatiblerpcv2protocol");
142143
}

‎generated/protocol-tests/test-clients/aws-cpp-sdk-protocol-mock/source/ProtocolMockClient.cpp‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,15 @@ std::shared_ptr<ProtocolMockEndpointProviderBase>& ProtocolMockClient::accessEnd
124124

125125
void ProtocolMockClient::init(const ProtocolMock::ProtocolMockClientConfiguration& config) {
126126
AWSClient::SetServiceClientName("Protocol Mock");
127-
if (!m_clientConfiguration.executor) {
128-
if (!m_clientConfiguration.configFactories.executorCreateFn()) {
129-
AWS_LOGSTREAM_FATAL(ALLOCATION_TAG, "Failed to initialize client: config is missing Executor or executorCreateFn");
130-
m_isInitialized = false;
131-
return;
132-
}
127+
if (!m_clientConfiguration.executor && m_clientConfiguration.configFactories.executorCreateFn) {
133128
m_clientConfiguration.executor = m_clientConfiguration.configFactories.executorCreateFn();
134129
}
130+
if (!m_clientConfiguration.executor) {
131+
AWS_LOGSTREAM_FATAL(ALLOCATION_TAG, "Failed to initialize client: config is missing Executor or executorCreateFn");
132+
m_isInitialized = false;
133+
return;
134+
}
135+
AWSClient::SetUserAgentExecutor(*m_clientConfiguration.executor);
135136
AWS_CHECK_PTR(SERVICE_NAME, m_endpointProvider);
136137
m_endpointProvider->InitBuiltInParameters(config, "awscppsdktest");
137138
}

‎generated/protocol-tests/test-clients/aws-cpp-sdk-query-compatible-json-rpc-10/source/QueryCompatibleJSONRPC10Client.cpp‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,15 @@ std::shared_ptr<QueryCompatibleJSONRPC10EndpointProviderBase>& QueryCompatibleJS
128128

129129
void QueryCompatibleJSONRPC10Client::init(const QueryCompatibleJSONRPC10::QueryCompatibleJSONRPC10ClientConfiguration& config) {
130130
AWSClient::SetServiceClientName("Query Compatible JSON RPC 10");
131-
if (!m_clientConfiguration.executor) {
132-
if (!m_clientConfiguration.configFactories.executorCreateFn()) {
133-
AWS_LOGSTREAM_FATAL(ALLOCATION_TAG, "Failed to initialize client: config is missing Executor or executorCreateFn");
134-
m_isInitialized = false;
135-
return;
136-
}
131+
if (!m_clientConfiguration.executor && m_clientConfiguration.configFactories.executorCreateFn) {
137132
m_clientConfiguration.executor = m_clientConfiguration.configFactories.executorCreateFn();
138133
}
134+
if (!m_clientConfiguration.executor) {
135+
AWS_LOGSTREAM_FATAL(ALLOCATION_TAG, "Failed to initialize client: config is missing Executor or executorCreateFn");
136+
m_isInitialized = false;
137+
return;
138+
}
139+
AWSClient::SetUserAgentExecutor(*m_clientConfiguration.executor);
139140
AWS_CHECK_PTR(SERVICE_NAME, m_endpointProvider);
140141
m_endpointProvider->InitBuiltInParameters(config, "querycompatiblejsonrpc10");
141142
}

‎generated/protocol-tests/test-clients/aws-cpp-sdk-query-compatible-rpcv2-protocol/source/QueryCompatibleRpcV2ProtocolClient.cpp‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,15 @@ std::shared_ptr<QueryCompatibleRpcV2ProtocolEndpointProviderBase>& QueryCompatib
128128

129129
void QueryCompatibleRpcV2ProtocolClient::init(const QueryCompatibleRpcV2Protocol::QueryCompatibleRpcV2ProtocolClientConfiguration& config) {
130130
AWSClient::SetServiceClientName("Query Compatible RpcV2 Protocol");
131-
if (!m_clientConfiguration.executor) {
132-
if (!m_clientConfiguration.configFactories.executorCreateFn()) {
133-
AWS_LOGSTREAM_FATAL(ALLOCATION_TAG, "Failed to initialize client: config is missing Executor or executorCreateFn");
134-
m_isInitialized = false;
135-
return;
136-
}
131+
if (!m_clientConfiguration.executor && m_clientConfiguration.configFactories.executorCreateFn) {
137132
m_clientConfiguration.executor = m_clientConfiguration.configFactories.executorCreateFn();
138133
}
134+
if (!m_clientConfiguration.executor) {
135+
AWS_LOGSTREAM_FATAL(ALLOCATION_TAG, "Failed to initialize client: config is missing Executor or executorCreateFn");
136+
m_isInitialized = false;
137+
return;
138+
}
139+
AWSClient::SetUserAgentExecutor(*m_clientConfiguration.executor);
139140
AWS_CHECK_PTR(SERVICE_NAME, m_endpointProvider);
140141
m_endpointProvider->InitBuiltInParameters(config, "querycompatiblerpcv2protocol");
141142
}

‎generated/protocol-tests/test-clients/aws-cpp-sdk-query-protocol/source/QueryProtocolClient.cpp‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,15 @@ std::shared_ptr<QueryProtocolEndpointProviderBase>& QueryProtocolClient::accessE
152152

153153
void QueryProtocolClient::init(const QueryProtocol::QueryProtocolClientConfiguration& config) {
154154
AWSClient::SetServiceClientName("Query Protocol");
155-
if (!m_clientConfiguration.executor) {
156-
if (!m_clientConfiguration.configFactories.executorCreateFn()) {
157-
AWS_LOGSTREAM_FATAL(ALLOCATION_TAG, "Failed to initialize client: config is missing Executor or executorCreateFn");
158-
m_isInitialized = false;
159-
return;
160-
}
155+
if (!m_clientConfiguration.executor && m_clientConfiguration.configFactories.executorCreateFn) {
161156
m_clientConfiguration.executor = m_clientConfiguration.configFactories.executorCreateFn();
162157
}
158+
if (!m_clientConfiguration.executor) {
159+
AWS_LOGSTREAM_FATAL(ALLOCATION_TAG, "Failed to initialize client: config is missing Executor or executorCreateFn");
160+
m_isInitialized = false;
161+
return;
162+
}
163+
AWSClient::SetUserAgentExecutor(*m_clientConfiguration.executor);
163164
AWS_CHECK_PTR(SERVICE_NAME, m_endpointProvider);
164165
m_endpointProvider->InitBuiltInParameters(config, "awsquery");
165166
}

‎generated/protocol-tests/test-clients/aws-cpp-sdk-rest-json-protocol/source/RestJsonProtocolClient.cpp‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,15 @@ std::shared_ptr<RestJsonProtocolEndpointProviderBase>& RestJsonProtocolClient::a
200200

201201
void RestJsonProtocolClient::init(const RestJsonProtocol::RestJsonProtocolClientConfiguration& config) {
202202
AWSClient::SetServiceClientName("Rest Json Protocol");
203-
if (!m_clientConfiguration.executor) {
204-
if (!m_clientConfiguration.configFactories.executorCreateFn()) {
205-
AWS_LOGSTREAM_FATAL(ALLOCATION_TAG, "Failed to initialize client: config is missing Executor or executorCreateFn");
206-
m_isInitialized = false;
207-
return;
208-
}
203+
if (!m_clientConfiguration.executor && m_clientConfiguration.configFactories.executorCreateFn) {
209204
m_clientConfiguration.executor = m_clientConfiguration.configFactories.executorCreateFn();
210205
}
206+
if (!m_clientConfiguration.executor) {
207+
AWS_LOGSTREAM_FATAL(ALLOCATION_TAG, "Failed to initialize client: config is missing Executor or executorCreateFn");
208+
m_isInitialized = false;
209+
return;
210+
}
211+
AWSClient::SetUserAgentExecutor(*m_clientConfiguration.executor);
211212
AWS_CHECK_PTR(SERVICE_NAME, m_endpointProvider);
212213
m_endpointProvider->InitBuiltInParameters(config, "restjson");
213214
}

0 commit comments

Comments
 (0)