From 421a4ba370f31ebd678b1ce2eb309e7e55dfb427 Mon Sep 17 00:00:00 2001 From: Vadim Sadokhov Date: Tue, 18 Jul 2023 18:06:40 +0300 Subject: [PATCH] review fix #2 --- runtime/curl.cpp | 2 +- runtime/resumable.cpp | 8 ++++---- server/php-master.cpp | 2 +- server/php-worker.cpp | 21 ++++++++++----------- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/runtime/curl.cpp b/runtime/curl.cpp index 382d0003d9..645a501f0f 100644 --- a/runtime/curl.cpp +++ b/runtime/curl.cpp @@ -662,7 +662,7 @@ bool f$curl_setopt_array(curl_easy easy_id, const array &options) noexcep } mixed f$curl_exec(curl_easy easy_id) noexcept { - constexpr double long_curl_query = 2 * 10e-2; // 0.2 sec + constexpr double long_curl_query = 1 * 10e-2; // 0.1 sec auto *easy_context = get_context(easy_id); if (!easy_context) { return false; diff --git a/runtime/resumable.cpp b/runtime/resumable.cpp index fea0c06dcc..4af069ce2a 100644 --- a/runtime/resumable.cpp +++ b/runtime/resumable.cpp @@ -329,7 +329,7 @@ Resumable *get_started_resumable(int64_t resumable_id) { static void add_resumable_to_queue(int64_t resumable_id, forked_resumable_info *resumable) { int64_t queue_id = resumable->queue_id; wait_queue *q = get_wait_queue(queue_id); - tvkprintf(resumable, 1, "Push resumable %" PRIi64 " to queue %" PRIi64 "(%" PRIi64 ", %" PRIi64 ", %" PRIi32 ") at %.6lf\n", + tvkprintf(resumable, 2, "Push resumable %" PRIi64 " to queue %" PRIi64 "(%" PRIi64 ", %" PRIi64 ", %" PRIi32 ") at %.6lf\n", resumable_id, resumable->queue_id, q->resumable_id, q->first_finished_function, q->left_functions, (update_precise_now(), get_precise_now())); resumable->queue_id = q->first_finished_function; @@ -555,7 +555,7 @@ void run_scheduler(double timeout) __attribute__((section("run_scheduler_section static int64_t scheduled_resumable_id = 0; void run_scheduler(double dead_line_time) { - tvkprintf(resumable, 1, "Run scheduler %" PRIu32 "\n", finished_resumables_count); + tvkprintf(resumable, 2, "Run scheduler %" PRIu32 "\n", finished_resumables_count); int32_t left_resumables = 1000; bool force_run_next = false; while (resumable_has_finished() && --left_resumables >= 0) { @@ -922,7 +922,7 @@ static int64_t wait_queue_push(int64_t queue_id, int64_t resumable_id) { if (resumable->queue_id == 0) { resumable->queue_id = queue_id; - tvkprintf(resumable, 1, "Link resumable %" PRIi64 " with queue %" PRIi64 " at %.6lf\n", + tvkprintf(resumable, 2, "Link resumable %" PRIi64 " with queue %" PRIi64 " at %.6lf\n", resumable_id, queue_id, (update_precise_now(), get_precise_now())); q->left_functions++; } else { @@ -1138,7 +1138,7 @@ static void process_wait_queue_timeout(kphp_event_timer *timer) { Optional f$wait_queue_next(int64_t queue_id, double timeout) { resumable_finished = true; - tvkprintf(resumable, 1, "Waiting for queue %" PRIi64 "\n", queue_id); + tvkprintf(resumable, 2, "Waiting for queue %" PRIi64 "\n", queue_id); if (!is_wait_queue_id(queue_id)) { if (queue_id != -1) { php_warning("Wrong queue_id %" PRIi64 " in function wait_queue_next", queue_id); diff --git a/server/php-master.cpp b/server/php-master.cpp index 795794881c..da080cab2a 100644 --- a/server/php-master.cpp +++ b/server/php-master.cpp @@ -1526,7 +1526,7 @@ WorkerType run_master() { for (int i = 0; i < job_workers_to_kill; ++i) { kill_worker(WorkerType::job_worker); } - for (int i = 0; i < job_workers_to_run && !failed; ++i) { + for (int i = 0; i < job_workers_to_run; ++i) { if (run_worker(WorkerType::job_worker)) { tvkprintf(job_workers, 1, "launched new job worker with pid = %d\n", pid); return WorkerType::job_worker; diff --git a/server/php-worker.cpp b/server/php-worker.cpp index aae5ef366f..47c882d1f5 100644 --- a/server/php-worker.cpp +++ b/server/php-worker.cpp @@ -32,36 +32,42 @@ double PhpWorker::enter_lifecycle() noexcept { } on_wakeup(); - tvkprintf(php_runner, 3, "PHP-worker [state = %d, php-script state = %d, conn status = %d] lifecycle [req_id = %016llx]\n", - state, php_script ? static_cast(php_script->state) : -1, conn->status, req_id); + tvkprintf(php_runner, 3, "PHP-worker enter lifecycle [php-script state = %d, conn status = %d] lifecycle [req_id = %016llx]\n", + php_script ? static_cast(php_script->state) : -1, conn->status, req_id); paused = false; do { switch (state) { case phpq_try_start: + tvkprintf(php_runner, 1, "PHP-worker try start [req_id = %016llx]\n", req_id); state_try_start(); break; case phpq_init_script: + tvkprintf(php_runner, 1, "PHP-worker init PHP-script [req_id = %016llx]\n", req_id); state_init_script(); break; case phpq_run: + tvkprintf(php_runner, 3, "execute PHP-worker [req_id = %016llx]\n", req_id); state_run(); break; case phpq_free_script: + get_utime_monotonic(); + tvkprintf(php_runner, 1, "PHP-worker free PHP-script [query worked = %.5lf] [query waited for start = %.5lf] [req_id = %016llx]\n", precise_now - start_time, start_time - init_time, req_id); state_free_script(); break; case phpq_finish: + tvkprintf(php_runner, 1, "finish PHP-worker [req_id = %016llx]\n", req_id); state_finish(); return 0; } get_utime_monotonic(); } while (!paused); - tvkprintf(php_runner, 3, "PHP-worker [state = %d, php-script state = %d, conn status = %d] return in net reactor [req_id = %016llx]\n", - state, php_script ? static_cast(php_script->state) : -1, conn->status, req_id); + tvkprintf(php_runner, 3, "PHP-worker [php-script state = %d, conn status = %d] return in net reactor [req_id = %016llx]\n", + php_script ? static_cast(php_script->state) : -1, conn->status, req_id); assert(conn->status == conn_wait_net); return get_timeout(); } @@ -88,7 +94,6 @@ void PhpWorker::on_wakeup() noexcept { } void PhpWorker::state_try_start() noexcept { - tvkprintf(php_runner, 1, "PHP-worker try start [req_id = %016llx]\n", req_id); if (terminate_flag) { state = phpq_finish; return; @@ -140,7 +145,6 @@ void PhpWorker::state_init_script() noexcept { get_utime_monotonic(); start_time = precise_now; - tvkprintf(php_runner, 1, "init PHP-script inside PHP-worker [req_id = %016llx]\n", req_id); assert(active_worker == nullptr); active_worker = this; vk::singleton::get().set_running_worker_status(); @@ -389,13 +393,8 @@ void PhpWorker::state_free_script() noexcept { php_worker_run_flag = 0; int f = 0; - get_utime_monotonic(); - double worked = precise_now - start_time; - double waited = start_time - init_time; - assert(active_worker == this); active_worker = nullptr; - tvkprintf(php_runner, 1, "PHP-worker free PHP-script [query worked = %.5lf] [query waited for start = %.5lf] [req_id = %016llx]\n", worked, waited, req_id); vk::singleton::get().set_idle_worker_status(); if (mode == once_worker) { static int left = run_once_count;