php / php-src

The PHP Interpreter
https://www.php.net
Other
38.14k stars 7.74k forks source link

io_uring for stream_copy_to_stream #8013

Open tsukasagenesis opened 2 years ago

tsukasagenesis commented 2 years ago

Description

Hello,

It would be really nice to implement io_uring like here https://lwn.net/Articles/879724/ (talked in hn on https://news.ycombinator.com/item?id=30144652) to get stream_copy_to_stream() really performant. example code here : https://lwn.net/ml/linux-kernel/af0d6b3e-85d0-9b61-4acd-5eef1375f934@gmail.com/ It would help a lot of stream proxy in php to be handled directly in the kernel, and increase drastically the performance.

From many test, stream_copy_to_stream() is sadly "slow" because it didn't use any trick, like sendfile() or 0copy, but instead is just a warper for a classic read/write loop, no gain in performance.

arnaud-lb commented 2 years ago

Hello

A first step could be to make a PoC to demonstrate the speed boost.

stream_copy_to_stream is implemented here: https://github.com/php/php-src/blob/php-8.1.4/main/streams/streams.c#L1540

gnat commented 1 year ago

Related benchmarks using io_uring over on ASP: https://ndportmann.com/io_uring-preview-release/

arnaud-lb commented 1 year ago

If I understand correctly, this is benchmarking an ASP async framework with various I/O adapters, including an io_uring one?

There are a few async frameworks in PHP, like https://amphp.org/ or https://reactphp.org/. It would be worth trying to implement an io_uring event loop for these.

staabm commented 1 year ago

I just learned that windows has an io_uring equivalent named IoRing - I will leave it here in case its useful

https://github.com/oven-sh/bun/issues/43#issuecomment-1605693525