My small app executes within 400μs but the exit happens in about 0.16s

109 views
Skip to first unread message

Denis Cheremisov

unread,
Jul 4, 2020, 8:24:35 PM7/4/20
to golang-nuts
Hi!

I have a small app like


func main() {
    start := time.Now()

    …

    fmt.Println(time.Since(start))
}

where output is ≈400μs but the actual time is about 0.16s, I mean

$ time app-name 

real 0m0,156s
user 0m0,238s
sys 0m0,054s

Profiling collects nothing (it is expected with ≈400μs of course). Is there a method to detect what holds this for so long?

Kurtis Rader

unread,
Jul 4, 2020, 8:45:34 PM7/4/20
to Denis Cheremisov, golang-nuts
On Sat, Jul 4, 2020 at 5:24 PM Denis Cheremisov <denis.ch...@gmail.com> wrote:
I have a small app like

func main() {
    start := time.Now()
    …
    fmt.Println(time.Since(start))
}

where output is ≈400μs but the actual time is about 0.16s, I mean....

I can't reproduce and since it is really rare to see anyone report something like this it is most likely a quirk of your system. Also, when reporting issues of this nature you should include the go version and information about the platform such as the OS. I would start by using `strace -ttt -o strace.out app-name` to see if there are any syscalls that are taking longer than expected. If that doesn't reveal an obvious culprit then the time is probably external to your program.

--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

Denis Cheremisov

unread,
Jul 5, 2020, 8:33:04 AM7/5/20
to golang-nuts
Thank you, this helped a lot, strace showed there was a background activity looking for gopackgesdriver file. The problem was I had 

packages.Load(nil, "std")

in one of my modules run in an init(). Changed this piece into on-demand logic and now

real    0m0,010s
user    0m0,001s
sys 0m0,009s


воскресенье, 5 июля 2020 г., 3:45:34 UTC+3 пользователь Kurtis Rader написал:
Reply all
Reply to author
Forward
0 new messages