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

add extra thread pool size option #889

Merged
merged 5 commits into from
Aug 23, 2023
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
2 changes: 1 addition & 1 deletion compiler/pipes/register-kphp-configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void RegisterKphpConfiguration::handle_constant_runtime_options(const ClassMembe
} else if (vk::any_of_equal(*opt_key,
warmup_workers_part_key_, warmup_instance_cache_elements_part_key_, warmup_timeout_sec_key_,
oom_handling_memory_ratio_key_, mysql_db_name_key_, job_workers_shared_memory_distribution_weights_,
thread_pool_ratio_key_)) {
thread_pool_ratio_key_, thread_pool_size_key_)) {
generic_register_simple_option(opt_pair->value(), *opt_key);
} else {
kphp_error(0, fmt_format("Got unexpected option {}::{}['{}']",
Expand Down
1 change: 1 addition & 0 deletions compiler/pipes/register-kphp-configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class RegisterKphpConfiguration final : public SyncPipeF<FunctionPtr> {
const vk::string_view job_workers_shared_memory_distribution_weights_{"--job-workers-shared-memory-distribution-weights"};

const vk::string_view thread_pool_ratio_key_{"--thread-pool-ratio"};
const vk::string_view thread_pool_size_key_{"--thread-pool-size"};
public:
void execute(FunctionPtr function, DataStream<FunctionPtr> &unused_os) final;
void on_finish(DataStream<FunctionPtr> &os) override;
Expand Down
3 changes: 1 addition & 2 deletions runtime/thread-pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


void ThreadPool::init() noexcept {
int thread_pool_size = static_cast<int>(std::ceil(std::thread::hardware_concurrency() * thread_pool_ratio));
if (!is_thread_pool_available() && thread_pool_size > 0) {
/**
* linux does not determinize the thread to which the signal will arrive,
Expand All @@ -27,4 +26,4 @@ void ThreadPool::init() noexcept {
}
}

double thread_pool_ratio = 0;
uint32_t thread_pool_size = 0;
2 changes: 1 addition & 1 deletion runtime/thread-pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ class ThreadPool : vk::not_copyable {
BS::thread_pool * thread_pool_ptr{nullptr};
};

extern double thread_pool_ratio;
extern uint32_t thread_pool_size;
9 changes: 8 additions & 1 deletion server/php-engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2190,7 +2190,13 @@ int main_args_handler(int i, const char *long_option) {
return read_option_to(long_option, 0.0, 5.0, hard_timeout);
}
case 2035: {
return read_option_to(long_option, 0.0, 5.0, thread_pool_ratio);
double thread_pool_ratio = 0.0;
int res = read_option_to(long_option, 0.0, 10.0, thread_pool_ratio);
thread_pool_size = static_cast<int>(std::ceil(std::thread::hardware_concurrency() * thread_pool_ratio));
return res;
}
case 2036: {
return read_option_to(long_option, 0U, 2048U, thread_pool_size);
}
default:
return -1;
Expand Down Expand Up @@ -2300,6 +2306,7 @@ void parse_main_args(int argc, char *argv[]) {
parse_option("oom-handling-memory-ratio", required_argument, 2033, "memory ratio of overall script memory to handle OOM errors (default: 0.00)");
parse_option("hard-time-limit", required_argument, 2034, "time limit for script termination after the main timeout has expired (default: 1 sec). Use 0 to disable");
parse_option("thread-pool-ratio", required_argument, 2035, "the thread pool size ratio of the overall cpu numbers");
parse_option("thread-pool-size", required_argument, 2036, "the total threads num per worker");
parse_engine_options_long(argc, argv, main_args_handler);
parse_main_args_till_option(argc, argv);
// TODO: remove it after successful migration from kphb.readyV2 to kphb.readyV3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class KphpConfiguration {
const DEFAULT_RUNTIME_OPTIONS = [
"--thread-pool-size" => "10",
"--thread-pool-ratio" => "0.42",
];
}
Expand Down