zephinzer / godev

Golang development tool that supports project bootstrap, live-reload (tests + application), and auto dependency retrieval based on Go Modules
https://getgo.dev
MIT License
198 stars 30 forks source link

Crazy CPU usage on Mac (edit: also inside Docker container) #39

Open fishnux opened 5 years ago

fishnux commented 5 years ago

Hi,

I'm trying godev for the first time. It looks like the godev process is generating an astounding load on the CPU (over 1.00). I wonder if you have an infinite loop somewhere?

Edit: Also happens inside a Docker container

crabmusket commented 5 years ago

I've just started running godev through Docker (using the zephinzer/godev:go-1.12 image) and I am seeing the same thing!

zephinzer commented 5 years ago

Thanks for the report! I will look into this-

zephinzer commented 5 years ago

Seems like there's a channel leak at handleStart, after doing 4 live-reloads, the following appears in the profiling:

goroutine profile: total 17
5 @ 0x42d72b 0x42d7d3 0x404e0d 0x404be5 0x753473 0x45ab61
#   0x753472    main.(*Command).handleStart+0x62    /REDACTED/godev/command.go:220
crabmusket commented 5 years ago

I previously wrote some code to watch files in a similar manner, and found it burned CPU like this, until I added a sleep to each watch loop. I tried doing so in all the loops I could find, but it didn't seem to reduce the CPU usage :/

EDIT: there are actually several more for { loops than the one that I added to in that commit. I thought I'd fixed all of them - maybe I never committed those changes. But you get the idea.

zephinzer commented 5 years ago

Thanks for investigating @crabmusket, I’m seeing if I can rewrite some parts to use channels in a more “go” way, realised I may have done some things wrongly after attending a workshop that covers these sort of things!