Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoids converting from/to byte array from Chunk within UDP ASG single… #927

Merged

Conversation

sbuzzard
Copy link

…ton socket selector thread by introducing a package private analog of the public Packet data type which holds a byte array. The conversion from/to Chunk is done in the socket implementation prior to calling ASG.read or ASG write. More a proposal or query for better solution at this point. This does have the effect, at least in two applications, with eliminating the selector thread as a hot spot under load (one app, the client, creates 20 concurrent UDP connections and writes data at 38.8mbps to the 2nd app, which in turn manipulates the data and outputs it to third UDP destination).

@sbuzzard sbuzzard force-pushed the avoid-chunk-array-creation branch from afa2749 to d5334af Compare August 28, 2017 14:38
Copy link
Member

@mpilquist mpilquist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we change val bytes = Array.ofDim[Byte](readBuffer.remaining) to val bytes = new Array[Byte](readBuffer.remaining), we should get another significant improvement under contention (ofDim uses a class manifest IIRC)

@@ -193,6 +199,10 @@ object AsynchronousSocketGroup {
}

override def write(key: SelectionKey, packet: Packet, timeout: Option[FiniteDuration], cb: Option[Throwable] => Unit): Unit = {
val writerPacket = {
val b = packet.bytes.toBytes
new WriterPacket(packet.remote, ByteBuffer.wrap(if (b.size == b.values.size) b.values else b.values.slice(b.offset, b.size)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using slice, let's use Array.copy instead

…ocket selector thread when doing writes by introducing an ASG private analog of the public Packet data type for the ASG writer which holds a ByteBuffer. The conversion from Chunk is done in the ASG write implementation prior to context switching to selector thread.
@sbuzzard sbuzzard force-pushed the avoid-chunk-array-creation branch from d5334af to ca6e66c Compare August 28, 2017 16:26
@mpilquist mpilquist merged commit 6cddf8b into typelevel:series/0.10 Aug 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants