Skip to content

Improve auto WriteStrategy with writev heuristic #2910

Open
@seanmonstar

Description

@seanmonstar

The default write strategy for HTTP/1 in hyper is to automatically to chose the "best" option. Currently, it simply determines the best based on if AsyncWrite::is_write_vectored(). However, depending on if the response bodies are usually big or usually small, flatten or queue might be better.

The suggested improvement here is:

  • Determine a best-guess size for when bodies smaller than N should prefer Flatten. Make it a constant and document how the number was determined.
  • In proto/h1/io.rs:
    • Add an Auto variant to WriteStrategy, and default to it. If the user has specified a strategy, the default will be overridden already.
      • If the underlying IO doesn't support vectored writes, set the strategy to Flatten.
    • In WriteBuf::buffer(), if the strategy is Auto, check if the buffer size is less than the defined constant. If it is smaller, then change the strategy to Flatten, otherwise change it to Queue.

There's no need for any public API changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-http1Area: HTTP/1 specific.C-performanceCategory: performance. This is making existing behavior go faster.E-mediumEffort: medium. Some knowledge of how hyper internal works would be useful.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions