make cassandra io threads configurable

This commit is contained in:
CJ Cobb
2021-12-02 16:06:03 -05:00
committed by manojsdoshi
parent c663f1f62b
commit 72752b1ee0
2 changed files with 14 additions and 12 deletions

View File

@@ -1150,6 +1150,9 @@
# cluster. Setting this option can help eliminate
# write timeouts and other write errors due to the
# cluster being overloaded.
# io_threads
# Set the number of IO threads used by the
# Cassandra driver. Defaults to 4.
#
# Notes:
# The 'node_db' entry configures the primary, persistent storage.

View File

@@ -249,18 +249,22 @@ public:
cluster, username.c_str(), get(config_, "password").c_str());
}
unsigned int const workers = std::thread::hardware_concurrency();
rc = cass_cluster_set_num_threads_io(cluster, workers);
unsigned int const ioThreads = get<int>(config_, "io_threads", 4);
maxRequestsOutstanding =
get<int>(config_, "max_requests_outstanding", 10000000);
JLOG(j_.info()) << "Configuring Cassandra driver to use " << ioThreads
<< " IO threads. Capping maximum pending requests at "
<< maxRequestsOutstanding;
rc = cass_cluster_set_num_threads_io(cluster, ioThreads);
if (rc != CASS_OK)
{
std::stringstream ss;
ss << "nodestore: Error setting Cassandra io threads to " << workers
<< ", result: " << rc << ", " << cass_error_desc(rc);
ss << "nodestore: Error setting Cassandra io threads to "
<< ioThreads << ", result: " << rc << ", "
<< cass_error_desc(rc);
Throw<std::runtime_error>(ss.str());
}
cass_cluster_set_request_timeout(cluster, 2000);
rc = cass_cluster_set_queue_size_io(
cluster,
maxRequestsOutstanding); // This number needs to scale w/ the
@@ -275,6 +279,7 @@ public:
return;
;
}
cass_cluster_set_request_timeout(cluster, 2000);
std::string certfile = get(config_, "certfile");
if (certfile.size())
@@ -466,12 +471,6 @@ public:
work_.emplace(ioContext_);
ioThread_ = std::thread{[this]() { ioContext_.run(); }};
open_ = true;
if (config_.exists("max_requests_outstanding"))
{
maxRequestsOutstanding =
get<int>(config_, "max_requests_outstanding");
}
}
// Close the connection to the database