- 再次压测,得到结果如下,并发数涨了10倍,QPS也涨了10倍,很完美的线程提升,不过平均等待时间略涨
文章插图
- 再来个狠的,并发数一口暴涨到5000试试,如下图,这么高的并发,已经无法保障100%的成功率了,好在95%也不低,另外平均等待时间从39毫秒暴涨到6.26秒,至于QPS当然不会太高,仅比300并发的时候高了百分之五十
文章插图
- 操作步骤和刚才差不多,只是要修改脚本中的接口地址,如下所示
import http from 'k6/http';import { sleep, check } from 'k6';export let options = {vus: 30,duration: '60s',};export default function () {let r = Math.floor(Math.random() * 6) + 1;const res = http.get(`http://192.168.0.1:8080/pool/persons/${r}`);check(res, {'is status 200': (res) => res.status === 200,'body size is > 0': (r) => r.body.length > 0,});sleep(1);}
- 30并发的压测结果如下,和使用虚拟线程并无区别
文章插图
- 300并发压测结果如下,和使用虚拟线程并无区别
![支持JDK19虚拟线程的web框架,之一:体验](http://img.zhejianglong.com/231018/2131263059-10.png)
文章插图
- 5000并发压测结果如下,和虚拟线程相比,平均等待时间略长,QPS略低,但是整体上差别不大
![支持JDK19虚拟线程的web框架,之一:体验](http://img.zhejianglong.com/231018/21312B615-11.png)
文章插图
小结
- 在响应式web服务中,并且关联的数据库操作也是响应式的,相比传统的线程池模型,虚拟线程并未带来明显收益
- 不甘心啊,接下来就换成SpringBoot应用,模拟咱们日常开发最常见的数据库访问场景,看看相比之下,差距有多大?
- 由于打算将SpringBoot应用部署在quarkus应用所在电脑上,所以要先停掉quarkus应用,执行以下命令
sudo docker stop quarkus
启动SpringBoot应用- 新建名为application.properties的配置文件 , 内容是数据库相关的参数,如下所示
spring.datasource.url=jdbc:postgresql://42.193.162.141:5432/quarkus_testspring.datasource.username=quarkusspring.datasource.password=123456spring.datasource.driver-class-name=org.postgresql.Driverspring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialectspring.jpa.properties.hibernate.hbm2ddl.auto=updatespring.datasource.hikari.maximum-pool-size=256
- 我这里,application.properties的路径是:/home/lighthouse/config/springboot/application.properties
- 检查application.properties文件的可读性,执行以下命令设置
sudo chmod a+r application.properties
- 执行以下命令即可部署和启动springboot应用,注意application.properties文件的位置要换成您自己的配置文件路径
docker run -idt \--name springboot \-p 8080:8080 \-v /home/lighthouse/config/springboot/application.properties:/application/BOOT-INF/classes/application.properties \bolingcavalry/springboot-postgresql-demo:x64-0.0.3
- 上述命令中,springboot应用的镜像bolingcavalry/springboot-postgresql-demo:x64-0.0.3是我提前准备好的,本篇只管使用即可,至于如何制作此镜像,接下来的文章会有详细说明
- 看到以下日志,证明应用启动成功
._______ _ _ /\\ / ___'_ __ _ _(_)_ ____ _ \ \ \ \( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/___)| |_)| | | | | || (_| |) ) ) )'|____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot ::(v2.7.4)2022-10-16 13:01:01.022INFO 1 --- [main] .b.s.SpringbootPostgresqlDemoApplication : Starting SpringbootPostgresqlDemoApplication v0.0.1-SNAPSHOT using Java 11.0.13 on 5c25db81639e with PID 1 (/application/BOOT-INF/classes started by root in /application)2022-10-16 13:01:01.025INFO 1 --- [main] .b.s.SpringbootPostgresqlDemoApplication : No active profile set, falling back to 1 default profile: "default"2022-10-16 13:01:01.795INFO 1 --- [main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.2022-10-16 13:01:01.857INFO 1 --- [main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 47 ms. Found 1 JPA repository interfaces.2022-10-16 13:01:02.392INFO 1 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer: Tomcat initialized with port(s): 8080 (http)2022-10-16 13:01:02.405INFO 1 --- [main] o.apache.catalina.core.StandardService: Starting service [Tomcat]2022-10-16 13:01:02.405INFO 1 --- [main] org.apache.catalina.core.StandardEngine: Starting Servlet engine: [Apache Tomcat/9.0.65]2022-10-16 13:01:02.492INFO 1 --- [main] o.a.c.c.C.[Tomcat].[localhost].[/]: Initializing Spring embedded WebApplicationContext2022-10-16 13:01:02.492INFO 1 --- [main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1364 ms2022-10-16 13:01:02.701INFO 1 --- [main] o.hibernate.jpa.internal.util.LogHelper: HHH000204: Processing PersistenceUnitInfo [name: default]2022-10-16 13:01:02.741INFO 1 --- [main] org.hibernate.Version: HHH000412: Hibernate ORM core version 5.6.11.Final2022-10-16 13:01:02.867INFO 1 --- [main] o.hibernate.annotations.common.Version: HCANN000001: Hibernate Commons Annotations {5.1.2.Final}2022-10-16 13:01:02.942INFO 1 --- [main] com.zaxxer.hikari.HikariDataSource: HikariPool-1 - Starting...2022-10-16 13:01:03.164INFO 1 --- [main] com.zaxxer.hikari.HikariDataSource: HikariPool-1 - Start completed.2022-10-16 13:01:03.179INFO 1 --- [main] org.hibernate.dialect.Dialect: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect2022-10-16 13:01:03.688INFO 1 --- [main] o.h.e.t.j.p.i.JtaPlatformInitiator: HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]2022-10-16 13:01:03.695INFO 1 --- [main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 华为P50支持几倍变焦_华为P50有光学防抖吗
- 小米11Ultra支持变焦吗_支持多少倍变焦
- 虚拟化_Vmware——敬请期待!
- 虚拟化_Xen——敬请期待!
- 小米11支持人脸支付吗_小米11支持人脸识别吗
- 如何用Virtualbox搭建一个虚拟机
- 华为nova9支持NFC吗_华为nova9有NFC功能吗
- vulnhub靶场之EMPIRE
- 华为nova9pro是5g手机吗_支持5g吗
- iPhone13有高刷吗_iPhone13支持高刷吗