简体   繁体   English

运行许多IO线程是否会影响一些CPU密集型线程的性能?

[英]Does running many IO threads impact performance of a few CPU-intensive threads?

Let's say I have a 6-core machine with 12MB cache. 假设我有一台具有12MB​​缓存的6核计算机。 I use it for a server application that has a few gigabytes of heap (much of it 2nd level Hibernate cache). 我将其用于具有几GB堆(大部分是2级Hibernate缓存)的服务器应用程序。

I noticed that most of the time I have a handful threads actively serving client requests (burning CPU and talking to DB), as well as about 30-50 more threads that are only doing ol' good synchronous network IO with client. 我注意到大多数时候,我有少数几个线程在积极地服务于客户端请求(正在燃烧CPU和与DB通讯),以及大约30-50个以上的线程仅与客户端进行良好的同步网络IO。

As I am learning about Java memory model, I am wondering if this can impact performance. 在学习Java内存模型时,我想知道这是否会影响性能。 Does context switching for one of the many network IO threads ruin thread/CPU cache of the "active" threads? 许多网络IO线程之一的上下文切换是否会破坏“活动”线程的线程/ CPU缓存? Is this level of concurrency harmful in itself (memory cache aside)? 此级别的并发本身是否有害(不考虑内存缓存)?

Does it really matter, given how small the CPU cache is in relation to the whole application memory? 考虑到CPU缓存相对于整个应用程序内存有多小,这真的重要吗? How can I determine where the boundary is? 如何确定边界在哪里?

Does context switching for one of the many network IO threads ruin thread/CPU cache of the "active" threads? 许多网络IO线程之一的上下文切换是否会破坏“活动”线程的线程/ CPU缓存?

There are no hard guarantees, but my gut feeling is that, in practice, CPU caches get updated by order(s) of magnitude more frequently than the scheduler switches threads. 没有硬性保证,但是我的直觉是,在实践中,CPU缓存比数量级调度程序切换线程更频繁地按数量级进行更新。 If this is the case, then the cache update required by thread context switching is extremely small overhead compared to the cache updates that are going on already. 如果是这种情况,那么与已经进行的缓存更新相比,线程上下文切换所需的缓存更新的开销非常小。

How can I determine where the boundary is? 如何确定边界在哪里?

By experimenting and measuring (profiling), as is the case with most performance-related questions. 通过试验和测量(分析),与大多数与性能相关的问题一样。 Simple theoretical approximations won't work because the reality of what's really going on in a modern PC is more complex than any reasonable approximation. 简单的理论近似不会起作用,因为什么在现代PC 真的会在现实比任何合理的近似更复杂。

There will be an impact and you can get some jitter when you have more active threads than cpus. 这将产生影响,并且当活动线程多于cpus时,您可能会有些抖动。 However, the jitter is usually considered to be relatively small 10 to 100 micro-seconds. 但是,抖动通常被认为相对较小,为10到100微秒。

You can have the thread competing for cache resources, but there is not much you can do about it except reduce the amount of active data each thread uses. 您可以让线程争用缓存资源,但是除了减少每个线程使用的活动数据量之外,您无能为力。 This can reduce your cpu load by a factor of 2x or more, but involves alot of work, possibly a complete re-write (including some JDK and third party libraries) and it may yeild little benefit. 这可以将您的cpu负载减少2倍或更多倍,但是会涉及很多工作,可能需要完全重写(包括一些JDK和第三方库),并且收效甚微。 eg how much do you need the cpu load to be lower. 例如,您需要多少CPU负载才能降低。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM