Skip to content

Use sendfile syscall in ServeFile #381

Open
@YuzhongHuangCS

Description

@YuzhongHuangCS

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.E-hardCall for participation: Experience needed to fix: Hard / a lotS-blockedStatus: marked as blocked ❌ on something else such as a PR or other implementation work.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions