Tencent / TencentKona-8

Tencent Kona is a no-cost, production-ready distribution of the Open Java Development Kit (OpenJDK), Long-term support(LTS) with quarterly updates. Tencent Kona serves as the default JDK internally at Tencent Cloud for cloud computing and other Java applications.
Other
938 stars 146 forks source link

用Kona的Fiber解决Http阻塞的问题 #97

Closed sssxyd closed 1 year ago

sssxyd commented 1 year ago
  1. 看了你们的文章:https://juejin.cn/post/7007261636561993759 里面说尚未解决Socket阻塞问题(阻塞在native代码里了);
  2. 你们的demo代码中,有用netty作为client解决阻塞问题的例子; 请问如下思路能否解决Socket阻塞线程的问题:
  3. 业务代码在fiber中执行;
  4. 业务代码将http请求发送到本地的netty客户端,netty客户端用非阻塞的socket发送http请求;
  5. 业务代码用 completefuture.get() 等待netty客户端反馈;

请问: completefuture.get() 时,阻塞的是fiber还是其所属的核心线程?

miao-zheng commented 1 year ago
  1. socket在最新的协程版本已经支持,可以参考这篇文章:https://mp.weixin.qq.com/s/RZzcCUc9iM_hOLaAoqw8tg 可以试试新版本
  2. demo是老的方案,参考demo来写也可以,本质上是将网络操作放到netty的线程池上执行,然后将执行业务代码的协程通过 completefuture.get()阻塞起来,等待netty执行完;
  3. 如果协程执行completefuture.get(),阻塞的就是当前正在执行的协程。
sssxyd commented 1 year ago

谢谢,我还想请教,你们的协程是怎么处理ThreadLocal的, 掘金的那篇文章里,你们没有实现Loom的Scope Variable; 比如,我的业务代码改用协程执行,原来的ThreadLocal是否还继续有效? 如果无效,那有没有替代方案?(stackful的部分我没找到介绍的文档)

miao-zheng commented 1 year ago

每个协程有自己的thread local,正常使用的话,协程只会访问到自己的thread local。

sssxyd commented 1 year ago

明白了,谢谢;