Skip to content

Commit 8b1cc4e

Browse files
committed
impl(bigtable): simplify adding channels in dynamic channel pool
1 parent 5b7b3c8 commit 8b1cc4e

File tree

3 files changed

+5
-89
lines changed

3 files changed

+5
-89
lines changed

google/cloud/bigtable/internal/dynamic_channel_pool.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -241,22 +241,6 @@ class DynamicChannelPool
241241
return channel;
242242
}
243243

244-
struct ChannelAddVisitor {
245-
std::size_t pool_size;
246-
explicit ChannelAddVisitor(std::size_t pool_size) : pool_size(pool_size) {}
247-
std::size_t operator()(
248-
typename bigtable::experimental::DynamicChannelPoolSizingPolicy::
249-
DiscreteChannels const& c) const {
250-
return c.number;
251-
}
252-
std::size_t operator()(
253-
typename bigtable::experimental::DynamicChannelPoolSizingPolicy::
254-
PercentageOfPoolSize const& c) const {
255-
return static_cast<std::size_t>(
256-
std::floor(static_cast<double>(pool_size) * c.percentage));
257-
}
258-
};
259-
260244
// Determines the number of channels to add and reserves the channel ids to
261245
// be used. Lastly, it calls CompletionQueue::RunAsync with a callback that
262246
// executes AddChannels with the reserved ids.
@@ -271,8 +255,7 @@ class DynamicChannelPool
271255
} else {
272256
num_channels_to_add =
273257
std::min(sizing_policy_.maximum_channel_pool_size - channels_.size(),
274-
absl::visit(ChannelAddVisitor(channels_.size()),
275-
sizing_policy_.channels_to_add_per_resize));
258+
std::size_t(1));
276259
}
277260
num_pending_channels_ += num_channels_to_add;
278261
std::vector<int> new_channel_ids;

google/cloud/bigtable/internal/dynamic_channel_pool_test.cc

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ TEST_F(DynamicChannelPoolTest, ScheduleAddChannelsPoolUndersized) {
371371
}
372372
}
373373

