Hi guys

Today while analyzing CPU usage of one of our processes written in go, I 
noticed that there were multiple threads associated with the process which 
is actually serial. (Doesn't make use of goroutines)
I wanted to know if it was the expected behaviour or some issue in our 
service.

So I tested the same with this snippet:
func main() {
    for {
    }
}


And to my surprise, even this ever running process had multiple threads 
associated with it:

➜  go build everRunningProgram.go
➜  ./everRunningProgram &
[1] 13745
➜  top -b -n 1 -H -p 13745       
top - 15:07:38 up  4:03,  1 user,  load average: 0.63, 0.80, 0.72
Threads:   5 total,   1 running,   4 sleeping,   0 stopped,   0 zombie
%Cpu(s):  4.9 us,  1.1 sy,  0.3 ni, 93.2 id,  0.0 wa,  0.0 hi,  0.5 si,  
0.0 st
KiB Mem : 16301396 total,  4780820 free,  5033472 used,  6487104 buff/cache
KiB Swap:        0 total,        0 free,        0 used. 10270784 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
13745 mani-86+  25   5  101856    764    584 R 99.9  0.0   0:10.38 
everRunningProg
13746 mani-86+  25   5  101856    764    584 S  0.0  0.0   0:00.00 
everRunningProg
13747 mani-86+  25   5  101856    764    584 S  0.0  0.0   0:00.00 
everRunningProg
13748 mani-86+  25   5  101856    764    584 S  0.0  0.0   0:00.00 
everRunningProg
13749 mani-86+  25   5  101856    764    584 S  0.0  0.0   0:00.00 
everRunningProg

I tried the same with other programming languages and they didn't seem to 
exhibit this behaviour.

*Rust:*
fn main() {
loop {}
}

➜  rustc everRunningProgram.rs
➜  ./everRunningProgram &
[2] 14265
➜  top -b -n 1 -H -p 14265
top - 15:11:36 up  4:07,  1 user,  load average: 1.59, 1.29, 0.95
Threads:   1 total,   1 running,   0 sleeping,   0 stopped,   0 zombie
%Cpu(s):  4.9 us,  1.1 sy,  0.5 ni, 93.0 id,  0.0 wa,  0.0 hi,  0.5 si,  
0.0 st
KiB Mem : 16301396 total,  4584980 free,  5132508 used,  6583908 buff/cache
KiB Swap:        0 total,        0 free,        0 used. 10111372 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
14265 mani-86+  25   5   13156    980    868 R 99.9  0.0   0:10.22 
everRunningProg

*C:*
int main() {
while(1);
}

➜  cc everRunningProgram.c 
➜  ./a.out &             
[3] 14413
➜  top -b -n 1 -H -p 14413
top - 15:14:34 up  4:10,  1 user,  load average: 2.43, 1.81, 1.22
Threads:   1 total,   1 running,   0 sleeping,   0 stopped,   0 zombie
%Cpu(s):  4.8 us,  1.1 sy,  0.8 ni, 92.7 id,  0.0 wa,  0.0 hi,  0.5 si,  
0.0 st
KiB Mem : 16301396 total,  4603696 free,  5098020 used,  6599680 buff/cache
KiB Swap:        0 total,        0 free,        0 used. 10134048 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
14413 mani-86+  25   5    4380    712    648 R 99.9  0.0   0:06.07 a.out

*Python:*
while True:
    pass

➜  scripts python3 everRunningProgram.py &
[4] 14587
➜  scripts top -b -n 1 -H -p 14587        
top - 15:16:35 up  4:12,  1 user,  load average: 4.08, 2.62, 1.59
Threads:   1 total,   1 running,   0 sleeping,   0 stopped,   0 zombie
%Cpu(s):  4.8 us,  1.1 sy,  1.1 ni, 92.5 id,  0.0 wa,  0.0 hi,  0.5 si,  
0.0 st
KiB Mem : 16301396 total,  4551664 free,  5146576 used,  6603156 buff/cache
KiB Swap:        0 total,        0 free,        0 used. 10082516 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
14587 mani-86+  25   5   33056   8736   5472 R 99.9  0.1   0:06.63 python3


Is there any explanation for this behaviour on Go?
What's really happening behind the scenes?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/a15cf939-02cb-4c51-af20-f0109ffe63df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to