我不确定这是某种错误还是只是我身边缺少的配置,但是在 Vertx eventBus 将线程分配给“@ConsumeEvent”方法的方式上,我得到了不同的行为。
在 Quarkus 版本 1.13.7.FINAL 和更早版本中,如果池有足够的线程,Vertx 会为每个消费者方法绑定一个事件循环线程。但在 Quarkus 2.0.0 中,每条消息都由一个或两个线程处理,使得执行几乎是同步的。这种行为在 VM 或本机模式下是相同的。
我做了一个愚蠢的项目来说明这一点:https ://github.com/AngelPerz/test-vertx-q2
在这个项目中,当收到对localhost:8080/test的调用时,它通过 eventBus 使用 .publish() 方法向 3 个消费者发送一些消息,通过简单的等待模拟每个消费者的一些工作,并将完成发送到最终收集器也通过 eventBus。
对于Quarkus 1.13.7.FINAL中的这种情况,相同的应用程序同时执行所有内容:
2021-07-04 14:18:44,597 INFO [io.quarkus] (main) code-with-quarkus 1.0.0-SNAPSHOT native (powered by Quarkus 1.13.7.Final) started in 0.008s. Listening on: http://0.0.0.0:8080
2021-07-04 14:18:44,598 INFO [io.quarkus] (main) Profile prod activated.
2021-07-04 14:18:44,598 INFO [io.quarkus] (main) Installed features: [cdi, mutiny, resteasy, smallrye-context-propagation, vertx]
2021-07-04 14:18:50,082 INFO [org.acm.con.TestLauncher] (vert.x-eventloop-thread-17) Starting test with [5] workUnits
2021-07-04 14:18:50,082 INFO [org.acm.con.ConsumerC] (vert.x-eventloop-thread-16) ConsumerC :: starting workUnit [0]
2021-07-04 14:18:50,082 INFO [org.acm.con.ConsumerB] (vert.x-eventloop-thread-14) ConsumerB :: starting workUnit [0]
2021-07-04 14:18:50,082 INFO [org.acm.con.ConsumerA] (vert.x-eventloop-thread-18) ConsumerA :: starting workUnit [0]
2021-07-04 14:18:50,233 INFO [org.acm.con.ConsumerC] (vert.x-eventloop-thread-16) ConsumerC :: finished workUnit [0]
2021-07-04 14:18:50,233 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-15) WorkCollector :: received finish work [ConsumerC, 0]
2021-07-04 14:18:50,233 INFO [org.acm.con.ConsumerB] (vert.x-eventloop-thread-14) ConsumerB :: finished workUnit [0]
2021-07-04 14:18:50,233 INFO [org.acm.con.ConsumerA] (vert.x-eventloop-thread-18) ConsumerA :: finished workUnit [0]
2021-07-04 14:18:50,233 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-15) WorkCollector :: received finish work [ConsumerB, 0]
2021-07-04 14:18:50,233 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-15) WorkCollector :: received finish work [ConsumerA, 0]
2021-07-04 14:18:50,233 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-15) WorkCollector :: all works completed by consumers for workUnit [0]
2021-07-04 14:18:50,283 INFO [org.acm.con.ConsumerC] (vert.x-eventloop-thread-16) ConsumerC :: starting workUnit [1]
2021-07-04 14:18:50,283 INFO [org.acm.con.ConsumerB] (vert.x-eventloop-thread-14) ConsumerB :: starting workUnit [1]
2021-07-04 14:18:50,283 INFO [org.acm.con.ConsumerA] (vert.x-eventloop-thread-18) ConsumerA :: starting workUnit [1]
2021-07-04 14:18:50,435 INFO [org.acm.con.ConsumerC] (vert.x-eventloop-thread-16) ConsumerC :: finished workUnit [1]
2021-07-04 14:18:50,435 INFO [org.acm.con.ConsumerA] (vert.x-eventloop-thread-18) ConsumerA :: finished workUnit [1]
2021-07-04 14:18:50,435 INFO [org.acm.con.ConsumerB] (vert.x-eventloop-thread-14) ConsumerB :: finished workUnit [1]
2021-07-04 14:18:50,435 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-15) WorkCollector :: received finish work [ConsumerC, 1]
2021-07-04 14:18:50,435 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-15) WorkCollector :: received finish work [ConsumerA, 1]
2021-07-04 14:18:50,435 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-15) WorkCollector :: received finish work [ConsumerB, 1]
2021-07-04 14:18:50,435 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-15) WorkCollector :: all works completed by consumers for workUnit [1]
2021-07-04 14:18:50,483 INFO [org.acm.con.ConsumerC] (vert.x-eventloop-thread-16) ConsumerC :: starting workUnit [2]
2021-07-04 14:18:50,483 INFO [org.acm.con.ConsumerB] (vert.x-eventloop-thread-14) ConsumerB :: starting workUnit [2]
2021-07-04 14:18:50,483 INFO [org.acm.con.ConsumerA] (vert.x-eventloop-thread-18) ConsumerA :: starting workUnit [2]
2021-07-04 14:18:50,633 INFO [org.acm.con.ConsumerC] (vert.x-eventloop-thread-16) ConsumerC :: finished workUnit [2]
2021-07-04 14:18:50,634 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-15) WorkCollector :: received finish work [ConsumerC, 2]
2021-07-04 14:18:50,634 INFO [org.acm.con.ConsumerB] (vert.x-eventloop-thread-14) ConsumerB :: finished workUnit [2]
2021-07-04 14:18:50,634 INFO [org.acm.con.ConsumerA] (vert.x-eventloop-thread-18) ConsumerA :: finished workUnit [2]
2021-07-04 14:18:50,634 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-15) WorkCollector :: received finish work [ConsumerB, 2]
2021-07-04 14:18:50,634 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-15) WorkCollector :: received finish work [ConsumerA, 2]
2021-07-04 14:18:50,634 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-15) WorkCollector :: all works completed by consumers for workUnit [2]
2021-07-04 14:18:50,684 INFO [org.acm.con.ConsumerA] (vert.x-eventloop-thread-18) ConsumerA :: starting workUnit [3]
2021-07-04 14:18:50,684 INFO [org.acm.con.ConsumerB] (vert.x-eventloop-thread-14) ConsumerB :: starting workUnit [3]
2021-07-04 14:18:50,684 INFO [org.acm.con.ConsumerC] (vert.x-eventloop-thread-16) ConsumerC :: starting workUnit [3]
2021-07-04 14:18:50,835 INFO [org.acm.con.ConsumerC] (vert.x-eventloop-thread-16) ConsumerC :: finished workUnit [3]
2021-07-04 14:18:50,836 INFO [org.acm.con.ConsumerB] (vert.x-eventloop-thread-14) ConsumerB :: finished workUnit [3]
2021-07-04 14:18:50,836 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-15) WorkCollector :: received finish work [ConsumerC, 3]
2021-07-04 14:18:50,836 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-15) WorkCollector :: received finish work [ConsumerB, 3]
2021-07-04 14:18:50,836 INFO [org.acm.con.ConsumerA] (vert.x-eventloop-thread-18) ConsumerA :: finished workUnit [3]
2021-07-04 14:18:50,837 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-15) WorkCollector :: received finish work [ConsumerA, 3]
2021-07-04 14:18:50,837 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-15) WorkCollector :: all works completed by consumers for workUnit [3]
2021-07-04 14:18:50,884 INFO [org.acm.con.ConsumerB] (vert.x-eventloop-thread-14) ConsumerB :: starting workUnit [4]
2021-07-04 14:18:50,884 INFO [org.acm.con.ConsumerA] (vert.x-eventloop-thread-18) ConsumerA :: starting workUnit [4]
2021-07-04 14:18:50,884 INFO [org.acm.con.ConsumerC] (vert.x-eventloop-thread-16) ConsumerC :: starting workUnit [4]
2021-07-04 14:18:51,035 INFO [org.acm.con.ConsumerC] (vert.x-eventloop-thread-16) ConsumerC :: finished workUnit [4]
2021-07-04 14:18:51,035 INFO [org.acm.con.ConsumerA] (vert.x-eventloop-thread-18) ConsumerA :: finished workUnit [4]
2021-07-04 14:18:51,035 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-15) WorkCollector :: received finish work [ConsumerC, 4]
2021-07-04 14:18:51,035 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-15) WorkCollector :: received finish work [ConsumerA, 4]
2021-07-04 14:18:51,035 INFO [org.acm.con.ConsumerB] (vert.x-eventloop-thread-14) ConsumerB :: finished workUnit [4]
2021-07-04 14:18:51,037 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-15) WorkCollector :: received finish work [ConsumerB, 4]
2021-07-04 14:18:51,037 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-15) WorkCollector :: all works completed by consumers for workUnit [4]
正如我们所见,有 5 个不同的线程执行测试,但在Quarkus 2.0.0.FINAL中运行相同的代码,只有一个线程执行所有操作:
2021-07-04 13:27:54,523 INFO [io.quarkus] (main) code-with-quarkus 1.0.0-SNAPSHOT native (powered by Quarkus 2.0.0.Final) started in 0.007s. Listening on: http://0.0.0.0:8080
2021-07-04 13:27:54,524 INFO [io.quarkus] (main) Profile prod activated.
2021-07-04 13:27:54,524 INFO [io.quarkus] (main) Installed features: [cdi, resteasy, smallrye-context-propagation, vertx]
2021-07-04 13:28:03,630 INFO [org.acm.con.TestLauncher] (vert.x-eventloop-thread-0) Starting test with [5] workUnits
2021-07-04 13:28:04,632 INFO [org.acm.con.ConsumerB] (vert.x-eventloop-thread-0) ConsumerB :: starting workUnit [0]
2021-07-04 13:28:04,784 INFO [org.acm.con.ConsumerB] (vert.x-eventloop-thread-0) ConsumerB :: finished workUnit [0]
2021-07-04 13:28:04,784 INFO [org.acm.con.ConsumerC] (vert.x-eventloop-thread-0) ConsumerC :: starting workUnit [0]
2021-07-04 13:28:04,940 INFO [org.acm.con.ConsumerC] (vert.x-eventloop-thread-0) ConsumerC :: finished workUnit [0]
2021-07-04 13:28:04,940 INFO [org.acm.con.ConsumerA] (vert.x-eventloop-thread-0) ConsumerA :: starting workUnit [0]
2021-07-04 13:28:05,091 INFO [org.acm.con.ConsumerA] (vert.x-eventloop-thread-0) ConsumerA :: finished workUnit [0]
2021-07-04 13:28:05,091 INFO [org.acm.con.ConsumerB] (vert.x-eventloop-thread-0) ConsumerB :: starting workUnit [1]
2021-07-04 13:28:05,242 INFO [org.acm.con.ConsumerB] (vert.x-eventloop-thread-0) ConsumerB :: finished workUnit [1]
2021-07-04 13:28:05,242 INFO [org.acm.con.ConsumerC] (vert.x-eventloop-thread-0) ConsumerC :: starting workUnit [1]
2021-07-04 13:28:05,395 INFO [org.acm.con.ConsumerC] (vert.x-eventloop-thread-0) ConsumerC :: finished workUnit [1]
2021-07-04 13:28:05,395 INFO [org.acm.con.ConsumerA] (vert.x-eventloop-thread-0) ConsumerA :: starting workUnit [1]
2021-07-04 13:28:05,548 INFO [org.acm.con.ConsumerA] (vert.x-eventloop-thread-0) ConsumerA :: finished workUnit [1]
2021-07-04 13:28:05,549 INFO [org.acm.con.ConsumerB] (vert.x-eventloop-thread-0) ConsumerB :: starting workUnit [2]
2021-07-04 13:28:05,702 INFO [org.acm.con.ConsumerB] (vert.x-eventloop-thread-0) ConsumerB :: finished workUnit [2]
2021-07-04 13:28:05,702 INFO [org.acm.con.ConsumerC] (vert.x-eventloop-thread-0) ConsumerC :: starting workUnit [2]
2021-07-04 13:28:05,854 INFO [org.acm.con.ConsumerC] (vert.x-eventloop-thread-0) ConsumerC :: finished workUnit [2]
2021-07-04 13:28:05,854 INFO [org.acm.con.ConsumerA] (vert.x-eventloop-thread-0) ConsumerA :: starting workUnit [2]
2021-07-04 13:28:06,005 INFO [org.acm.con.ConsumerA] (vert.x-eventloop-thread-0) ConsumerA :: finished workUnit [2]
2021-07-04 13:28:06,006 INFO [org.acm.con.ConsumerB] (vert.x-eventloop-thread-0) ConsumerB :: starting workUnit [3]
2021-07-04 13:28:06,158 INFO [org.acm.con.ConsumerB] (vert.x-eventloop-thread-0) ConsumerB :: finished workUnit [3]
2021-07-04 13:28:06,158 INFO [org.acm.con.ConsumerC] (vert.x-eventloop-thread-0) ConsumerC :: starting workUnit [3]
2021-07-04 13:28:06,310 INFO [org.acm.con.ConsumerC] (vert.x-eventloop-thread-0) ConsumerC :: finished workUnit [3]
2021-07-04 13:28:06,310 INFO [org.acm.con.ConsumerA] (vert.x-eventloop-thread-0) ConsumerA :: starting workUnit [3]
2021-07-04 13:28:06,461 INFO [org.acm.con.ConsumerA] (vert.x-eventloop-thread-0) ConsumerA :: finished workUnit [3]
2021-07-04 13:28:06,461 INFO [org.acm.con.ConsumerB] (vert.x-eventloop-thread-0) ConsumerB :: starting workUnit [4]
2021-07-04 13:28:06,611 INFO [org.acm.con.ConsumerB] (vert.x-eventloop-thread-0) ConsumerB :: finished workUnit [4]
2021-07-04 13:28:06,611 INFO [org.acm.con.ConsumerC] (vert.x-eventloop-thread-0) ConsumerC :: starting workUnit [4]
2021-07-04 13:28:06,761 INFO [org.acm.con.ConsumerC] (vert.x-eventloop-thread-0) ConsumerC :: finished workUnit [4]
2021-07-04 13:28:06,762 INFO [org.acm.con.ConsumerA] (vert.x-eventloop-thread-0) ConsumerA :: starting workUnit [4]
2021-07-04 13:28:06,915 INFO [org.acm.con.ConsumerA] (vert.x-eventloop-thread-0) ConsumerA :: finished workUnit [4]
2021-07-04 13:28:06,915 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-0) WorkCollector :: received finish work [ConsumerB, 0]
2021-07-04 13:28:06,915 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-0) WorkCollector :: received finish work [ConsumerC, 0]
2021-07-04 13:28:06,916 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-0) WorkCollector :: received finish work [ConsumerA, 0]
2021-07-04 13:28:06,916 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-0) WorkCollector :: all works completed by consumers for workUnit [0]
2021-07-04 13:28:06,916 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-0) WorkCollector :: received finish work [ConsumerB, 1]
2021-07-04 13:28:06,916 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-0) WorkCollector :: received finish work [ConsumerC, 1]
2021-07-04 13:28:06,916 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-0) WorkCollector :: received finish work [ConsumerA, 1]
2021-07-04 13:28:06,916 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-0) WorkCollector :: all works completed by consumers for workUnit [1]
2021-07-04 13:28:06,916 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-0) WorkCollector :: received finish work [ConsumerB, 2]
2021-07-04 13:28:06,916 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-0) WorkCollector :: received finish work [ConsumerC, 2]
2021-07-04 13:28:06,916 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-0) WorkCollector :: received finish work [ConsumerA, 2]
2021-07-04 13:28:06,916 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-0) WorkCollector :: all works completed by consumers for workUnit [2]
2021-07-04 13:28:06,916 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-0) WorkCollector :: received finish work [ConsumerB, 3]
2021-07-04 13:28:06,916 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-0) WorkCollector :: received finish work [ConsumerC, 3]
2021-07-04 13:28:06,916 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-0) WorkCollector :: received finish work [ConsumerA, 3]
2021-07-04 13:28:06,916 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-0) WorkCollector :: all works completed by consumers for workUnit [3]
2021-07-04 13:28:06,916 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-0) WorkCollector :: received finish work [ConsumerB, 4]
2021-07-04 13:28:06,916 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-0) WorkCollector :: received finish work [ConsumerC, 4]
2021-07-04 13:28:06,916 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-0) WorkCollector :: received finish work [ConsumerA, 4]
2021-07-04 13:28:06,916 INFO [org.acm.con.TestWorkCollector] (vert.x-eventloop-thread-0) WorkCollector :: all works completed by consumers for workUnit [4]
1.13.7.FINAL的执行时间差为955ms,2.0.0.FINAL的执行时间差为2592ms;如果它可能相关,则使用 GraalVM 21.0.0.2 java11 进行了测试