Skip to content

Commit

Permalink
cleanup(bigtable): remove ClientOptions from benchmark (#7233)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbolduc authored Aug 27, 2021
1 parent d8bc8ce commit c155c02
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
21 changes: 14 additions & 7 deletions google/cloud/bigtable/benchmarks/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "google/cloud/bigtable/benchmarks/benchmark.h"
#include "google/cloud/bigtable/benchmarks/random_mutation.h"
#include "google/cloud/bigtable/table_admin.h"
#include "google/cloud/internal/background_threads_impl.h"
#include "google/cloud/internal/getenv.h"
#include <future>
#include <iomanip>
Expand Down Expand Up @@ -68,20 +69,19 @@ google::cloud::StatusOr<BenchmarkOptions> ParseArgs(

Benchmark::Benchmark(BenchmarkOptions options)
: options_(std::move(options)), key_width_(KeyWidth()) {
auto opts = Options{}.set<GrpcNumChannelsOption>(options_.thread_count);
opts_.set<GrpcNumChannelsOption>(options_.thread_count);
if (options_.use_embedded_server) {
server_ = CreateEmbeddedServer();
std::string address = server_->address();
std::cout << "Running embedded Cloud Bigtable server at " << address
<< "\n";
server_thread_ = std::thread([this]() { server_->Wait(); });

opts.set<GrpcCredentialOption>(grpc::InsecureChannelCredentials())
opts_.set<GrpcCredentialOption>(grpc::InsecureChannelCredentials())
.set<DataEndpointOption>(address)
.set<AdminEndpointOption>(address)
.set<InstanceAdminEndpointOption>(address);
}
client_options_ = ClientOptions(std::move(opts));
}

Benchmark::~Benchmark() {
Expand All @@ -98,7 +98,7 @@ Benchmark::~Benchmark() {
std::string Benchmark::CreateTable() {
// Create the table, with an initial split.
bigtable::TableAdmin admin(
bigtable::CreateDefaultAdminClient(options_.project_id, client_options_),
bigtable::MakeAdminClient(options_.project_id, opts_),
options_.instance_id);

std::vector<std::string> splits{"user0", "user1", "user2", "user3", "user4",
Expand All @@ -112,7 +112,7 @@ std::string Benchmark::CreateTable() {

void Benchmark::DeleteTable() {
bigtable::TableAdmin admin(
bigtable::CreateDefaultAdminClient(options_.project_id, client_options_),
bigtable::MakeAdminClient(options_.project_id, opts_),
options_.instance_id);
auto status = admin.DeleteTable(options_.table_id);
if (!status.ok()) {
Expand All @@ -122,8 +122,8 @@ void Benchmark::DeleteTable() {
}

std::shared_ptr<bigtable::DataClient> Benchmark::MakeDataClient() {
return bigtable::CreateDefaultDataClient(
options_.project_id, options_.instance_id, client_options_);
return bigtable::MakeDataClient(options_.project_id, options_.instance_id,
opts_);
}

google::cloud::StatusOr<BenchmarkResult> Benchmark::PopulateTable() {
Expand Down Expand Up @@ -289,6 +289,13 @@ int Benchmark::read_rows_count() const {
return server_->read_rows_count();
}

void Benchmark::DisableBackgroundThreads(CompletionQueue& cq) {
opts_.set<GrpcBackgroundThreadsFactoryOption>([&cq] {
return absl::make_unique<
google::cloud::internal::CustomerSuppliedBackgroundThreads>(cq);
});
}

google::cloud::StatusOr<BenchmarkResult> Benchmark::PopulateTableShard(
bigtable::Table& table, std::int64_t begin, std::int64_t end) const {
auto start = std::chrono::steady_clock::now();
Expand Down
5 changes: 2 additions & 3 deletions google/cloud/bigtable/benchmarks/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ class Benchmark {
int read_rows_count() const;
//@}

/// Return a mutable reference to client options.
ClientOptions& ClientOptionsRef() { return client_options_; }
void DisableBackgroundThreads(CompletionQueue& cq);

private:
/// Populate the table rows in the range [@p begin, @p end)
Expand All @@ -135,7 +134,7 @@ class Benchmark {

BenchmarkOptions options_;
int key_width_;
bigtable::ClientOptions client_options_;
Options opts_;
std::unique_ptr<EmbeddedServer> server_;
std::thread server_thread_;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ int main(int argc, char* argv[]) {

Benchmark benchmark(*options);
google::cloud::CompletionQueue cq;
benchmark.ClientOptionsRef().DisableBackgroundThreads(cq);
benchmark.DisableBackgroundThreads(cq);

// Create and populate the table for the benchmark.
benchmark.CreateTable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "google/cloud/bigtable/testing/embedded_server_test_fixture.h"
#include "google/cloud/grpc_error_delegate.h"
#include "google/cloud/internal/build_info.h"
#include "google/cloud/internal/user_agent_prefix.h"
#include <thread>

namespace google {
Expand Down Expand Up @@ -48,7 +49,8 @@ void EmbeddedServerTestFixture::SetUp() {
StartServer();

grpc::ChannelArguments channel_arguments;
channel_arguments.SetUserAgentPrefix(ClientOptions::UserAgentPrefix());
channel_arguments.SetUserAgentPrefix(
google::cloud::internal::UserAgentPrefix());
std::string project_id = kProjectId;
std::string instance_id = kInstanceId;
std::string table_id = kTableId;
Expand Down

0 comments on commit c155c02

Please sign in to comment.