Skip to content

Improved prefork run-once mode#1532

Open
DrDet wants to merge 5 commits intomasterfrom
dvaksman/improve-run-once-prefork
Open

Improved prefork run-once mode#1532
DrDet wants to merge 5 commits intomasterfrom
dvaksman/improve-run-once-prefork

Conversation

@DrDet
Copy link
Contributor

@DrDet DrDet commented Feb 19, 2026

Main changes:

  • make pipe for dummy self queries nonblocking
  • send dummy self queries to pipe in bathces from event loop instead of straightforward loop at the beginning
  • next batch is sent only if we have nothing to do (no pending scripts)
  • extract the whole logic for invoking dummy self queries in separate class PhpScriptRunOnceInvoker
  • add e2e tests

Before these changes execution suspended infinitely with --once count more than 2720, caused by blocking writing to pipe when its buffer was overflowed.

- don't close write end of the pipe to prevent infinite hanging in the event loop
- send next batch of run once messages only if we don't have running php scripts
@DrDet DrDet added this to the next milestone Feb 19, 2026
@DrDet DrDet requested a review from PetrShumilov February 19, 2026 15:48
@DrDet DrDet self-assigned this Feb 19, 2026
@DrDet DrDet added the runtime Feature related to runtime label Feb 19, 2026
KPHP-CI
KPHP-CI previously approved these changes Feb 24, 2026
Copy link

@KPHP-CI KPHP-CI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic job!

assert(write(write_fd, q, (size_t)qsize) == qsize);
}
if (run_once_mode_enabled) {
run_once_invoker.init(run_once_count);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that worker wouldn't be started "in both modes simultaneously"? For example, if I pass ports option and once

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added extra check that it never happens

epoll_insert_pipe(pipe_for_read, read_fd, &ct_php_rpc_client, &rpc_client_methods);
}

bool PhpScriptRunOnceInvoker::invoke_run_once(int runs_count) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add assert(runs_count > 0) here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually it works correct with zero

}

rpc_client_methods.rpc_ready = nullptr;
epoll_insert_pipe(pipe_for_read, read_fd, &ct_php_rpc_client, &rpc_client_methods);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I see, will be better to check the result of epoll_insert_pipe too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link

@KPHP-CI KPHP-CI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

runtime Feature related to runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants