mirror of https://github.com/docker/docs.git
vendor: patch template init in trace pkg for performance
Temporarily include a fork of golang/net package that includes a performance patch. Measured performance gain is ~60ms for every `docker run` command. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
1fbdd354c2
commit
07fe6947a4
|
@ -20,7 +20,8 @@ clone git github.com/mattn/go-sqlite3 v1.1.0
|
||||||
clone git github.com/mistifyio/go-zfs v2.1.1
|
clone git github.com/mistifyio/go-zfs v2.1.1
|
||||||
clone git github.com/tchap/go-patricia v2.1.0
|
clone git github.com/tchap/go-patricia v2.1.0
|
||||||
clone git github.com/vdemeester/shakers 24d7f1d6a71aa5d9cbe7390e4afb66b7eef9e1b3
|
clone git github.com/vdemeester/shakers 24d7f1d6a71aa5d9cbe7390e4afb66b7eef9e1b3
|
||||||
clone git golang.org/x/net 47990a1ba55743e6ef1affd3a14e5bac8553615d https://github.com/golang/net.git
|
# forked golang.org/x/net package includes a patch for lazy loading trace templates
|
||||||
|
clone git golang.org/x/net 78cb2c067747f08b343f20614155233ab4ea2ad3 https://github.com/tonistiigi/net.git
|
||||||
clone git golang.org/x/sys eb2c74142fd19a79b3f237334c7384d5167b1b46 https://github.com/golang/sys.git
|
clone git golang.org/x/sys eb2c74142fd19a79b3f237334c7384d5167b1b46 https://github.com/golang/sys.git
|
||||||
clone git github.com/docker/go-units 651fc226e7441360384da338d0fd37f2440ffbe3
|
clone git github.com/docker/go-units 651fc226e7441360384da338d0fd37f2440ffbe3
|
||||||
clone git github.com/docker/go-connections v0.2.0
|
clone git github.com/docker/go-connections v0.2.0
|
||||||
|
|
|
@ -21,11 +21,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var eventsTmpl = template.Must(template.New("events").Funcs(template.FuncMap{
|
|
||||||
"elapsed": elapsed,
|
|
||||||
"trimSpace": strings.TrimSpace,
|
|
||||||
}).Parse(eventsHTML))
|
|
||||||
|
|
||||||
const maxEventsPerLog = 100
|
const maxEventsPerLog = 100
|
||||||
|
|
||||||
type bucket struct {
|
type bucket struct {
|
||||||
|
@ -101,7 +96,7 @@ func RenderEvents(w http.ResponseWriter, req *http.Request, sensitive bool) {
|
||||||
|
|
||||||
famMu.RLock()
|
famMu.RLock()
|
||||||
defer famMu.RUnlock()
|
defer famMu.RUnlock()
|
||||||
if err := eventsTmpl.Execute(w, data); err != nil {
|
if err := eventsTmpl().Execute(w, data); err != nil {
|
||||||
log.Printf("net/trace: Failed executing template: %v", err)
|
log.Printf("net/trace: Failed executing template: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -421,6 +416,19 @@ func freeEventLog(el *eventLog) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var eventsTmplCache *template.Template
|
||||||
|
var eventsTmplOnce sync.Once
|
||||||
|
|
||||||
|
func eventsTmpl() *template.Template {
|
||||||
|
eventsTmplOnce.Do(func() {
|
||||||
|
eventsTmplCache = template.Must(template.New("events").Funcs(template.FuncMap{
|
||||||
|
"elapsed": elapsed,
|
||||||
|
"trimSpace": strings.TrimSpace,
|
||||||
|
}).Parse(eventsHTML))
|
||||||
|
})
|
||||||
|
return eventsTmplCache
|
||||||
|
}
|
||||||
|
|
||||||
const eventsHTML = `
|
const eventsHTML = `
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"golang.org/x/net/internal/timeseries"
|
"golang.org/x/net/internal/timeseries"
|
||||||
)
|
)
|
||||||
|
@ -320,15 +321,20 @@ func (h *histogram) newData() *data {
|
||||||
|
|
||||||
func (h *histogram) html() template.HTML {
|
func (h *histogram) html() template.HTML {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
if err := distTmpl.Execute(buf, h.newData()); err != nil {
|
if err := distTmpl().Execute(buf, h.newData()); err != nil {
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
log.Printf("net/trace: couldn't execute template: %v", err)
|
log.Printf("net/trace: couldn't execute template: %v", err)
|
||||||
}
|
}
|
||||||
return template.HTML(buf.String())
|
return template.HTML(buf.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Input: data
|
var distTmplCache *template.Template
|
||||||
var distTmpl = template.Must(template.New("distTmpl").Parse(`
|
var distTmplOnce sync.Once
|
||||||
|
|
||||||
|
func distTmpl() *template.Template {
|
||||||
|
distTmplOnce.Do(func() {
|
||||||
|
// Input: data
|
||||||
|
distTmplCache = template.Must(template.New("distTmpl").Parse(`
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="padding:0.25em">Count: {{.Count}}</td>
|
<td style="padding:0.25em">Count: {{.Count}}</td>
|
||||||
|
@ -354,3 +360,6 @@ var distTmpl = template.Must(template.New("distTmpl").Parse(`
|
||||||
{{end}}
|
{{end}}
|
||||||
</table>
|
</table>
|
||||||
`))
|
`))
|
||||||
|
})
|
||||||
|
return distTmplCache
|
||||||
|
}
|
||||||
|
|
|
@ -232,7 +232,7 @@ func Render(w io.Writer, req *http.Request, sensitive bool) {
|
||||||
|
|
||||||
completedMu.RLock()
|
completedMu.RLock()
|
||||||
defer completedMu.RUnlock()
|
defer completedMu.RUnlock()
|
||||||
if err := pageTmpl.ExecuteTemplate(w, "Page", data); err != nil {
|
if err := pageTmpl().ExecuteTemplate(w, "Page", data); err != nil {
|
||||||
log.Printf("net/trace: Failed executing template: %v", err)
|
log.Printf("net/trace: Failed executing template: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -888,10 +888,18 @@ func elapsed(d time.Duration) string {
|
||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
var pageTmpl = template.Must(template.New("Page").Funcs(template.FuncMap{
|
var pageTmplCache *template.Template
|
||||||
"elapsed": elapsed,
|
var pageTmplOnce sync.Once
|
||||||
"add": func(a, b int) int { return a + b },
|
|
||||||
}).Parse(pageHTML))
|
func pageTmpl() *template.Template {
|
||||||
|
pageTmplOnce.Do(func() {
|
||||||
|
pageTmplCache = template.Must(template.New("Page").Funcs(template.FuncMap{
|
||||||
|
"elapsed": elapsed,
|
||||||
|
"add": func(a, b int) int { return a + b },
|
||||||
|
}).Parse(pageHTML))
|
||||||
|
})
|
||||||
|
return pageTmplCache
|
||||||
|
}
|
||||||
|
|
||||||
const pageHTML = `
|
const pageHTML = `
|
||||||
{{template "Prolog" .}}
|
{{template "Prolog" .}}
|
||||||
|
|
Loading…
Reference in New Issue