Use sendfile syscall in ServeFile #381
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.
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
tower_http::services::ServeFile
The text was updated successfully, but these errors were encountered: