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

shutdown时间为何设置30s太长了吧 #3

Closed
zhangyq1011 opened this issue Jun 28, 2018 · 11 comments
Closed

shutdown时间为何设置30s太长了吧 #3

zhangyq1011 opened this issue Jun 28, 2018 · 11 comments

Comments

@zhangyq1011
Copy link

ThreadPoolExecutor executor = processor.getExecutor();
executor.shutdown();
executor.awaitTermination(30, TimeUnit.SECONDS);

@LinShunKang
Copy link
Owner

嗯,已经更改为5s了,原意是为了让AsyncPerfStatsProcessor中的任务能完全执行完毕,根据目前的使用情况来看是有点长了。
感谢指出:)

@zhangyq1011
Copy link
Author

如果能够配上架构图或者详细点的使用说明图就更好了。我按照使用手册跑起来了,没有看到你输出的内容。

@LinShunKang
Copy link
Owner

LinShunKang commented Jun 28, 2018

指定IncludePackages了么,默认的输出到stdout里了,并且默认只输出count > 0的方法;
文档方面我会继续完善的。

@zhangyq1011
Copy link
Author

打印日志如下:
2018-06-29 08:35:00.721 [MyPerf4J] INFO BackgroundProcessor finished!!! cost: 0ms
2018-06-29 08:35:30.144 [MyPerf4J] INFO RoundRobinProcessor finished!!! cost: 0ms
2018-06-29 08:35:30.146 [MyPerf4J] INFO BackgroundProcessor finished!!! cost: 0ms
2018-06-29 08:35:30.219 [MyPerf4J] INFO RoundRobinProcessor finished!!! cost: 0ms
2018-06-29 08:35:30.721 [MyPerf4J] INFO BackgroundProcessor finished!!! cost: 0ms

IncludePackages也配置的有。没有你给的:
Performance Statistics

@LinShunKang
Copy link
Owner

看日志, “RoundRobinProcessor finished”和“BackgroundProcessor finished”个打印了两次,理论上应该是各一次,应该是哪里配置错了;
1、你的项目依赖了MyPerf4J-ASM.jar ?
2、启动过程中是否报错了?
3、你的配置文件是如何配置的?

@zhangyq1011
Copy link
Author

项目没有依赖。
1、我配置的使用 java-agent 引用的。
2、启动正常没有异常
3、配置文件配置和你提供的demo一样我只是修改了IncludePackages 我们公司的包名而已

@LinShunKang
Copy link
Owner

LinShunKang commented Jul 2, 2018

我刚刚修复了一个bug,是由于代码中尝试对抽象方法和native方法进行注入后导致BackgroundProcessor提前结束循环,进而所输出的'MyPerf4J Performance Statistics'的方法偏少甚至不输出;
你pull一下develop分支的代码然后打包试一下:)

@zhangyq1011
Copy link
Author

已经尝试在使用中、如有问题反馈!

@LinShunKang
Copy link
Owner

好的,感谢反馈!

@zhangyq1011
Copy link
Author

AsyncPerfStatsProcessor类
ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 2, 5, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>(500), ThreadUtils.newThreadFactory("MyPerf4J-AsyncPerfStatsProcessor_"), new ThreadPoolExecutor.DiscardPolicy());
定义如上 最大线程池数目为2、keepAliveTime为5分钟。添加shutdown hook
使用如下代码:
ThreadPoolExecutor executor = processor.getExecutor(); executor.shutdown(); executor.awaitTermination(5, TimeUnit.SECONDS);
又启动了一个 线程 线程等待5s 关闭。感觉与ThreadPoolExecutor 设置的keepAliveTime为5分钟有些冲突。

第二个小疑问为何 shutdown hook 没有对 RoundRobinProcessor、BackgroundProcessor 两个线程进行关闭处理呢?谢谢!

@LinShunKang
Copy link
Owner

LinShunKang commented Jul 9, 2018

对于第一个问题,是这样的,AsyncPerfStatsProcessor负责处理提交自backgroundExecutor的性能统计数据,而引入ShutdownHook是为了把在当前TimeSlice里的数据进行处理,尽可能的保证数据不丢失,所以才等待了5s的时间,AsyncPerfStatsProcessor. executor设置的5分钟是指当前线程数超过coreSize部分的线程空闲时间达到5分钟后线程池会自动缩容至coreSize。

对于第二个问题,这个我倒是没注意到,不过RoundRobinProcessor和BackgroundProcessor只是在一个TimeSlice结束时才会触发,并且它们的执行时间都非常短(都是内存操作),理论上应该不用手动进行关闭。

PS:
1、AbstractRecorderMaintainer中涉及时间片轮转和数据转发的逻辑已经重写了,在MyPerf4J的整个生命周期均无锁等待,并且backgroundExecutor的执行效率提高了不少,建议你pull一下develop分支的代码 : )
2、中文的Wiki已经写好了:中文Wiki

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

No branches or pull requests

2 participants