我不确定这是某种错误还是我这边缺少的配置,但我得到了一种不同的行为,vertx事件总线将线程分配给“@consumeevent”方法。
在quarkus版本1.13.7.final及更高版本中,如果池中有足够的线程,则vertx会将一个eventloop线程绑定到每个使用者方法。但在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中运行相同的代码。最终,只有一个线程执行所有操作:
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进行测试
暂无答案!
目前还没有任何答案,快来回答吧!