Involuntary context switch refers to the context switch that occurs when the process is forced to be rescheduled by the system due to time slice has expired. For example, involuntary context switches are prone to occur when a large number of processes are competing for CPU.
A high context switch rate in the operating system (OS) signals that the OS is handling many different tasks and must alternate between them. In a DB2® system, this usually causes latch contention or the presence of many database connections. A slow down in SQL query performance can be the result.
A voluntary context switch occurs when a thread blocks because it requires a resource that is unavailable. An involuntary context switch takes place when a thread executes for the duration of its time slice or when the system identifies a higher-priority thread to run.
If it's close to 10% or higher, that means your OS is spending too much time doing the context switches.
I have re-written a part of code in C. When testing it with logging the resource usage using getrusage(2) C API.
Before changing the code:
user time (ms): 21503
system time (ms): 372
involuntary context switches: 20
After changing:
user time (ms): 25589
system time (ms): 80732
involuntary context switches: 821
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: There is no activity on the disk as nothing is being written. It just pings the server several times.
Update:
Added system and user time taken.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With