From 47565e93b58f847622eb8cbf46e93d4ed22b1a6f Mon Sep 17 00:00:00 2001 From: Baodi Shi Date: Mon, 1 Aug 2022 22:46:57 +0800 Subject: [PATCH 1/3] [client][c++] Enable client memory limit controller by default. --- pulsar-client-cpp/.gitignore | 1 + .../include/pulsar/ClientConfiguration.h | 1 + .../include/pulsar/ProducerConfiguration.h | 4 +- .../lib/ClientConfigurationImpl.h | 2 +- .../lib/ProducerConfigurationImpl.h | 4 +- .../tests/ClientConfigurationTest.cc | 38 +++++++++++++++++++ .../tests/ProducerConfigurationTest.cc | 4 +- 7 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 pulsar-client-cpp/tests/ClientConfigurationTest.cc diff --git a/pulsar-client-cpp/.gitignore b/pulsar-client-cpp/.gitignore index 0d8d323e7ff97..271ff9783e81b 100644 --- a/pulsar-client-cpp/.gitignore +++ b/pulsar-client-cpp/.gitignore @@ -50,6 +50,7 @@ lib*.so* # Files generated from templates by CMAKE include/pulsar/Version.h +.cmake # IDE generated files .csettings diff --git a/pulsar-client-cpp/include/pulsar/ClientConfiguration.h b/pulsar-client-cpp/include/pulsar/ClientConfiguration.h index 451ab4ef2180b..983d5d3bedd58 100644 --- a/pulsar-client-cpp/include/pulsar/ClientConfiguration.h +++ b/pulsar-client-cpp/include/pulsar/ClientConfiguration.h @@ -36,6 +36,7 @@ class PULSAR_PUBLIC ClientConfiguration { /** * Configure a limit on the amount of memory that will be allocated by this client instance. * Setting this to 0 will disable the limit. By default this is disabled. + * default: 64MB, The 64M default can guarantee a high producer throughput. * * @param memoryLimitBytes the memory limit */ diff --git a/pulsar-client-cpp/include/pulsar/ProducerConfiguration.h b/pulsar-client-cpp/include/pulsar/ProducerConfiguration.h index 7c278dd6e9124..78dd57570d953 100644 --- a/pulsar-client-cpp/include/pulsar/ProducerConfiguration.h +++ b/pulsar-client-cpp/include/pulsar/ProducerConfiguration.h @@ -180,7 +180,7 @@ class PULSAR_PUBLIC ProducerConfiguration { * would fail unless blockIfQueueFull is set to true. Use {@link #setBlockIfQueueFull} to change the * blocking behavior. * - * Default: 1000 + * Default: 0, disable the pending messages check. * * @param maxPendingMessages max number of pending messages. * @return @@ -198,7 +198,7 @@ class PULSAR_PUBLIC ProducerConfiguration { * This setting will be used to lower the max pending messages for each partition * ({@link #setMaxPendingMessages(int)}), if the total exceeds the configured value. * - * Default: 50000 + * Default: 0, disable the pending messages across partitions check. * * @param maxPendingMessagesAcrossPartitions */ diff --git a/pulsar-client-cpp/lib/ClientConfigurationImpl.h b/pulsar-client-cpp/lib/ClientConfigurationImpl.h index 887ecf2037851..85c6799ef1b52 100644 --- a/pulsar-client-cpp/lib/ClientConfigurationImpl.h +++ b/pulsar-client-cpp/lib/ClientConfigurationImpl.h @@ -25,7 +25,7 @@ namespace pulsar { struct ClientConfigurationImpl { AuthenticationPtr authenticationPtr{AuthFactory::Disabled()}; - uint64_t memoryLimit{0ull}; + uint64_t memoryLimit{64 * 1024 *1024}; int ioThreads{1}; int operationTimeoutSeconds{30}; int messageListenerThreads{1}; diff --git a/pulsar-client-cpp/lib/ProducerConfigurationImpl.h b/pulsar-client-cpp/lib/ProducerConfigurationImpl.h index 2ac1ebaa5df1a..5a37c6b5cfa78 100644 --- a/pulsar-client-cpp/lib/ProducerConfigurationImpl.h +++ b/pulsar-client-cpp/lib/ProducerConfigurationImpl.h @@ -32,8 +32,8 @@ struct ProducerConfigurationImpl { Optional initialSequenceId; int sendTimeoutMs{30000}; CompressionType compressionType{CompressionNone}; - int maxPendingMessages{1000}; - int maxPendingMessagesAcrossPartitions{50000}; + int maxPendingMessages{0}; + int maxPendingMessagesAcrossPartitions{0}; ProducerConfiguration::PartitionsRoutingMode routingMode{ProducerConfiguration::UseSinglePartition}; MessageRoutingPolicyPtr messageRouter; ProducerConfiguration::HashingScheme hashingScheme{ProducerConfiguration::BoostHash}; diff --git a/pulsar-client-cpp/tests/ClientConfigurationTest.cc b/pulsar-client-cpp/tests/ClientConfigurationTest.cc new file mode 100644 index 0000000000000..c159dcd53197b --- /dev/null +++ b/pulsar-client-cpp/tests/ClientConfigurationTest.cc @@ -0,0 +1,38 @@ +/** +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +#include +#include + +using namespace pulsar; + +TEST(ClientConfigurationTest, testDefaultConfig) { + ClientConfiguration conf; + ASSERT_EQ(conf.getMemoryLimit(), 64 * 1024 * 1024); + ASSERT_EQ(conf.getIOThreads(), 1); + ASSERT_EQ(conf.getOperationTimeoutSeconds(), 30); + ASSERT_EQ(conf.getMessageListenerThreads(), 1); + ASSERT_EQ(conf.getConcurrentLookupRequest(), 50000); + ASSERT_EQ(conf.getLogConfFilePath(), ""); + ASSERT_EQ(conf.isUseTls(), false); + ASSERT_EQ(conf.getTlsTrustCertsFilePath(), ""); + ASSERT_EQ(conf.getStatsIntervalInSeconds(), 600); + ASSERT_EQ(conf.isValidateHostName(), false); + ASSERT_EQ(conf.getPartitionsUpdateInterval(), 60); + ASSERT_EQ(conf.getConnectionTimeout(), 10000); +} \ No newline at end of file diff --git a/pulsar-client-cpp/tests/ProducerConfigurationTest.cc b/pulsar-client-cpp/tests/ProducerConfigurationTest.cc index 5c541295ff966..5e7ec8fa8563f 100644 --- a/pulsar-client-cpp/tests/ProducerConfigurationTest.cc +++ b/pulsar-client-cpp/tests/ProducerConfigurationTest.cc @@ -30,8 +30,8 @@ TEST(ProducerConfigurationTest, testDefaultConfig) { ASSERT_EQ(conf.getSendTimeout(), 30000); ASSERT_EQ(conf.getInitialSequenceId(), -1ll); ASSERT_EQ(conf.getCompressionType(), CompressionType::CompressionNone); - ASSERT_EQ(conf.getMaxPendingMessages(), 1000); - ASSERT_EQ(conf.getMaxPendingMessagesAcrossPartitions(), 50000); + ASSERT_EQ(conf.getMaxPendingMessages(), 0); + ASSERT_EQ(conf.getMaxPendingMessagesAcrossPartitions(), 0); ASSERT_EQ(conf.getPartitionsRoutingMode(), ProducerConfiguration::UseSinglePartition); ASSERT_EQ(conf.getMessageRouterPtr(), MessageRoutingPolicyPtr{}); ASSERT_EQ(conf.getHashingScheme(), ProducerConfiguration::BoostHash); From 7eb1d2897f2ef84e783cf785a4ba70d0281e449d Mon Sep 17 00:00:00 2001 From: Baodi Shi Date: Mon, 1 Aug 2022 22:54:14 +0800 Subject: [PATCH 2/3] change license header --- .../tests/ClientConfigurationTest.cc | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/pulsar-client-cpp/tests/ClientConfigurationTest.cc b/pulsar-client-cpp/tests/ClientConfigurationTest.cc index c159dcd53197b..21f8849365e59 100644 --- a/pulsar-client-cpp/tests/ClientConfigurationTest.cc +++ b/pulsar-client-cpp/tests/ClientConfigurationTest.cc @@ -1,21 +1,21 @@ /** -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you under the Apache License, Version 2.0 (the -* "License"); you may not use this file except in compliance -* with the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ #include #include From bd5934c02c58f00340c82a9c8d05474f54387053 Mon Sep 17 00:00:00 2001 From: Baodi Shi Date: Mon, 1 Aug 2022 23:53:37 +0800 Subject: [PATCH 3/3] code format --- pulsar-client-cpp/lib/ClientConfigurationImpl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pulsar-client-cpp/lib/ClientConfigurationImpl.h b/pulsar-client-cpp/lib/ClientConfigurationImpl.h index 85c6799ef1b52..55fd6e4595255 100644 --- a/pulsar-client-cpp/lib/ClientConfigurationImpl.h +++ b/pulsar-client-cpp/lib/ClientConfigurationImpl.h @@ -25,7 +25,7 @@ namespace pulsar { struct ClientConfigurationImpl { AuthenticationPtr authenticationPtr{AuthFactory::Disabled()}; - uint64_t memoryLimit{64 * 1024 *1024}; + uint64_t memoryLimit{64 * 1024 * 1024}; int ioThreads{1}; int operationTimeoutSeconds{30}; int messageListenerThreads{1};