Go to start multiple processes

I play with Go to understand its features and syntax. I made a simple producer-consumer program with parallel go functions and a priority buffer in the middle. One manufacturer creates tasks with a certain priority and sends them to the buffer using the channel. A set of consumers will request a task when it is idle, receives it, and consumes. The intermediate buffer will store a set of tasks in the priority queue buffer, therefore, tasks with the highest priority are performed first. The program also prints the activity of the garbage collector (how many times it was called and how long it took to collect the garbage).

I run it on a raspberry Pi using Go 1.1.

The software seems to be working fine, but I found that at the SO level, htop shows that there are 4 processes with the same memory usage, and the total CPU usage is more than 100% (Raspberry Pi has only one so I suppose this associated with threads / processes). In addition, the system load is about 7% of the processor, I believe, due to the constant context switching at the OS level. The GOMAXPROCS environment variable is set to 1 or not set.

Do you know why Go uses more than one OS process?

The code can be found here: http://pastebin.com/HJUq6sab

Thanks!

EDIT:

htop seems to show easy processes in the system. Go starts several such easy processes (they differ from goroutines threads), therefore when using htop several processes are shown, and ps or top will show only one, as it should be.

+4
source share
1 answer

Try to kill all suspicious processes and try to run it again only once. Also, do not use go run , at least for now, this is the minimum number of running processes.

I suspect that the other instances are just the remnants of your previous development attempts (probably called via go run and not correctly [indirectly] killed on SIGINT [hypothesis only]), especially because there is a 1-hour β€œtimeout” at the end "at the end of the" main "(instead of the correct synchronization or select{} ). Go bit code can spawn new threads, but it should never create new processes unless explicitly specified. This does not apply to your code - it does not even import "os / exec" or "syscall" in the first place.

If my assumption about the combination of go run and the use of a long timeout is really the culprit, then there may be some difference in the RP core from what the development guys use for testing.

+5
source

Source: https://habr.com/ru/post/1482796/


All Articles