Skip to content

Provide support for sending Content.Source via sendfile / FileChannel.transferTo #13392

@kohlschuetter

Description

@kohlschuetter

Jetty version(s)
12.x

Enhancement Description
Currently, it appears that all data provided via Content.Source or Path resource is transferred to the client socked by copying data in userspace (via ByteBuffers).

In many cases, it may be possible to leverage sendfile(2) / FileChannel.transferTo to serve content directly from kernel buffers. This may greatly improve throughput and also reduce CPU usage when transferring lots of data.

We could do the following:

  1. Add an asWritableByteChannel method to Content.Sink, which may or may not return an optimized WritableByteChannel, depending on filters, etc.
  2. Give Content.Source the ability to write to a Content.Sink directly (without forcibly using ContentCopier). Suitable Content.Source implementations may call Content.Sink#asWritableByteChannel and use FileChannel#transferTo(long,long,WritableByteChannel) with the corresponding data.
  3. Optimize the Content.Sink implementation in ServletChannel to return a direct-socket WritableByteChannel whenever possible.
  4. Improve IOResources.PathToSinkCopier as well.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions