为什么增加线程数没有用? [英] Why increasing number of threads is useless?

查看:62
本文介绍了为什么增加线程数没有用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找提高处理从rabbitmq 队列接收的消息的速度的方法.我发现的唯一方法是让多个线程做同样的事情——接收和处理.这给了我一些利润.创建 4 个线程后,速度翻了两番.因为我有 8 核处理器,所以我决定将线程数增加到 8.但这不会提高性能.YourKit 显示仅使用了 50% 的 CPU.有人可以说我的应用程序是轻量级的,所以确实如此,但我可以说它不能做比它做的更多的工作,不管我做了多少工作.为什么这不起作用?

I've been looking for the way to increase the speed of processing messages received from rabbitmq queue. The only way I've found is make more than one threads doing the same - receiving and processing. And this gave me some profit. After I created 4 threads the speed quadrupled. As I have 8-core processor I've decided to increase the number of threads to 8. But this gives no performance increasing. YourKit shows that only 50% of CPU is used. Somebody can say that my app is lightweight and so it is so, but I can say that it can't do more work than it does regardless I produce much more what to do. Why this doesn't work?

推荐答案

有许多不同的问题会限制给定系统上某些应用程序的最大速度.例如,它可能受到内存带宽、阿姆达尔定律效应的限制(非并行代码,包括同步块)、I/O 带宽和缓存空间.

There are many different issues that can constrain the maximum speed of some application on a given system. For example, it can be limited by memory bandwidth, by Amdahl's Law effects (time needed for non-parallel code, including synchronized blocks), I/O bandwidth, and cache space.

如果您想要进一步改进,您需要进行一些测量和分析,以找出时间的去向,然后继续努力.

If you want further improvement you need to do some measurements and profiling to find where the time is going, and then work on that.

这篇关于为什么增加线程数没有用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