Skip to content

Commit

Permalink
review fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadim Sadokhov committed Jul 19, 2023
1 parent f1e9d07 commit 421a4ba
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion runtime/curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ bool f$curl_setopt_array(curl_easy easy_id, const array<mixed> &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<EasyContext>(easy_id);
if (!easy_context) {
return false;
Expand Down
8 changes: 4 additions & 4 deletions runtime/resumable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -1138,7 +1138,7 @@ static void process_wait_queue_timeout(kphp_event_timer *timer) {
Optional<int64_t> 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);
Expand Down
2 changes: 1 addition & 1 deletion server/php-master.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 10 additions & 11 deletions server/php-worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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<int>(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<int>(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<int>(php_script->state) : -1, conn->status, req_id);
assert(conn->status == conn_wait_net);
return get_timeout();
}
Expand All @@ -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;
Expand Down Expand Up @@ -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<ServerStats>::get().set_running_worker_status();
Expand Down Expand Up @@ -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<ServerStats>::get().set_idle_worker_status();
if (mode == once_worker) {
static int left = run_once_count;
Expand Down

0 comments on commit 421a4ba

Please sign in to comment.