&是什么QUOT;高无意的上下文"开关是什么意思? [英] What does "high involuntary context" switches mean?
问题描述
我的重新编写在C code的一部分时使用的的getrusage(2) C API。
I have re-written a part of code in C. When testing it with logging the resource usage using getrusage(2) C API.
改变code之前:
user time (ms): 21503
system time (ms): 372
involuntary context switches: 20
变化后:
user time (ms): 25589
system time (ms): 80732
involuntary context switches: 821
我看到了很多非自愿的上下文切换
被在code我已经重新编写完成。
I see a lot of involuntary context switches
being done in the code I have re-written.
我的问题是不是的如何的减少上下文切换。但是..
My question is not about how to reduce context switches. But..
- 在非自愿上下文切换会发生什么情况都比较?
- 在什么样的方式会影响系统?
P.S:有是什么都没有写在磁盘上没有活动。它只是执行ping服务器几次。
P.S: There is no activity on the disk as nothing is being written. It just pings the server several times.
更新:
新增系统和用户花费时间。
Added system and user time taken.
程序是多线程的。线程(线程3K)的相同数量催生了两种情况。只有在C中的底层API被改写。
Program is multi-threaded. Same number of threads (3k thread) are spawned in both the cases. Only the underlying api in C is being rewritten.
推荐答案
每当一个线程/进程进行系统调用,则可能发生volontary上下文切换阻止。
A volontary context switch can occur whenever a thread/process makes a system call that blocks.
当一个线程已经未做系统调用运行块太长(通常类似于10毫秒),就会发生involontary上下文切换,并有等待CPU的进程。
An involontary context switch occurs when a thread has been running too long (usually something like 10 ms) without making a system call that blocks and there are processes waiting for the CPU.
它看起来像你的程序是更多的CPU密集现在比以前。如果你做了它的多线程则同比增长可能是预期。
It looks like your program is more CPU-intensive now than before. If you have made it multi-threaded then an increase is probably expected.
821上下文切换 - 这取决于你的程序的执行时间,这可能是也可能不是很多。
821 context switches - depending on the execution time of your program this may or may not be a lot.
如果你想减少上下文的数量开关可以减少工作线程的数量,以便有较少的线程之外还有CPU内核。
If you want to reduce the number of context switches you can reduce the number of worker threads so there are less threads than there are CPU cores.
更新
假设负载是在两种情况下是相同的,它看起来像code的修改都提高了CPU使用率。如果增加的负载是一个问题,你应该分析code,找到瓶颈。 仪表可在隔离有助于其code的一部分,是造成问题。
Assuming that the load is identical in both cases, it looks like the code modifications have increased the cpu usage. If the increased load is a concern you should analyse the code to find the bottleneck. Instrumentation can be helpful in isolating which part of the code is causing the problem.
这篇关于&是什么QUOT;高无意的上下文"开关是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!