opt(server): If unspecified, use num_shards == proactor_threads (#1998)

* opt(server): If unspecified, use num_shards == proactor_threads

* Use same config for tests, per Roman's request
This commit is contained in:
Shahar Mike 2023-10-10 14:12:39 +03:00 committed by GitHub
parent cbba6f4e11
commit b1bd2103d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 4 deletions

2
helio

@ -1 +1 @@
Subproject commit 6655f713c7cb6aebc586973ebea6d6bfea06df3c Subproject commit 0950c8fd612bba442caffdabd86d67a32246d461

View File

@ -686,9 +686,10 @@ void Service::Init(util::AcceptServer* acceptor, std::vector<facade::Listener*>
pp_.Await([reg](uint32_t index, ProactorBase* pb) { ServerState::Init(index, reg); }); pp_.Await([reg](uint32_t index, ProactorBase* pb) { ServerState::Init(index, reg); });
uint32_t shard_num = GetFlag(FLAGS_num_shards); uint32_t shard_num = GetFlag(FLAGS_num_shards);
if (shard_num == 0) { if (shard_num == 0 || shard_num > pp_.size()) {
shard_num = pp_.size() > 1 ? pp_.size() - 1 : pp_.size(); LOG_IF(WARNING, shard_num > pp_.size())
} else if (shard_num > pp_.size()) { << "Requested num_shards (" << shard_num << ") is bigger than thread count (" << pp_.size()
<< "), using num_shards=" << pp_.size();
shard_num = pp_.size(); shard_num = pp_.size();
} }

View File

@ -25,6 +25,7 @@ extern "C" {
using namespace std; using namespace std;
ABSL_DECLARE_FLAG(string, dbfilename); ABSL_DECLARE_FLAG(string, dbfilename);
ABSL_DECLARE_FLAG(uint32_t, num_shards);
ABSL_FLAG(bool, force_epoll, false, "If true, uses epoll api instead iouring to run tests"); ABSL_FLAG(bool, force_epoll, false, "If true, uses epoll api instead iouring to run tests");
namespace dfly { namespace dfly {
@ -193,6 +194,10 @@ void BaseFamilyTest::ResetService() {
pp_.reset(fb2::Pool::Epoll(num_threads_)); pp_.reset(fb2::Pool::Epoll(num_threads_));
#endif #endif
// Using a different default than production could expose bugs
if (absl::GetFlag(FLAGS_num_shards) == 0) {
absl::SetFlag(&FLAGS_num_shards, num_threads_ - 1);
}
pp_->Run(); pp_->Run();
service_ = std::make_unique<Service>(pp_.get()); service_ = std::make_unique<Service>(pp_.get());

View File

@ -74,6 +74,14 @@ class DflyInstance:
del self.args["logtostderr"] del self.args["logtostderr"]
self.args["alsologtostderr"] = None self.args["alsologtostderr"] = None
# Run with num_shards = (proactor_threads - 1) if possible, so help expose bugs
if "num_shards" not in self.args:
threads = psutil.cpu_count()
if "proactor_threads" in self.args:
threads = int(self.args["proactor_threads"])
if threads > 1:
self.args["num_shards"] = threads - 1
def __del__(self): def __del__(self):
assert self.proc == None assert self.proc == None