summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.build.yml9
-rw-r--r--cmd/home/main.go9
-rw-r--r--posts/001.md9
-rw-r--r--posts/003.md19
-rw-r--r--templates/index.html14
-rw-r--r--templates/layouts/default.html24
-rw-r--r--templates/layouts/header.html7
-rw-r--r--templates/post.html3
8 files changed, 72 insertions, 22 deletions
diff --git a/.build.yml b/.build.yml
new file mode 100644
index 0000000..86f5b9d
--- /dev/null
+++ b/.build.yml
@@ -0,0 +1,9 @@
+image: debian/stable
+packages:
+ - go
+ - docker
+sources:
+ - https://git.sr.ht/~a73x/home
+tasks:
+ - setup: |
+ make public \ No newline at end of file
diff --git a/cmd/home/main.go b/cmd/home/main.go
index 01bddee..5a4573f 100644
--- a/cmd/home/main.go
+++ b/cmd/home/main.go
@@ -77,8 +77,15 @@ func GeneratePosts(mux *http.ServeMux) ([]PostData, error) {
return nil, fmt.Errorf("failed to read post template: %v", err)
}
+ type IPostData struct {
+ Title string
+ Post string
+ }
mux.HandleFunc("/posts/"+postName, func(w http.ResponseWriter, r *http.Request) {
- if err := foo.ExecuteTemplate(w, "post.html", string(content)); err != nil {
+ if err := foo.ExecuteTemplate(w, "post.html", IPostData{
+ Title: meta["title"],
+ Post: string(content),
+ }); err != nil {
fmt.Println(err)
}
})
diff --git a/posts/001.md b/posts/001.md
index 9942c2f..71ece5b 100644
--- a/posts/001.md
+++ b/posts/001.md
@@ -1,26 +1,25 @@
---
title: "Go Benchmarking"
---
-## Benchmarking
1. write a benchmark
2. run a benchmark
3. get a profile
4. optimise
5. run your tests
6. goto 2.
-### cpuprofile
+## cpuprofile
`go test -test=XXX -bench <regex> -cpuprofile <file>`
-### memprofile
+## memprofile
`go test -test=XXX -bench <regex> -memprofile <file> -benchmem`
-### pprof
+## pprof
[pprof usage](https://github.com/google/pprof/blob/main/doc/README.md)
`go pprof -http=:8080 profile.pb.gz`
will show a web UI for analysing the profile.
-#### views:
+### views:
- flame graph: `localhost:8080/ui/flamegraph`
- shows percentage breakdown of how much resource each "call" made.
- clicking a box will make it "100%" allowing for deep diving
diff --git a/posts/003.md b/posts/003.md
new file mode 100644
index 0000000..690b215
--- /dev/null
+++ b/posts/003.md
@@ -0,0 +1,19 @@
+---
+title: "Levels of Optimisation"
+---
+This probably isn't strictly true, but it makes sense to me.
+We've got three levels of "optimisation" (assuming your actual design doesn't suck and needs optimising).
+
+## Benchmark Optimisation
+To begin with, we have benchmark optimisation; you create a benchmark locally, dump a profile of it, and optimise it. Then, you run your tests because the most optimal solution is "return nil" and make sure you didn't break your tests.
+This is the first and easiest optimisation because it only requires a function, nothing else, and can be done in isolation. You don't need a working "application" here, just the function you're trying to benchmark. There are different types of benchmarks, micro, macro, etc., but I'm leaving them out of scope for this conversation. Go read [Efficient Go](https://learning.oreilly.com/library/view/efficient-go/9781098105709/).
+
+## Profile guided optimisation
+This is a mild step up from benchmark optimisation only because you need a live server load from which you use to pull a profile, but it is probably the most hands-off step. You import the `net/http/pprof` package into your service, call the `debug/profile?seconds=30` to get a profile, and compile your binary with `go build -pgo=profile.pgo`. The compiler will make optimisations for you, and even if your profile is garbage, it shouldn't cause any regressions.
+
+You probably want to get a few profiles and merge them using `go tool pprof -proto a.out b.out > merged`. This will help provide optimisations that are more relevant to your overall system; instead of just a single 30s slice.
+Also, if you have long-running calls that are chained together, a 30-second snapshot might not be enough, so try a sample with a longer window.
+
+## Runtime optimisation
+This is where you expose `/runtime/metrics` and monitor them continuously. There's a list of metrics that you might be interested in, a recommended set of metrics, and generally, you are looking to optimise your interactions with the go runtime. There are a few stats here: goroutine counts, goroutines waiting to run, heap size, how often garbage collection runs, how long garbage collection takes, etc. All useful information to use when optimising - when garbage collection is running, your program ain't. It's also useful for finding memory leaks; it becomes pretty obvious you are leaking goroutines when you graph the count and just watch it go up and never down.
+It's also just lowkey fun to look at the exposed data and understand what your system is doing. \ No newline at end of file
diff --git a/templates/index.html b/templates/index.html
index 8f07cc0..e84a09e 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -5,7 +5,7 @@
<li>lang: go</li>
<li>infra: kubernetes</li>
</ul>
- <h2>daily learnings</h2>
+ <h2>tidbits</h2>
<h3>#go</h3>
<ul>
<li>layout packages by what they do, not by their abstract type</li>
@@ -19,15 +19,25 @@
</li>
<li>don't use <code>init()</code></li>
<li>TFBO (test, fix, benchmark, optimise)</li>
+ <li>more CPU != more performance
+ <br/>
+ more CPU == more Contention
+ </li>
</ul>
<h3>#git</h3>
<ul>
- <li><code>git commit --fixup=&lt;COMMITSH&gt;</code>
+ <li><code>git reflog</code></li>
+ <li><code>git commit --fixup=&lt;COMMITISH&gt;</code>
<br />
<code>git rebase origin/main --autosquash</code>
</li>
</ul>
+ <h2>resources</h2>
+ <ul>
+ <li><a href=https://cs.opensource.google/go/go/+/refs/tags/go1.23.0:src/runtime/proc.go><code>proc.go</code></a></li>
+ <li><a href=https://github.com/golang/go/issues/67120>proposal: runtime/metrics: define a recommended set of metrics</a></li>
+ </ul>
<h2>books</h2>
<ul>
<li><a href=https://www.oreilly.com/library/view/designing-data-intensive-applications/9781491903063 />Designing
diff --git a/templates/layouts/default.html b/templates/layouts/default.html
index b12c520..8275843 100644
--- a/templates/layouts/default.html
+++ b/templates/layouts/default.html
@@ -21,16 +21,18 @@
max-width: 70ch;
font-family: "Mono";
}
+
pre {
font-family: "Mono";
color: crimson;
background-color: #f1f1f1;
padding: 2px;
- }
- pre code {
- background: none;
- }
+ }
+
+ pre code {
+ background: none;
+ }
code {
font-family: "Mono";
@@ -51,9 +53,19 @@
</head>
<body>
- {{ template "header.html" . }}
+ <h1>a73x</h1>
+ <nav>
+ <ul>
+ <li><a href="/">home</a></li>
+ <li><a href="/posts.html">posts</a></li>
+ </ul>
+ </nav>
{{ template "content" . }}
+ <footer>
+ <br />​<hr />​​​​​​​​​​​​​​​​​​​<br />​​​​​
+ <p>see something you disagree with? Email: <a href="mailto:[email protected]">[email protected]</a></p>
+ </footer>
</body>
</html>
-{{end}}
+{{end}} \ No newline at end of file
diff --git a/templates/layouts/header.html b/templates/layouts/header.html
deleted file mode 100644
index f1d2d18..0000000
--- a/templates/layouts/header.html
+++ /dev/null
@@ -1,7 +0,0 @@
-<h1>a73x</h1>
-<nav>
- <ul>
- <li><a href="/">home</a></li>
- <li><a href="/posts.html">posts</a></li>
- </ul>
-</nav>
diff --git a/templates/post.html b/templates/post.html
index 69c17e2..0a6cc6e 100644
--- a/templates/post.html
+++ b/templates/post.html
@@ -1,5 +1,6 @@
{{template "base" .}}
{{define "content"}}
-{{ . }}
+<h1>{{.Title}}</h1>
+{{ .Post }}
{{end}}