我不确定这是某种错误还是只是我身边缺少的配置,但是在 Vertx eventBus 将线程分配给“@ConsumeEvent”方法的方式上,我得到了不同的行为。
在Quarkus版本1.13.7中。最后,如果池中有足够的线程,那么Vertx会将一个eventloop线程绑定到每个使用者方法。但在Quarkus 2.0.0中,每条消息都由一个或两个线程处理,使执行几乎同步。在VM或本机模式下,这种行为是相同的。
我做了一个愚蠢的项目来说明这一点:https://github.com/AngelPerz/test-vertx-q2
在这个项目中,当接收到对localhost:8080/test的调用时,它会通过eventBus将一些消息发送给3个用户。方法,通过一个简单的等待来模拟每个方法上的一些工作,并通过eventBus将完成情况发送给最终收集器。
在Quarkus 1.13.7中使用此场景。最终,同一应用程序同时执行所有操作:
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中,执行之间的时间差为955ms。2.0.0中的最终和2592ms。最终的如果相关,则使用GraalVM 21.0.0.2 java11进行测试
最后,这是一个bug,修复已包含在Quarkus 2.0.2版中。最终的
本文向大家介绍多处理和多线程之间的区别,包括了多处理和多线程之间的区别的使用技巧和注意事项,需要的朋友参考一下 多处理 多处理是指在单个系统中使用多个CPU /处理器。多个CPU可以并行运行,并一起执行多个进程。它们在很大程度上提高了计算能力。对称多重处理和非对称多重处理是两种类型的多重处理。 多线程 多线程是指由单个CPU执行的多个线程,使得每个线程以并行方式执行,并且CPU /处理器使用上下文
问题内容: 我正在学习如何在Python中使用和模块来并行运行某些操作并加速我的代码。 我发现很难理解一个对象与一个对象之间的区别是什么(也许是因为我没有任何理论背景)。 另外,对我来说,如何实例化一个作业队列并使其只有4个(例如)并行运行,而另一个则等待资源释放后再执行,对我来说也不是很清楚。 我发现文档中的示例很清楚,但并不十分详尽。一旦我尝试使事情复杂化,我就会收到很多奇怪的错误(例如无法腌
本文向大家介绍python进阶之多线程对同一个全局变量的处理方法,包括了python进阶之多线程对同一个全局变量的处理方法的使用技巧和注意事项,需要的朋友参考一下 通常情况下: 输出结果: #由于多线程不像多进程一样,每一个进程都一个独立的资源块,线程之间是共享主线程的一个资源块(虽然这样说不合适) #这样虽然方便了线程之间的数据传递,但是又会由于线程之间执行顺序的不确定,导致最后的结果不是应该输
我的工作应该使用并行技术,我是python的新用户。因此,我想知道您是否可以分享一些关于python和模块的资料。这两者有什么区别?
我正在尝试使用多个处理器类在处理器步骤中处理记录。这些类可以并行工作。目前我已经编写了一个多线程步骤,其中我 设置处理器类的输入和输出行 提交给遗嘱执行人服务 获取所有未来对象并收集最终输出
我有一个图像路径列表,我想在进程或线程之间划分,以便每个进程处理列表的某些部分。处理包括从磁盘加载图像,进行一些计算并返回结果。我正在使用Python 2.7 下面是我如何创建辅助进程 我所面临的问题是,当我在initializer函数中记录初始化时间时,我知道worker不是并行初始化的,而是每个worker都以5秒的间隔初始化,下面是供参考的日志 我尝试过使用将同时启动辅助线程 我知道Wind