Skip to content

Instantly share code, notes, and snippets.

@aclements
Created July 18, 2017 20:03
Show Gist options
  • Save aclements/f7a770f9cb5682e038fe3f6ebd66bcba to your computer and use it in GitHub Desktop.
Save aclements/f7a770f9cb5682e038fe3f6ebd66bcba to your computer and use it in GitHub Desktop.
Plot GC pacer trigger error function
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"image/color"
"math"
"os"
"github.com/aclements/go-gg/gg"
"github.com/aclements/go-gg/table"
"github.com/aclements/go-moremath/vec"
)
func main() {
var xs, ys []float64
var fs []color.Color
for _, x := range vec.Linspace(0, 2, 200) {
for _, y := range vec.Linspace(0, 1, 200) {
xs = append(xs, x)
ys = append(ys, y)
fs = append(fs, cmap(triggerError(x, y)))
}
}
tab := new(table.Builder).Add("Heap completion ratio (h)", xs).Add("GC CPU (u_a)", ys).Add("fill", fs).Done()
plot := gg.NewPlot(tab)
plot.Add(gg.LayerTiles{Fill: "fill"})
plot.WriteSVG(os.Stdout, 400, 300)
}
func triggerError(completionFraction, utilization float64) float64 {
// The zero error is not affected by these parameters, but the
// scale of non-zero errors is.
const gcpercent = 100
goalGrowthRatio := float64(gcpercent) / 100
const gcGoalUtilization = 0.25
triggerRatio := .95
// Back out h_a from h, h_T, and h_g.
actualGrowthRatio := completionFraction*(goalGrowthRatio-triggerRatio) + triggerRatio
triggerError := goalGrowthRatio - triggerRatio - utilization/gcGoalUtilization*(actualGrowthRatio-triggerRatio)
return triggerError
}
func cmap(err float64) color.Color {
// TODO: Have a diverging color scale.
maxErr := 0.05
if err <= 0 {
v := uint8(255 * math.Max(1-(-err/maxErr), 0))
return color.NRGBA{255, v, v, 200}
} else {
v := uint8(255 * math.Max(1-(err/maxErr), 0))
return color.NRGBA{v, v, 255, 200}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment