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 syscall in ServeFile #381

Open
YuzhongHuangCS opened this issue Jun 28, 2023 · 1 comment
Open

Use sendfile syscall in ServeFile #381

YuzhongHuangCS opened this issue Jun 28, 2023 · 1 comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. E-hard Call for participation: Experience needed to fix: Hard / a lot S-blocked Status: marked as blocked ❌ on something else such as a PR or other implementation work.

Comments

@YuzhongHuangCS
Copy link

YuzhongHuangCS commented Jun 28, 2023

Feature Request

Motivation

Currently, tower_http::services::ServeFile will read content of the file to the memory (in chunks if file is large), then send it to net socket, which involves 2 copies.

Linux/BSD support sendfile system call, which directly transfer data from file descriptor to net socket, with zero copy in user space, and support arbitrary large files.

Proposal

There is a sendfile wrapper available in Rust, but it require direct access to the net socket, which is not exposed in tower or axum framework.

If you could give me hints on how to find/expose the net socket I am happy to implement it myself.

Alternatives

  1. Use current 2 copy implementation in tower_http::services::ServeFile
@jplatte
Copy link
Collaborator

jplatte commented Jun 29, 2023

We can't really do anything here until hyper supports sendfile¹:

This likely also requires changes to the http_body crate.

¹ while tower-http isn't strongly tied to hyper, it's by far the most-used server for serving HTTP services using tower. It would probably not be worth it to implement this in a way that only works for some other server impl, even if there was one supporting sendfile somehow, which I doubt.

@jplatte jplatte added C-feature-request Category: A feature request, i.e: not implemented / a PR. E-hard Call for participation: Experience needed to fix: Hard / a lot S-blocked Status: marked as blocked ❌ on something else such as a PR or other implementation work. labels Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. E-hard Call for participation: Experience needed to fix: Hard / a lot S-blocked Status: marked as blocked ❌ on something else such as a PR or other implementation work.
Projects
None yet
Development

No branches or pull requests

2 participants