Sudheera
Sudheera

Reputation: 1957

is there transferFrom like functionality in Netty for zero copy?

I'm developing a Http server that processes fairly large size of payloads. Since Netty provide zero-copy, I thought of using zero-coping of the payload using Netty's zero-copy. But it seems Netty only provide transferTo(WritableByteChannel target, long position) but not providing transferFrom() like method to read the content directly in to a file.

Is that just the way it is or are there any workarounds? thanks.

Upvotes: 3

Views: 1518

Answers (2)

Ersin Er
Ersin Er

Reputation: 1045

Netty 4.0.28+ provides splice support when using the native epoll transport. After proper setup, channel.spliceTo(fileDescriptor, 0, data.length); call in your handler will do the trick. Note that this only works on Linux.

Upvotes: 5

trustin
trustin

Reputation: 12351

A Netty channel does not provide an operation that zero-copies the inbound traffic into a file. Alternatively, you can unregister your Netty channel from its event loop, do the zero-copy into the file, and then re-register it to the event loop. However, it is relatively an expensive operation, so its gain might be canceled by unregistration/reregistration overhead.

Upvotes: 2

Related Questions