Skip to content

Optimizations for readers #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Conversation

acogoluegnes
Copy link
Contributor

@acogoluegnes acogoluegnes commented Jul 4, 2025

A couple of optimizations when sending chunks to readers:

  • Change the signature of the sendfile callback. The callback is used in RabbitMQ to send the frame header. The callback expects now a binary result to send it along the chunk header. This saves a system call and improves performance with small chunks.
  • Try to read the whole chunk with its header if the previous one was small enough. This can avoid using sendfile (and save a syscall) for stream with small chunks.

acogoluegnes added a commit to rabbitmq/rabbitmq-server that referenced this pull request Jul 4, 2025
This saves a system call by sending the frame header and the chunk
header at the same time.

References rabbitmq/osiris#192
acogoluegnes added a commit to rabbitmq/rabbitmq-server that referenced this pull request Jul 23, 2025
This saves a system call by sending the frame header and the chunk
header at the same time.

References rabbitmq/osiris#192
The callback is used in RabbitMQ to send the frame header. This commit
changes the callback to expect a binary result and to send it along the
chunk header. This saves a system call and improves performance with
small chunks.
@acogoluegnes acogoluegnes force-pushed the send-file-improvements branch 4 times, most recently from 5fdaec1 to 09ef637 Compare July 24, 2025 07:14
Reading a chunk header then using the sendfile syscall to send the chunk
data is not optimal for small chunks, as it amounts to 2 system calls
for a small amount of bytes.

This commit uses the size of the last chunk to try to read the whole
chunk when the library reads the chunk header. If the last chunk data
size was under 4096 bytes, the library does not only read the chunk
header, but reads ahead to try to read the whole and thus to save the
sendfile call later.

This optimization should improve the read throughput for streams with
small chunks, e.g. streams with 1-message chunks.
@acogoluegnes acogoluegnes force-pushed the send-file-improvements branch from c5572f0 to bda8f17 Compare July 24, 2025 10:07
acogoluegnes added a commit to rabbitmq/rabbitmq-server that referenced this pull request Jul 24, 2025
This saves a system call by sending the frame header and the chunk
header at the same time.

References rabbitmq/osiris#192
@acogoluegnes acogoluegnes changed the title Update send_file callback to save a system call Optimizations for readers Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant