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

Consumer实现中关于线程池的疑问 #34

Closed
rottle opened this issue Mar 18, 2013 · 4 comments
Closed

Consumer实现中关于线程池的疑问 #34

rottle opened this issue Mar 18, 2013 · 4 comments

Comments

@rottle
Copy link

rottle commented Mar 18, 2013

Consumer实现中,用到的MessageListener,其中,public Executor getExecutor(),返回处理消息的线程池。比如,我采用Executors.newFixedThreadPool(8)返回一个简单的线程池。可是通过计算消息的平均处理时间,发现性能并没有提高多少?这个地方,是否我理解有误?不能这样实现?

@hi-wayne
Copy link

consumer使用pull的方式去拉取数据
你拉取到数据后,扔给threadpool去处理
全部扔入threadpool后,consumer进行下一次拉取数据操作
看你的描述,没办法搞清楚,你具体每条信息消费的耗时,所以没办法衡量扔入threadpool是否会比直接处理消息,吞吐更快一些。

还有getExecutor()部分应该每次都返回是同一个threadpool实例,不需要每次new一个,没看到你贴这部分代码,不是太清楚你如何实现的。

@killme2008
Copy link
Owner

@rottle

线程池并不能提高单个消息的处理速度,原来是什么速度,现在还是什么速度,你想想是不是这样。

线程池的意义在于可以不阻塞消息接受的线程,提高消息处理的吞吐量。

@rottle
Copy link
Author

rottle commented Mar 21, 2013

嗯。非常谢谢两位的回复。
可能我的描述不太清楚。举个例子吧。比如一次拉取6000条消息,getExecutor(){return null}是采用单线程处理,共耗时300秒,即每条消息耗时50ms;同样,一次拉取6000条消息,如果通过getExecutor(){ return pool},即返回一个线程池(固定大小8),共耗时应该小于300S,可能为200S。基于上述,消息吞吐量应该是提高了。@killme2008 的回复,我清楚意思。
我的问题是:我经过测试发现,上述情况,6000条的处理时间,在线程池中基本还是300S,按道理总耗时应该更少的???????

@killme2008
Copy link
Owner

@rottle
return
null不是单线程处理,默认是CPU个数的线程做消息拉取,你在拉取线程跑,那就是至少cpu个线程在处理消息。这个可以通过ConsumerConfig.fetchRunnerCount设置。也就是拉取本身就是多线程的。

你的机器如果是4核,8核的,那跟你创建一个线程池跑不会有太大区别。也取决于你的任务类型,如果是CPU密集型,更多线程也不会带来提升,甚至可能下降。

在 2013年3月21日下午3:56,rottle notifications@github.com写道:

嗯。非常谢谢两位的回复。
可能我的描述不太清楚。举个例子吧。比如一次拉取6000条消息,getExecutor(){return
null}是采用单线程处理,共耗时300秒,即每条消息耗时50ms;同样,一次拉取6000条消息,如果通过getExecutor(){ return
pool},即返回一个线程池(固定大小8),共耗时应该小于300S,可能为200S。基于上述,消息吞吐量应该是提高了。@killme2008https://github.com/killme2008的回复,我清楚意思。
我的问题是:我经过测试发现,上述情况,6000条的处理时间,在线程池中基本还是300S,按道理总耗时应该更少的???????


Reply to this email directly or view it on GitHubhttps://github.com//issues/34#issuecomment-15223631
.

庄晓丹
Email: killme2008@gmail.com xzhuang@avos.com
Site: http://fnil.net
Twitter: @killme2008

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

3 participants