diff options
author | Brad Fitzpatrick <bradfitz@golang.org> | 2015-04-10 15:59:06 +0200 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2015-04-13 07:08:00 +0000 |
commit | dc2d64bf81b3342d35bdbfa42b971087ade6dfc6 (patch) | |
tree | 12c319c62687e90880ec7f6d2ecfd7ff96af5870 /src/net/lookup.go | |
parent | d1af6bed847291599985e85a8fbf207b6f0342a6 (diff) | |
download | go-dc2d64bf81b3342d35bdbfa42b971087ade6dfc6.tar.gz go-dc2d64bf81b3342d35bdbfa42b971087ade6dfc6.zip |
cmd/go: cache results of HTTP requests done during meta tag discovery
Previously, running
$ go get -u -v golang.org/x/tools/cmd/godoc
would results in dozens of HTTP requests for
https://golang.org/x/tools?go-get=1
once per package under x/tools.
Now it caches the results. We still end up doing one HTTP request for
all the packages under x/tools, but this reduces the total number of
HTTP requests in ~half.
This also moves the singleflight package back into an internal
package. singleflight was originally elsewhere as a package, then got
copied into "net" (without its tests). But now that we have internal,
put it in its own package, and restore its test.
Fixes #9249
Change-Id: Ieb5cf04fc4d0a0c188cb957efdc7ea3068c34e3f
Reviewed-on: https://go-review.googlesource.com/8727
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/net/lookup.go')
-rw-r--r-- | src/net/lookup.go | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/net/lookup.go b/src/net/lookup.go index be4b0c2df6..5adcd8bb68 100644 --- a/src/net/lookup.go +++ b/src/net/lookup.go @@ -4,7 +4,10 @@ package net -import "time" +import ( + "internal/singleflight" + "time" +) // protocols contains minimal mappings between internet protocol // names and numbers for platforms that don't have a complete list of @@ -39,7 +42,7 @@ func LookupIP(host string) (ips []IP, err error) { return } -var lookupGroup singleflight +var lookupGroup singleflight.Group // lookupIPMerge wraps lookupIP, but makes sure that for any given // host, only one lookup is in-flight at a time. The returned memory @@ -98,7 +101,7 @@ func lookupIPDeadline(host string, deadline time.Time) (addrs []IPAddr, err erro return nil, errTimeout case r := <-ch: - return lookupIPReturn(r.v, r.err, r.shared) + return lookupIPReturn(r.Val, r.Err, r.Shared) } } |