Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: heavy time.Now usage cause taskgated to consume lots of cpu #15290

Open
davecheney opened this issue Apr 14, 2016 · 1 comment
Open
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin Performance
Milestone

Comments

@davecheney
Copy link
Contributor

davecheney commented Apr 14, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?

go version devel +bd72497 Mon Apr 11 01:52:10 2016 +0000 darwin/amd64

  1. What operating system and processor architecture are you using (go env)?

darwin/amd64

  1. What did you do?
    Run this program
package main

import (
        "fmt"
        "time"
)

func main() {
        t1 := time.Now().Add(-1 * time.Second) // ensure there is no collision on first iteration
        for {
                t2 := time.Now()
                d := t2.Sub(t1)
                if d == 0 {
                        fmt.Println("collision at", t2)
                }
                t1 = t2
        }
}
  1. What did you expect to see?

This program should cause 100% cpu usage.

  1. What did you see instead?

The program causes 100% cpu usage, but taskgated is also heavily used , around 20% on my system.

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man8/taskgated.8.html

Reports that taskgated is responsible for implemting the mach task_for_pid syscall (?), so it looks like we're calling this syscall many times, we should probably not do that and cache the task port once per process.

@AlekSi
Copy link
Contributor

AlekSi commented Apr 14, 2016

Can't verify it on OS X 10.11.4 with both 1.6.1 and devel +285e786. taskgated is nowhere near the top, dtruss doesn't show anything unexpected.

@bradfitz bradfitz added this to the Unplanned milestone Apr 14, 2016
@josharian josharian changed the title Heavy time.Now usage cause taskgated to consume lots of cpu runtime: heavy time.Now usage cause taskgated to consume lots of cpu Apr 14, 2016
@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 14, 2019
@rsc rsc removed their assignment Jun 23, 2022
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin Performance
Projects
None yet
Development

No branches or pull requests

6 participants