Skip to content
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

Use sendfile system call on Linux in HTTPServerResponseImpl::sendFile #3277

Closed
carun opened this issue May 21, 2021 · 4 comments
Closed

Use sendfile system call on Linux in HTTPServerResponseImpl::sendFile #3277

carun opened this issue May 21, 2021 · 4 comments

Comments

@carun
Copy link

carun commented May 21, 2021

At the moment, HTTPServerResponseImpl::sendFile uses StreamCopied::copyStream which in turn uses intermediate buffer copies. This is inefficient on Linux as the buffers are copied from user space to user space and again from user space to kernel space.

StreamCopier::copyStream(istr, *_pStream);

istr.read(buffer.begin(), bufferSize);

As the size of the file increases this will become evident as the kernel buffer cache will get filled up pretty quickly and we have to resort to running

$ free -m
              total        used        free      shared  buff/cache   available
Mem:          32115        1859       12880           1       17374       29812
Swap:          3935         167        3768

$ echo 3 | sudo tee /proc/sys/vm/drop_caches
3

$ free -m
              total        used        free      shared  buff/cache   available
Mem:          32115        1866       29841           1         407       29816
Swap:          3935         167        3768

Linux has sendfile system call. This can be used to speed up the sends and also minimize the memory usage of the process and in turn reduce the kernel buffer cache.

@aleks-f
Copy link
Member

aleks-f commented May 21, 2021

It would require exposing the file descriptors, either at the HTTPResponse (from HTTPSession) level, or at the streams layer. Plus reliably detecting if sendfile() is available (since 2.2, so I think practically can be relied on being there for linux).

@obiltschnig obiltschnig self-assigned this May 21, 2021
@github-actions
Copy link

This issue is stale because it has been open for 365 days with no activity.

@github-actions
Copy link

This issue was closed because it has been inactive for 60 days since being marked as stale.

@github-actions
Copy link

This issue was closed because it has been inactive for 60 days since being marked as stale.

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

No branches or pull requests

4 participants