374-
TEST_F(DynamicChannelPoolTest, ScheduleAddChannelsPoolNearMax) {
374+
TEST_F(DynamicChannelPoolTest, ScheduleAddChannelsPoolAtMax) {
375375
auto instance_name =
376376
bigtable::InstanceResource(Project("my-project"), "my-instance")
377377
.FullName();
@@ -386,58 +386,7 @@ TEST_F(DynamicChannelPoolTest, ScheduleAddChannelsPoolNearMax) {
386386
std::make_shared<MockBigtableStub>(), 0));
387387
DynamicChannelPoolSizingPolicy sizing_policy;
388388
sizing_policy.minimum_channel_pool_size = 2;
389-
sizing_policy.maximum_channel_pool_size = 3;
390-
sizing_policy.channels_to_add_per_resize =
391-
DynamicChannelPoolSizingPolicy::DiscreteChannels(3);
392-
393-
MockFunction<StatusOr<std::shared_ptr<ChannelUsage<BigtableStub>>>(
394-
std::uint32_t, std::string const&, StubManager::Priming)>
395-
stub_factory_fn;
396-
397-
// Pool creation should set the pool size increase cooldown timer.
398-
EXPECT_CALL(*mock_cq_impl_, MakeRelativeTimer)
399-
.WillOnce([&](std::chrono::nanoseconds ns) {
400-
EXPECT_THAT(ns.count(),
401-
Eq(std::chrono::nanoseconds(
402-
sizing_policy.pool_size_decrease_cooldown_interval)
403-
.count()));
404-
return make_ready_future(StatusOr(std::chrono::system_clock::now()));
405-
});
406-
407-
auto pool = DynamicChannelPool<BigtableStub>::Create(
408-
instance_name, CompletionQueue(mock_cq_impl_), channels, refresh_state,
409-
stub_factory_fn.AsStdFunction(), sizing_policy);
410-
DynamicChannelPoolTestWrapper wrapper(pool);
411-
412-
EXPECT_CALL(*mock_cq_impl_, RunAsync).Times(1);
413-
auto test_fn = [](std::vector<int> const& new_channel_ids) {
414-
EXPECT_THAT(new_channel_ids, ::testing::ElementsAreArray({2}));
415-
};
416-
417-
{
418-
auto lk = wrapper.CreateLock();
419-
wrapper.ScheduleAddChannels(lk, test_fn);
420-
}
421-
}
422-
423-
TEST_F(DynamicChannelPoolTest, ScheduleAddChannelsPoolNotNearMax) {
424-
auto instance_name =
425-
bigtable::InstanceResource(Project("my-project"), "my-instance")
426-
.FullName();
427-
auto refresh_state = std::make_shared<ConnectionRefreshState>(
428-
fake_cq_impl_, std::chrono::milliseconds(1),
429-
std::chrono::milliseconds(10));
430-
431-
std::vector<std::shared_ptr<ChannelUsage<BigtableStub>>> channels;
432-
channels.push_back(std::make_shared<ChannelUsage<BigtableStub>>(
433-
std::make_shared<MockBigtableStub>(), 0));
434-
channels.push_back(std::make_shared<ChannelUsage<BigtableStub>>(
435-
std::make_shared<MockBigtableStub>(), 0));
436-
DynamicChannelPoolSizingPolicy sizing_policy;
437-
sizing_policy.minimum_channel_pool_size = 2;
438-
sizing_policy.maximum_channel_pool_size = 10;
439-
sizing_policy.channels_to_add_per_resize =
440-
DynamicChannelPoolSizingPolicy::DiscreteChannels(3);
389+
sizing_policy.maximum_channel_pool_size = 2;
441390

442391
MockFunction<StatusOr<std::shared_ptr<ChannelUsage<BigtableStub>>>(
443392
std::uint32_t, std::string const&, StubManager::Priming)>
@@ -460,7 +409,7 @@ TEST_F(DynamicChannelPoolTest, ScheduleAddChannelsPoolNotNearMax) {
460409

461410
EXPECT_CALL(*mock_cq_impl_, RunAsync).Times(1);
462411
auto test_fn = [](std::vector<int> const& new_channel_ids) {
463-
EXPECT_THAT(new_channel_ids, ::testing::ElementsAreArray({2, 3, 4}));
412+
EXPECT_THAT(new_channel_ids, IsEmpty());
464413
};
465414

466415
{
@@ -469,7 +418,7 @@ TEST_F(DynamicChannelPoolTest, ScheduleAddChannelsPoolNotNearMax) {
469418
}
470419
}
471420

472-
TEST_F(DynamicChannelPoolTest, ScheduleAddChannelsPoolNotNearMaxPercentage) {
421+
TEST_F(DynamicChannelPoolTest, ScheduleAddChannelsPoolBelowMax) {
473422
auto instance_name =
474423
bigtable::InstanceResource(Project("my-project"), "my-instance")
475424
.FullName();
@@ -485,8 +434,6 @@ TEST_F(DynamicChannelPoolTest, ScheduleAddChannelsPoolNotNearMaxPercentage) {
485434
DynamicChannelPoolSizingPolicy sizing_policy;
486435
sizing_policy.minimum_channel_pool_size = 2;
487436
sizing_policy.maximum_channel_pool_size = 10;
488-
sizing_policy.channels_to_add_per_resize =
489-
DynamicChannelPoolSizingPolicy::PercentageOfPoolSize(0.5);
490437

491438
MockFunction<StatusOr<std::shared_ptr<ChannelUsage<BigtableStub>>>(
492439
std::uint32_t, std::string const&, StubManager::Priming)>

google/cloud/bigtable/options.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@
4242
#include "google/cloud/bigtable/instance_resource.h"
4343
#include "google/cloud/bigtable/internal/endpoint_options.h"
4444
#include "google/cloud/bigtable/retry_policy.h"
45-
#include "google/cloud/bigtable/rpc_retry_policy.h"
4645
#include "google/cloud/bigtable/version.h"
4746
#include "google/cloud/backoff_policy.h"
4847
#include "google/cloud/options.h"
4948
#include <chrono>
5049
#include <string>
51-
#include <variant>
5250

5351
namespace google {
5452
namespace cloud {
@@ -202,18 +200,6 @@ struct DynamicChannelPoolSizingPolicy {
202200
std::chrono::milliseconds pool_size_decrease_cooldown_interval =
203201
std::chrono::seconds(120);
204202

205-
struct DiscreteChannels {
206-
explicit DiscreteChannels(int number = 0) : number(number) {}
207-
int number;
208-
};
209-
struct PercentageOfPoolSize {
210-
explicit PercentageOfPoolSize(double percentage = 0.0)
211-
: percentage(percentage) {}
212-
double percentage;
213-
};
214-
std::variant<DiscreteChannels, PercentageOfPoolSize>
215-
channels_to_add_per_resize = DiscreteChannels{1};
216-
217203
// If the average number of outstanding RPCs is below this threshold,
218204
// the pool size will be decreased.
219205
int minimum_average_outstanding_rpcs_per_channel = 1;

0 commit comments

Comments
 (0)