Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the size of allocated shared memory is now adjusted according to the … #196

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions include/tateyama/status/resource/bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ class bridge : public framework::resource {
};

public:
static constexpr std::size_t shm_size = 16384;

static constexpr id_type tag = framework::resource_id_status;

static constexpr std::string_view file_prefix = "tsurugidb-"; // NOLINT
Expand Down Expand Up @@ -155,6 +153,14 @@ class bridge : public framework::resource {
std::unique_ptr<tateyama::api::server::database_info> database_info_{};

void set_digest(const std::string& path_string);

static constexpr std::size_t initial_size = 640; // obtained by experiment
static constexpr std::size_t per_size = 8; // obtained by experiment
std::size_t shm_size(std::size_t n) {
std::size_t size = initial_size + (n * per_size); // exact size
size += initial_size / 2; // a little bit of leeway
return ((size / 4096) + 1) * 4096; // round up to the page size
}
};

} // namespace tateyama::status_info::resource
11 changes: 8 additions & 3 deletions src/tateyama/endpoint/ipc/bootstrap/server_wires_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,6 @@ inline void server_wire_container_impl::resultset_wire_container_impl::write_com

class connection_container
{
static constexpr std::size_t request_queue_size = (1<<15); // 32K bytes (tentative) NOLINT

public:
explicit connection_container(std::string_view name, std::size_t n) : name_(name) {
boost::interprocess::shared_memory_object::remove(name_.c_str());
Expand All @@ -602,7 +600,7 @@ class connection_container
unrestricted_permissions.set_unrestricted();

managed_shared_memory_ =
std::make_unique<boost::interprocess::managed_shared_memory>(boost::interprocess::create_only, name_.c_str(), request_queue_size, nullptr, unrestricted_permissions);
std::make_unique<boost::interprocess::managed_shared_memory>(boost::interprocess::create_only, name_.c_str(), request_queue_size(n), nullptr, unrestricted_permissions);
managed_shared_memory_->destroy<tateyama::common::wire::connection_queue>(tateyama::common::wire::connection_queue::name);
connection_queue_ = managed_shared_memory_->construct<tateyama::common::wire::connection_queue>(tateyama::common::wire::connection_queue::name)(n, managed_shared_memory_->get_segment_manager());
}
Expand Down Expand Up @@ -643,6 +641,13 @@ class connection_container
std::unique_ptr<boost::interprocess::managed_shared_memory> managed_shared_memory_{};
tateyama::common::wire::connection_queue* connection_queue_;

static constexpr std::size_t initial_size = 720; // obtained by experiment
static constexpr std::size_t per_size = 112; // obtained by experiment
std::size_t request_queue_size(std::size_t n) {
std::size_t size = initial_size + (n * per_size); // exact size
size += initial_size / 2; // a little bit of leeway
return ((size / 4096) + 1) * 4096; // round up to the page size
}
};

}; // namespace tateyama::common::wire
10 changes: 8 additions & 2 deletions src/tateyama/status/resource/bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ bool bridge::setup(environment& env) {
const auto& conf = env.configuration();
set_digest(conf->get_canonical_path().string());

auto database_name_opt = conf->get_section("ipc_endpoint")->get<std::string>("database_name");
auto* ipc_section = conf->get_section("ipc_endpoint");
auto database_name_opt = ipc_section->get<std::string>("database_name");
if (!database_name_opt) {
LOG(ERROR) << "cannot find database_name at the section in the configuration";
return false;
Expand All @@ -45,13 +46,18 @@ bool bridge::setup(environment& env) {
dbinfo->name(name);
database_info_ = std::move(dbinfo);

auto threads_opt = ipc_section->get<std::size_t>("threads");
if (!threads_opt) {
LOG(ERROR) << "cannot find thread_pool_size at the section in the configuration";
return false;
}
std::string status_file_name{file_prefix};
status_file_name += digest_;
status_file_name += ".stat";
boost::interprocess::shared_memory_object::remove(status_file_name.c_str());
shm_remover_ = std::make_unique<shm_remover>(status_file_name);
try {
segment_ = std::make_unique<boost::interprocess::managed_shared_memory>(boost::interprocess::create_only, status_file_name.c_str(), shm_size);
segment_ = std::make_unique<boost::interprocess::managed_shared_memory>(boost::interprocess::create_only, status_file_name.c_str(), shm_size(threads_opt.value()));
resource_status_memory_ = std::make_unique<resource_status_memory>(*segment_);
resource_status_memory_->set_pid();
resource_status_memory_->set_database_name(name);
Expand Down