Skip to content

[RR2, RFC] Shared FD #579

@alexpts

Description

@alexpts

The file descriptor can be passed from rr process to the worker process.
The worker process will read from socket direct and write to socket direct. Possible it increases performance.

Edited:

  1. RR accepts the connection and receives the client socket file descriptor (FD).
  2. RR doesn't read data from the socket, instead, it sends FD to the worker via the defined in the .rr.yaml transport (sockets or pipes).
  3. In turn, the PHP worker can read and write data directly to the provided FD eliminating proxying via the RR.
    ref: https://man7.org/linux/man-pages/man7/unix.7.html

FD sending:

$result = socket_sendmsg($socket, [
            "iov" => [
                "0", // the message
            ],
            #"name" => [],
            #"controllen" => 0,
            "control" => [
                [
                    "level" => SOL_SOCKET,
                    "type" => SCM_RIGHTS,
                    "data" => [$stream], // where $stream is socket (fd) reveived during stream_socket_accept call
                ],
            ],
        ], 0);

FD receiving from the PHP worker POV:

$temp = [
            "buffer_size" => 1, // waiting for the 1 byte of the data. In case of empty message, share the socket itself.
            "controllen" => socket_cmsg_space(SOL_SOCKET, SCM_RIGHTS, 3)
        ];

 if (socket_recvmsg($socket, $temp, MSG_DONTWAIT)) {
            $message = $temp['iov'][0] ?? '';
            $shareSocket = $temp['control'][0]['data'][0] ?? null; // receive the socket (fd) and operate with it directly avoiding RR proxying
        }

Metadata

Metadata

Assignees

Labels

S-RFCRequest: Request for comments

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions