OpenJDK HotSpot
和GraalVM
量身定制的Kubernetes Native Java
框架,基于同类最佳的 Java 库和标准制作而成。Spring Reactive
和Quarkus
在原生镜像方面的差异。指标项 | Spring Boot Native | Quarkus Native | Spring Boot JVM | Quarkus JVM |
---|---|---|---|---|
启动耗时(秒) | 0.244 | 0.104 | 6.156 | 2.230 |
启动内存(MB) | 44.31 | 9.05 | 237.1 | 119.1 |
启动CPU使用率(%) | - | - | 0.22 | 0.26 |
构建镜像大小(MB) | 119.89 | 84.75 | 217.92 | 421.24 |
构建时长(秒) | 592 | 444 | 90 | 17.938 |
graph LR
A(K6施压机) --> B(应用容器)
B -->C(MySQL容器)
Spring Boot Native
,Quarkus Native
,Spring Boot JVM
,Quarkus JVM
每个一个实例{
"code": 200,
"message": "OK",
"data": {
"id": 4,
"version": 1,
"deleted": 0,
"createBy": "admin",
"updateBy": "admin",
"createTime": 1695312514000,
"updateTime": 1695312532000,
"username": "test41"
}
}
-i:指定请求数量 -u:模拟并发数量 –duration:请求时长定义,例如:60s,1m -e url:指定环境变量url,用于实际场景替换
- 脚本输出样例
scenarios: (100.00%) 1 scenario, 50 max VUs, 36s max duration (incl. graceful stop): * default: 50 looping VUs for 6s (gracefulStop: 30s)
✓ is status 200
checks.........................: 100.00% ✓ 7761 ✗ 0
data_received..................: 1.9 MB 324 kB/s
data_sent......................: 730 kB 121 kB/s
http_req_blocked...............: avg=12.22µs min=1µs med=3µs max=3.26ms p(90)=5µs p(95)=6µs
http_req_connecting............: avg=7.1µs min=0s med=0s max=2.19ms p(90)=0s p(95)=0s
http_req_duration..............: avg=38.56ms min=7.55ms med=34.26ms max=216.77ms p(90)=58.96ms p(95)=68.51ms
{ expected_response:true }...: avg=38.56ms min=7.55ms med=34.26ms max=216.77ms p(90)=58.96ms p(95)=68.51ms
http_req_failed................: 0.00% ✓ 0 ✗ 7761
http_req_receiving.............: avg=52.57µs min=19µs med=46µs max=680µs p(90)=81µs p(95)=97µs
http_req_sending...............: avg=19.87µs min=7µs med=16µs max=1.27ms p(90)=27µs p(95)=38µs
http_req_tls_handshaking.......: avg=0s min=0s med=0s max=0s p(90)=0s p(95)=0s
http_req_waiting...............: avg=38.49ms min=7.51ms med=34.18ms max=216.58ms p(90)=58.89ms p(95)=68.46ms
http_reqs......................: 7761 1288.780058/s
iteration_duration.............: avg=38.7ms min=7.76ms med=34.4ms max=218.51ms p(90)=59.08ms p(95)=68.64ms
iterations.....................: 7761 1288.780058/s
vus............................: 50 min=50 max=50
vus_max........................: 50 min=50 max=50 ``` - `simple-test.js`脚本说明 ``` import http from 'k6/http'; import { check } from 'k6';
export default function () {
const res = http.get(${__ENV.url}
);
check(res, {
‘is status 200’: (r) => r.status === 200
});
}
```
Case | QPS | Avg Latency | P95 | CPU usage | Memory usage |
---|---|---|---|---|---|
Quarkus Native,-u 50 | 1699.067212/s | 29.41ms | 50.07ms | 136.91% | 23.15MB |
Quarkus Native,-u 100 | 1749.35664/s | 57.14ms | 89.9ms | 148.9% | 23.95MB |
Quarkus Native,-u 200 | 1765.832527/s | 113.23ms | 167.43ms | 156.17% | 25.5MB |
Spring Boot Native,-u 50 | 1114.946899/s | 44.82ms | 85.11ms | 226.5% | 86.23MB |
Spring Boot Native,-u 100 | 1175.220721/s | 85.06ms | 137.26ms | 236.07% | 96.16MB |
Spring Boot Native,-u 200 | 1094.461679/s | 182.67ms | 284.98ms | 246.32% | 143.3MB |
Quarkus JVM,-u 50 | 2149.507697/s | 23.24ms | 39ms | 111.99% | 173.6MB |
Quarkus JVM,-u 100 | 2186.80721/s | 45.7m | 69.6ms | 126.62% | 174.2MB |
Quarkus JVM,-u 200 | 2211.63056/s | 90.38ms | 130.41ms | 125.45% | 180.1MB |
Spring Boot JVM,-u 50 | 1472.76853/s | 33.93ms | 65.69ms | 199.08% | 426.8MB |
Spring Boot JVM,-u 100 | 1624.997761/s | 61.51ms | 97.37ms | 211.01% | 427.2MB |
Spring Boot JVM,-u 200 | 1611.01646/s | 124.05ms | 188.24ms | 214.96% | 428.1MB |
项目需求:如果项目需要快速启动,低内存消耗,那么两者都可以满足。如果已经在使用 Spring Stack,并且想要继续保持使用它,那么 Spring Boot Native 会更加合适。如果项目对开发效率有高要求,那么 Quarkus 可能更符合需求。
团队技能:如果团队成员已经非常熟悉 Spring Stack,那么采用 Spring Boot Native 可能可以减少学习曲线。反之,如果团队愿意尝试新的技术,并且对响应式编程和函数式编程有兴趣,那么选择 Quarkus 可以是一个不错的选择。
社区支持和文档:Spring 社区非常活跃,有大量的教程和指南。虽然 Quarkus 比较新,但也在积极扩大其社区,并提供了详细的文档。
在实际决策过程中,最好能够根据具体情况进行技术选型,可能的话,可以在小规模的项目或者原型中尝试并评估这些框架。