Skip to content

Conversation

@JingkaiTang
Copy link
Contributor

@JingkaiTang JingkaiTang commented Nov 29, 2024

用Executors.newVirtualThreadPerTaskExecutor()的方式使用虚拟线程,用ThreadPerTaskExecutor代替,用完立即销毁

使用ExecutorServiceWrapper去实现ThreadPoolMXBean临时使用反射实现,只简单统计了提交和完成的任务数量,近似替代相关数据监控。JEP#444建议使用JFR来监控虚拟线程。

@github-actions
Copy link

github-actions bot commented Nov 29, 2024

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@codecov
Copy link

codecov bot commented Nov 29, 2024

Codecov Report

Attention: Patch coverage is 77.77778% with 26 lines in your changes missing coverage. Please review.

Project coverage is 70.10816%. Comparing base (a3dda78) to head (0155531).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...c/core/worker/support/thread/ThreadWorkerPool.java 35.13514% 24 Missing ⚠️
...trpc/core/management/AbstractThreadPoolMXBean.java 75.00000% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                  Coverage Diff                  @@
##                master         #71         +/-   ##
=====================================================
- Coverage     70.13750%   70.10816%   -0.02935%     
- Complexity        4212        4238         +26     
=====================================================
  Files              434         437          +3     
  Lines            17018       17105         +87     
  Branches          1726        1727          +1     
=====================================================
+ Hits             11936       11992         +56     
- Misses            3969        3996         +27     
- Partials          1113        1117          +4     
Files with missing lines Coverage Δ
...re/management/ThreadPerTaskExecutorMXBeanImpl.java 100.00000% <100.00000%> (ø)
.../core/management/ThreadPerTaskExecutorWrapper.java 100.00000% <100.00000%> (ø)
...ent/trpc/core/management/ThreadPoolMXBeanImpl.java 100.00000% <ø> (+13.33333%) ⬆️
...c/core/worker/support/thread/ThreadPoolConfig.java 96.77419% <100.00000%> (+3.67074%) ⬆️
...trpc/core/management/AbstractThreadPoolMXBean.java 75.00000% <75.00000%> (ø)
...c/core/worker/support/thread/ThreadWorkerPool.java 60.78431% <35.13514%> (-3.16919%) ⬇️

... and 11 files with indirect coverage changes

@JingkaiTang JingkaiTang changed the title ThreadWorkerPool支持newVirtualThreadPerTaskExecutor方式使用虚拟线程 WIP: ThreadWorkerPool支持newVirtualThreadPerTaskExecutor方式使用虚拟线程 Nov 29, 2024
@JingkaiTang
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

.getDeclaredMethod(NEW_THREAD_PER_TASK_EXECUTOR_NAME, ThreadFactory.class);
ThreadPerTaskExecutorWrapper wrappedThreadPool = ThreadPerTaskExecutorWrapper
.wrap((ExecutorService) newThreadPerTaskExecutorMethod.invoke(executorsClazz, threadFactory));
threadPool = wrappedThreadPool;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一行看起来多余,threadPool没有地方使用

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个threadPool变量是ThreadWorkPool的属性,是线程池的实例,会有跟维护ThreadWorkPool生命周期相关的操作

ThreadPerTaskExecutorWrapper wrappedThreadPool = ThreadPerTaskExecutorWrapper
.wrap((ExecutorService) newThreadPerTaskExecutorMethod.invoke(executorsClazz, threadFactory));
threadPool = wrappedThreadPool;
threadPoolMXBean = new ThreadPerTaskExecutorMXBeanImpl(wrappedThreadPool);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L124 - L128缺少单测

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里代码覆盖需要跑在Java21或者支持fiber的KonaJDK

@@ -0,0 +1,30 @@
package com.tencent.trpc.core.management;

import javax.management.MalformedObjectNameException;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码很优秀,感谢贡献

return useThreadPerTaskExecutor;
}

public void setUseThreadPerTaskExecutor(boolean useThreadPerTaskThread) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useThreadPerTaskThread命名是不是错了,useThreadPerTaskExecutor

ThreadPerTaskExecutorWrapper wrappedThreadPool = ThreadPerTaskExecutorWrapper
.wrap((ExecutorService) newThreadPerTaskExecutorMethod.invoke(executorsClazz, threadFactory));
threadPool = wrappedThreadPool;
threadPoolMXBean = new ThreadPerTaskExecutorMXBeanImpl(wrappedThreadPool);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

threadPool 和threadPoolMXBean 会被覆盖掉

package com.tencent.trpc.core.management;

/*
* Tencent is pleased to support the open source community by making tRPC available.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

帮加在package上面吧

@@ -0,0 +1,63 @@
package com.tencent.trpc.core.management;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

五个新文件都需要加一下版权说明

@wardseptember wardseptember merged commit c1c84f1 into trpc-group:master Jan 9, 2025
16 checks passed
liuzengh added a commit to liuzengh/cla-database that referenced this pull request Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants