从 quarkus-resteasy 迁移到 quarkus-resteasy-reactive,使用 ThreadLocal 的应用程序怎么样?
正如文档中所述,从 quarkus-resteasy 过渡到响应式就像仅更改 Maven 依赖项一样简单,并且它应该可以工作。
在我们的 quarkus 项目中,我们在 @PreMatching 过滤器中创建一个会话并将其保存在线程本地。在其他过滤器中,我们使用其他信息更新会话。然后,会话信息将用于所有服务和资源。
经过一些性能测试后,即使我们有更多的 RAM 和 CPU,我们也看到 prometheus 中只使用了 200 个线程。我们可以更改属性文件中的最大线程或转向反应式编程。
一开始,我们更改为 quarkus React,并遇到了以下问题:
当将 React 添加到 quarkus-resteasy 时,我们遇到了以下问题: 第一个拦截请求的线程是事件循环线程。然后,如果使用@Blocking注释的方法将执行委托给工作线程,否则它继续使用事件循环线程执行。
问题1) 屏蔽方法: 在 @PreMatching
过滤器中添加到会话的所有信息都将丢失。但是从具有优先级的其他过滤器添加到会话中的信息(例如 @Priority(Priorities.AUTHENTICATION - 10)
)存在于工作线程中。
问题2)NoBlocking方法: 对于几个请求,一切工作正常,但是对于 100 个并行请求,我们会遇到随机丢失会话信息的情况。谷歌搜索后,事件循环线程使用不同的上下文(Vertx 线程上下文),我没有找到任何文档来解释如何从 ThreadLocal 移动到 Vertx 线程上下文,同时从 quarkus 移动到 quarkus 反应式。
问题3) Transform方法返回Uni,ThreadLocal信息被传播,但我还没有在负载下测试它。 [更新] 与问题 2)
问题 4) 相同 无法找到如何在 Vertx Thread 中运行集成测试
关于如何在移动到时使用 ThreadLocal 将项目移动到其他任何东西的帮助夸库斯反应将受到赞赏
As stated in the documentation passing from quarkus-resteasy to reactive is as simple as changing only maven dependency and it should works.
In our quarkus project, we create a session in @PreMatching
filter and save it in thread local. In other filters we update session with other information. Session information are then used in all services and resources.
After somme performance tests, even we have more RAM and CPU we see only 200 threads used in prometheus. We have the possibility to change max-thread in properties file or moving to reactive programming.
At start point, we changed to quarkus reactive and we experienced the following problems:
When adding reactive to quarkus-resteasy we experienced the following:
The first thread that intercept request is an event loop thread. Then it delegate execution to worker thread if method annotated with @Blocking, else it continue execution with event loop thread.
Problem 1) Blocking method:
All information added to session in @PreMatching
filter are lost. But information added in the session from other filters with priority for example @Priority(Priorities.AUTHENTICATION - 10)
are present in the worker thread.
Problem 2) NoBlocking method:
With a few requests all thing works fine, but with 100 parallel requests, we experience a random losing session information. After googling, event loop thread use a different context (Vertx thread context) and I haven't find any documentation that explain how to move from ThreadLocal to Vertx Thread context while moving from quarkus to quarkus reactive.
Problem 3) Transform method to return Uni, ThreadLocal information are propagated but I haven't yet test it under load. [UPDATE] same as Problem 2)
Problem 4) Cant find how to run integration tests in Vertx Thread
Any help on how to move projects using ThreadLocal to anything else when moving to quarkus reactive will be appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你可以使用 Vertx
ContextLocals
,看看这个 https: //pt.quarkus.io/guides/duplicated-contextI think you can use Vertx
ContextLocals
, take a look at this https://pt.quarkus.io/guides/duplicated-context