Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: ThreadWorkerPool支持newVirtualThreadPerTaskExecutor方式使用虚拟线程 #71

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

JingkaiTang
Copy link

@JingkaiTang JingkaiTang commented Nov 29, 2024

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

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

Copy link

github-actions bot commented Nov 29, 2024

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

Copy link

codecov bot commented Nov 29, 2024

Codecov Report

Attention: Patch coverage is 89.36170% with 10 lines in your changes missing coverage. Please review.

Project coverage is 70.13040%. Comparing base (a3dda78) to head (8a6fb06).

Files with missing lines Patch % Lines
...c/core/worker/support/thread/ThreadWorkerPool.java 42.85714% 8 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.12575%   70.13040%   +0.00464%     
- Complexity        4211        4241         +30     
=====================================================
  Files              434         437          +3     
  Lines            17018       17101         +83     
  Branches          1726        1728          +2     
=====================================================
+ Hits             11934       11993         +59     
- Misses            3970        3992         +22     
- Partials          1114        1116          +2     
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 61.22449% <42.85714%> (-2.72900%) ⬇️

... and 8 files with indirect coverage changes

@JingkaiTang JingkaiTang changed the title ThreadWorkerPool支持newVirtualThreadPerTaskExecutor方式使用虚拟线程 WIP: ThreadWorkerPool支持newVirtualThreadPerTaskExecutor方式使用虚拟线程 Nov 29, 2024
@JingkaiTang
Copy link
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
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
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.

代码很优秀,感谢贡献

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