Skip to content

Commit dd879e2

Browse files
committed
🎨 优化使用方式
1 parent 6ecb701 commit dd879e2

File tree

6 files changed

+40
-4
lines changed

6 files changed

+40
-4
lines changed

frameworks/Java/today/build.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ configure(allprojects) {
88
group = "cn.taketoday.benchmark"
99

1010
repositories {
11+
mavenLocal()
1112
mavenCentral()
1213
maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" }
1314
}
@@ -57,15 +58,13 @@ application {
5758
"-Xms2G",
5859
"-Xmx2G",
5960
"-XX:+UseNUMA",
60-
"-XX:+UseParallelGC",
61-
"-XX:+AggressiveOpts",
62-
"-Djava.lang.Integer.IntegerCache.high=10000",
63-
"-XX:-StackTraceInThrowable",
6461
"-XX:+UseStringDeduplication",
6562
"-Dinfra.profiles.active=test",
6663
"-Dio.netty.buffer.checkBounds=false",
6764
"-Dio.netty.buffer.checkAccessible=false",
6865
"-Dio.netty.leakDetection.level=disabled",
66+
"-Dio.netty.iouring.iosqeAsyncThreshold=32000",
67+
"-Djava.lang.Integer.IntegerCache.high=10000",
6968
"--add-opens=java.base/java.nio=ALL-UNNAMED",
7069
"--add-opens=java.base/sun.nio.ch=ALL-UNNAMED"
7170
]

frameworks/Java/today/src/main/java/cn/taketoday/benchmark/AppConfig.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@
1111
import infra.jdbc.RepositoryManager;
1212
import infra.persistence.EntityManager;
1313
import infra.stereotype.Component;
14+
import infra.web.server.WebServerFactoryCustomizer;
1415
import infra.web.server.error.SendErrorHandler;
1516
import infra.web.server.support.NettyRequestConfig;
17+
import infra.web.server.support.NettyWebServerFactory;
1618
import io.netty.handler.codec.http.DefaultHttpHeaders;
1719
import io.netty.handler.codec.http.HttpHeaders;
1820
import io.netty.handler.codec.http.HttpHeadersFactory;
1921
import io.netty.handler.codec.http.multipart.DefaultHttpDataFactory;
22+
import io.netty.incubator.channel.uring.IOUring;
23+
import io.netty.incubator.channel.uring.IOUringEventLoopGroup;
24+
import io.netty.incubator.channel.uring.IOUringServerSocketChannel;
2025

2126
import static infra.http.HttpHeaders.DATE_FORMATTER;
2227

@@ -39,10 +44,23 @@ public static EntityManager entityManager(RepositoryManager repositoryManager) {
3944
return repositoryManager.getEntityManager();
4045
}
4146

47+
@Component
48+
public static WebServerFactoryCustomizer<NettyWebServerFactory> factoryWebServerFactoryCustomizer() {
49+
return factory -> {
50+
if (IOUring.isAvailable()) {
51+
IOUringEventLoopGroup loopGroup = new IOUringEventLoopGroup();
52+
factory.setAcceptorGroup(loopGroup);
53+
factory.setWorkerGroup(loopGroup);
54+
factory.setSocketChannel(IOUringServerSocketChannel.class);
55+
}
56+
};
57+
}
58+
4259
@Component
4360
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
4461
public static NettyRequestConfig nettyRequestConfig(SendErrorHandler sendErrorHandler) {
4562
var factory = new DefaultHttpDataFactory(false);
63+
4664
return NettyRequestConfig.forBuilder(false)
4765
.httpDataFactory(factory)
4866
.sendErrorHandler(sendErrorHandler)

frameworks/Java/today/src/main/java/cn/taketoday/benchmark/http/BenchmarkHttpHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public String plaintext() {
5050
return "Hello, World!";
5151
}
5252

53+
@Nullable
5354
@GET("/db")
5455
public World db() {
5556
return entityManager.findById(World.class, nextInt());
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@NonNullApi
2+
@NonNullFields
3+
package cn.taketoday.benchmark.http;
4+
5+
import infra.lang.NonNullApi;
6+
import infra.lang.NonNullFields;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@NonNullApi
2+
@NonNullFields
3+
package cn.taketoday.benchmark.model;
4+
5+
import infra.lang.NonNullApi;
6+
import infra.lang.NonNullFields;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@NonNullApi
2+
@NonNullFields
3+
package cn.taketoday.benchmark;
4+
5+
import infra.lang.NonNullApi;
6+
import infra.lang.NonNullFields;

0 commit comments

Comments
 (0)