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

feat: upgrade to Netty 4.2.0.Beta1 #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[versions]
kotlin = "1.9.23"
netty = "4.1.109.Final"
netty-iouring = "0.0.25.Final"
netty = "4.2.0.Beta1"
junit = "5.10.2"
jmh = "0.4.10"
inlinelogger = "1.0.6"
Expand All @@ -21,7 +20,7 @@ netty-handler = { module = "io.netty:netty-handler" }
netty-native-epoll = { module = "io.netty:netty-transport-native-epoll" }
netty-native-kqueue = { module = "io.netty:netty-transport-native-kqueue" }
netty-native-macos-dns-resolver = { module = "io.netty:netty-resolver-dns-native-macos" }
netty-incubator-iouring = { module = "io.netty.incubator:netty-incubator-transport-native-io_uring", version.ref = "netty-iouring" }
netty-iouring = { module = "io.netty:netty-transport-native-io_uring", version.ref = "netty" }
junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" }
junit-api = { module = "org.junit.jupiter:junit-jupiter-api" }
junit-engine = { module = "org.junit.jupiter:junit-jupiter-engine" }
Expand Down
4 changes: 2 additions & 2 deletions protocol/osrs-221/osrs-221-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dependencies {
implementation(rootProject.libs.netty.handler)
implementation(rootProject.libs.netty.native.epoll)
implementation(rootProject.libs.netty.native.kqueue)
implementation(rootProject.libs.netty.incubator.iouring)
implementation(rootProject.libs.netty.iouring)
implementation(rootProject.libs.netty.native.macos.dns.resolver)
val epollClassifiers = listOf("linux-aarch_64", "linux-x86_64", "linux-riscv64")
val kqueueClassifiers = listOf("osx-x86_64")
Expand All @@ -17,7 +17,7 @@ dependencies {
implementation(variantOf(rootProject.libs.netty.native.kqueue) { classifier(classifier) })
}
for (classifier in iouringClassifiers) {
implementation(variantOf(rootProject.libs.netty.incubator.iouring) { classifier(classifier) })
implementation(variantOf(rootProject.libs.netty.iouring) { classifier(classifier) })
}
implementation(rootProject.libs.inline.logger)
api(projects.protocol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import io.netty.bootstrap.ServerBootstrap
import io.netty.buffer.ByteBufAllocator
import io.netty.channel.ChannelOption
import io.netty.channel.EventLoopGroup
import io.netty.channel.IoHandlerFactory
import io.netty.channel.MultiThreadIoEventLoopGroup
import io.netty.channel.WriteBufferWaterMark
import io.netty.channel.epoll.Epoll
import io.netty.channel.epoll.EpollChannelOption
import io.netty.channel.epoll.EpollEventLoopGroup
import io.netty.channel.epoll.EpollMode
import io.netty.channel.epoll.EpollIoHandler
import io.netty.channel.epoll.EpollServerSocketChannel
import io.netty.channel.kqueue.KQueue
import io.netty.channel.kqueue.KQueueEventLoopGroup
import io.netty.channel.kqueue.KQueueIoHandler
import io.netty.channel.kqueue.KQueueServerSocketChannel
import io.netty.channel.nio.NioEventLoopGroup
import io.netty.channel.nio.NioIoHandler
import io.netty.channel.socket.nio.NioServerSocketChannel
import io.netty.incubator.channel.uring.IOUring
import io.netty.incubator.channel.uring.IOUringEventLoopGroup
import io.netty.incubator.channel.uring.IOUringServerSocketChannel
import io.netty.channel.uring.IoUring
import io.netty.channel.uring.IoUringIoHandler
import io.netty.channel.uring.IoUringServerSocketChannel
import net.rsprot.protocol.api.logging.networkLog

/**
Expand All @@ -28,28 +28,29 @@ public class BootstrapFactory(
private val alloc: ByteBufAllocator,
) {
/**
* Creates a parent loop group with a single thread behind it, based on the best
* available event loop group.
* Creates an IO handler factory based on the best available event loop group.
*/
public fun createParentLoopGroup(): EventLoopGroup =
public fun createIoHandlerFactory(): IoHandlerFactory =
when {
IOUring.isAvailable() -> IOUringEventLoopGroup(1)
Epoll.isAvailable() -> EpollEventLoopGroup(1)
KQueue.isAvailable() -> KQueueEventLoopGroup(1)
else -> NioEventLoopGroup(1)
IoUring.isAvailable() -> IoUringIoHandler.newFactory()
Epoll.isAvailable() -> EpollIoHandler.newFactory()
KQueue.isAvailable() -> KQueueIoHandler.newFactory()
else -> NioIoHandler.newFactory()
}

/**
* Creates a parent loop group with a single thread behind it, based on the best
* available event loop group.
*/
public fun createParentLoopGroup(nThreads: Int = 1): EventLoopGroup =
MultiThreadIoEventLoopGroup(nThreads, createIoHandlerFactory())

/**
* Creates a child loop group with a number of threads based on availableProcessors * 2,
* which is done at Netty level.
*/
public fun createChildLoopGroup(): EventLoopGroup =
when {
IOUring.isAvailable() -> IOUringEventLoopGroup()
Epoll.isAvailable() -> EpollEventLoopGroup()
KQueue.isAvailable() -> KQueueEventLoopGroup()
else -> NioEventLoopGroup()
}
public fun createChildLoopGroup(nThreads: Int = 0): EventLoopGroup =
MultiThreadIoEventLoopGroup(nThreads, createIoHandlerFactory())

/**
* Creates a server bootstrap using the parent and child event loop groups with
Expand All @@ -60,12 +61,11 @@ public class BootstrapFactory(
childGroup: EventLoopGroup,
): ServerBootstrap {
val channel =
when (parentGroup) {
is IOUringEventLoopGroup -> IOUringServerSocketChannel::class.java
is EpollEventLoopGroup -> EpollServerSocketChannel::class.java
is KQueueEventLoopGroup -> KQueueServerSocketChannel::class.java
is NioEventLoopGroup -> NioServerSocketChannel::class.java
else -> throw IllegalArgumentException("Unknown EventLoopGroup type")
when {
IoUring.isAvailable() -> IoUringServerSocketChannel::class.java
Epoll.isAvailable() -> EpollServerSocketChannel::class.java
KQueue.isAvailable() -> KQueueServerSocketChannel::class.java
else -> NioServerSocketChannel::class.java
}
networkLog(logger) {
"Bootstrap event loop group: ${parentGroup.javaClass.simpleName}"
Expand All @@ -81,11 +81,6 @@ public class BootstrapFactory(
.childOption(ChannelOption.SO_SNDBUF, 65536)
.childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, 30_000)
.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, WriteBufferWaterMark(524_288, 2_097_152))
.also {
if (parentGroup is EpollEventLoopGroup) {
it.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED)
}
}
}

private companion object {
Expand Down
4 changes: 2 additions & 2 deletions protocol/osrs-222/osrs-222-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dependencies {
implementation(rootProject.libs.netty.handler)
implementation(rootProject.libs.netty.native.epoll)
implementation(rootProject.libs.netty.native.kqueue)
implementation(rootProject.libs.netty.incubator.iouring)
implementation(rootProject.libs.netty.iouring)
implementation(rootProject.libs.netty.native.macos.dns.resolver)
val epollClassifiers = listOf("linux-aarch_64", "linux-x86_64", "linux-riscv64")
val kqueueClassifiers = listOf("osx-x86_64")
Expand All @@ -17,7 +17,7 @@ dependencies {
implementation(variantOf(rootProject.libs.netty.native.kqueue) { classifier(classifier) })
}
for (classifier in iouringClassifiers) {
implementation(variantOf(rootProject.libs.netty.incubator.iouring) { classifier(classifier) })
implementation(variantOf(rootProject.libs.netty.iouring) { classifier(classifier) })
}
implementation(rootProject.libs.inline.logger)
api(projects.protocol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import io.netty.bootstrap.ServerBootstrap
import io.netty.buffer.ByteBufAllocator
import io.netty.channel.ChannelOption
import io.netty.channel.EventLoopGroup
import io.netty.channel.IoHandlerFactory
import io.netty.channel.MultiThreadIoEventLoopGroup
import io.netty.channel.WriteBufferWaterMark
import io.netty.channel.epoll.Epoll
import io.netty.channel.epoll.EpollChannelOption
import io.netty.channel.epoll.EpollEventLoopGroup
import io.netty.channel.epoll.EpollMode
import io.netty.channel.epoll.EpollIoHandler
import io.netty.channel.epoll.EpollServerSocketChannel
import io.netty.channel.kqueue.KQueue
import io.netty.channel.kqueue.KQueueEventLoopGroup
import io.netty.channel.kqueue.KQueueIoHandler
import io.netty.channel.kqueue.KQueueServerSocketChannel
import io.netty.channel.nio.NioEventLoopGroup
import io.netty.channel.nio.NioIoHandler
import io.netty.channel.socket.nio.NioServerSocketChannel
import io.netty.incubator.channel.uring.IOUring
import io.netty.incubator.channel.uring.IOUringEventLoopGroup
import io.netty.incubator.channel.uring.IOUringServerSocketChannel
import io.netty.channel.uring.IoUring
import io.netty.channel.uring.IoUringIoHandler
import io.netty.channel.uring.IoUringServerSocketChannel
import net.rsprot.protocol.api.logging.networkLog

/**
Expand All @@ -28,28 +28,29 @@ public class BootstrapFactory(
private val alloc: ByteBufAllocator,
) {
/**
* Creates a parent loop group with a single thread behind it, based on the best
* available event loop group.
* Creates an IO handler factory based on the best available event loop group.
*/
public fun createParentLoopGroup(): EventLoopGroup =
public fun createIoHandlerFactory(): IoHandlerFactory =
when {
IOUring.isAvailable() -> IOUringEventLoopGroup(1)
Epoll.isAvailable() -> EpollEventLoopGroup(1)
KQueue.isAvailable() -> KQueueEventLoopGroup(1)
else -> NioEventLoopGroup(1)
IoUring.isAvailable() -> IoUringIoHandler.newFactory()
Epoll.isAvailable() -> EpollIoHandler.newFactory()
KQueue.isAvailable() -> KQueueIoHandler.newFactory()
else -> NioIoHandler.newFactory()
}

/**
* Creates a parent loop group with a single thread behind it, based on the best
* available event loop group.
*/
public fun createParentLoopGroup(nThreads: Int = 1): EventLoopGroup =
MultiThreadIoEventLoopGroup(nThreads, createIoHandlerFactory())

/**
* Creates a child loop group with a number of threads based on availableProcessors * 2,
* which is done at Netty level.
*/
public fun createChildLoopGroup(): EventLoopGroup =
when {
IOUring.isAvailable() -> IOUringEventLoopGroup()
Epoll.isAvailable() -> EpollEventLoopGroup()
KQueue.isAvailable() -> KQueueEventLoopGroup()
else -> NioEventLoopGroup()
}
public fun createChildLoopGroup(nThreads: Int = 0): EventLoopGroup =
MultiThreadIoEventLoopGroup(nThreads, createIoHandlerFactory())

/**
* Creates a server bootstrap using the parent and child event loop groups with
Expand All @@ -60,12 +61,11 @@ public class BootstrapFactory(
childGroup: EventLoopGroup,
): ServerBootstrap {
val channel =
when (parentGroup) {
is IOUringEventLoopGroup -> IOUringServerSocketChannel::class.java
is EpollEventLoopGroup -> EpollServerSocketChannel::class.java
is KQueueEventLoopGroup -> KQueueServerSocketChannel::class.java
is NioEventLoopGroup -> NioServerSocketChannel::class.java
else -> throw IllegalArgumentException("Unknown EventLoopGroup type")
when {
IoUring.isAvailable() -> IoUringServerSocketChannel::class.java
Epoll.isAvailable() -> EpollServerSocketChannel::class.java
KQueue.isAvailable() -> KQueueServerSocketChannel::class.java
else -> NioServerSocketChannel::class.java
}
networkLog(logger) {
"Bootstrap event loop group: ${parentGroup.javaClass.simpleName}"
Expand All @@ -81,11 +81,6 @@ public class BootstrapFactory(
.childOption(ChannelOption.SO_SNDBUF, 65536)
.childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, 30_000)
.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, WriteBufferWaterMark(524_288, 2_097_152))
.also {
if (parentGroup is EpollEventLoopGroup) {
it.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED)
}
}
}

private companion object {
Expand Down
4 changes: 2 additions & 2 deletions protocol/osrs-223/osrs-223-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dependencies {
implementation(rootProject.libs.netty.handler)
implementation(rootProject.libs.netty.native.epoll)
implementation(rootProject.libs.netty.native.kqueue)
implementation(rootProject.libs.netty.incubator.iouring)
implementation(rootProject.libs.netty.iouring)
implementation(rootProject.libs.netty.native.macos.dns.resolver)
val epollClassifiers = listOf("linux-aarch_64", "linux-x86_64", "linux-riscv64")
val kqueueClassifiers = listOf("osx-x86_64")
Expand All @@ -17,7 +17,7 @@ dependencies {
implementation(variantOf(rootProject.libs.netty.native.kqueue) { classifier(classifier) })
}
for (classifier in iouringClassifiers) {
implementation(variantOf(rootProject.libs.netty.incubator.iouring) { classifier(classifier) })
implementation(variantOf(rootProject.libs.netty.iouring) { classifier(classifier) })
}
implementation(rootProject.libs.inline.logger)
api(projects.protocol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import io.netty.bootstrap.ServerBootstrap
import io.netty.buffer.ByteBufAllocator
import io.netty.channel.ChannelOption
import io.netty.channel.EventLoopGroup
import io.netty.channel.IoHandlerFactory
import io.netty.channel.MultiThreadIoEventLoopGroup
import io.netty.channel.WriteBufferWaterMark
import io.netty.channel.epoll.Epoll
import io.netty.channel.epoll.EpollChannelOption
import io.netty.channel.epoll.EpollEventLoopGroup
import io.netty.channel.epoll.EpollMode
import io.netty.channel.epoll.EpollIoHandler
import io.netty.channel.epoll.EpollServerSocketChannel
import io.netty.channel.kqueue.KQueue
import io.netty.channel.kqueue.KQueueEventLoopGroup
import io.netty.channel.kqueue.KQueueIoHandler
import io.netty.channel.kqueue.KQueueServerSocketChannel
import io.netty.channel.nio.NioEventLoopGroup
import io.netty.channel.nio.NioIoHandler
import io.netty.channel.socket.nio.NioServerSocketChannel
import io.netty.incubator.channel.uring.IOUring
import io.netty.incubator.channel.uring.IOUringEventLoopGroup
import io.netty.incubator.channel.uring.IOUringServerSocketChannel
import io.netty.channel.uring.IoUring
import io.netty.channel.uring.IoUringIoHandler
import io.netty.channel.uring.IoUringServerSocketChannel
import net.rsprot.protocol.api.logging.networkLog

/**
Expand All @@ -28,28 +28,29 @@ public class BootstrapFactory(
private val alloc: ByteBufAllocator,
) {
/**
* Creates a parent loop group with a single thread behind it, based on the best
* available event loop group.
* Creates an IO handler factory based on the best available event loop group.
*/
public fun createParentLoopGroup(): EventLoopGroup =
public fun createIoHandlerFactory(): IoHandlerFactory =
when {
IOUring.isAvailable() -> IOUringEventLoopGroup(1)
Epoll.isAvailable() -> EpollEventLoopGroup(1)
KQueue.isAvailable() -> KQueueEventLoopGroup(1)
else -> NioEventLoopGroup(1)
IoUring.isAvailable() -> IoUringIoHandler.newFactory()
Epoll.isAvailable() -> EpollIoHandler.newFactory()
KQueue.isAvailable() -> KQueueIoHandler.newFactory()
else -> NioIoHandler.newFactory()
}

/**
* Creates a parent loop group with a single thread behind it, based on the best
* available event loop group.
*/
public fun createParentLoopGroup(nThreads: Int = 1): EventLoopGroup =
MultiThreadIoEventLoopGroup(nThreads, createIoHandlerFactory())

/**
* Creates a child loop group with a number of threads based on availableProcessors * 2,
* which is done at Netty level.
*/
public fun createChildLoopGroup(): EventLoopGroup =
when {
IOUring.isAvailable() -> IOUringEventLoopGroup()
Epoll.isAvailable() -> EpollEventLoopGroup()
KQueue.isAvailable() -> KQueueEventLoopGroup()
else -> NioEventLoopGroup()
}
public fun createChildLoopGroup(nThreads: Int = 0): EventLoopGroup =
MultiThreadIoEventLoopGroup(nThreads, createIoHandlerFactory())

/**
* Creates a server bootstrap using the parent and child event loop groups with
Expand All @@ -60,12 +61,11 @@ public class BootstrapFactory(
childGroup: EventLoopGroup,
): ServerBootstrap {
val channel =
when (parentGroup) {
is IOUringEventLoopGroup -> IOUringServerSocketChannel::class.java
is EpollEventLoopGroup -> EpollServerSocketChannel::class.java
is KQueueEventLoopGroup -> KQueueServerSocketChannel::class.java
is NioEventLoopGroup -> NioServerSocketChannel::class.java
else -> throw IllegalArgumentException("Unknown EventLoopGroup type")
when {
IoUring.isAvailable() -> IoUringServerSocketChannel::class.java
Epoll.isAvailable() -> EpollServerSocketChannel::class.java
KQueue.isAvailable() -> KQueueServerSocketChannel::class.java
else -> NioServerSocketChannel::class.java
}
networkLog(logger) {
"Bootstrap event loop group: ${parentGroup.javaClass.simpleName}"
Expand All @@ -81,11 +81,6 @@ public class BootstrapFactory(
.childOption(ChannelOption.SO_SNDBUF, 65536)
.childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, 30_000)
.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, WriteBufferWaterMark(524_288, 2_097_152))
.also {
if (parentGroup is EpollEventLoopGroup) {
it.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED)
}
}
}

private companion object {
Expand Down
4 changes: 2 additions & 2 deletions protocol/osrs-224/osrs-224-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dependencies {
implementation(rootProject.libs.netty.handler)
implementation(rootProject.libs.netty.native.epoll)
implementation(rootProject.libs.netty.native.kqueue)
implementation(rootProject.libs.netty.incubator.iouring)
implementation(rootProject.libs.netty.iouring)
implementation(rootProject.libs.netty.native.macos.dns.resolver)
val epollClassifiers = listOf("linux-aarch_64", "linux-x86_64", "linux-riscv64")
val kqueueClassifiers = listOf("osx-x86_64")
Expand All @@ -17,7 +17,7 @@ dependencies {
implementation(variantOf(rootProject.libs.netty.native.kqueue) { classifier(classifier) })
}
for (classifier in iouringClassifiers) {
implementation(variantOf(rootProject.libs.netty.incubator.iouring) { classifier(classifier) })
implementation(variantOf(rootProject.libs.netty.iouring) { classifier(classifier) })
}
implementation(rootProject.libs.inline.logger)
api(projects.protocol)
Expand Down
Loading