Skip to content

Instantly share code, notes, and snippets.

@jwreagor
Created October 18, 2017 03:51
Show Gist options
  • Save jwreagor/87e4947790f18e63fd6f5613ea1941aa to your computer and use it in GitHub Desktop.
Save jwreagor/87e4947790f18e63fd6f5613ea1941aa to your computer and use it in GitHub Desktop.
debugging a possible memory leak
{
consul: "consul:8500",
jobs: [
{
name: "pjob",
port: 8080,
exec: "/bin/pjob start",
restarts: "unlimited",
health: {
exec: "curl --fail -s http://127.0.0.1:8080",
interval: 2,
ttl: 10,
timeout: "10s"
},
},
{
name: "watchedjob",
port: 3001,
exec: "tail -F",
health: {
exec: "true",
interval: 20,
ttl: 10
}
},
{
name: "send-sighup-a",
exec: "pkill -SIGHUP pjob",
when: {
source: "watch.watchedjob",
each: "changed"
}
},
],
watches: [
{
name: "watchedjob",
interval: 2
}
],
telemetry: {
port: 9090
}
}
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, world")
})
log.Println("listening on 8080...")
log.Fatal(http.ListenAndServe(":8080", nil))
}
#!/bin/bash
build() {
GOOS=linux GOARCH=amd64 go build -o pjob main.go
echo "FROM alpine:latest" > Dockerfile
echo "RUN apk --no-cache add curl bash" >> Dockerfile
docker build -t="leaky" .
}
run() {
run-consul
run-leaky
run-profiler
}
# ----------------------------------------
run-leaky() {
docker run -d \
--name leaky \
-p 6060:6060 \
--link leaky_consul:consul \
-v "$(pwd)/containerpilot:/bin/containerpilot" \
-v "$(pwd)/containerpilot.json5:/etc/containerpilot.json5" \
-v "$(pwd)/pjob:/bin/pjob" \
leaky \
/bin/containerpilot -config /etc/containerpilot.json5
}
run-consul() {
docker run -d \
--name leaky_consul \
-m 256m \
consul:latest \
agent -dev -client 0.0.0.0 -bind=0.0.0.0
}
run-profiler() {
mkdir -p profile
docker run -d \
--name leaky_profiler \
--link leaky:leaky \
-v "$(pwd)/profile:/profile" \
-v "$(pwd)/test.sh:/test.sh" \
leaky \
/test.sh do-profile
}
stop() {
docker rm -f leaky_consul
docker rm -f leaky
docker rm -f leaky_profiler
}
# ----------------------------------------
do-profile() {
while true; do
now=$(date +%s)
curl -so "/profile/heap-$now" "http://leaky:6060/debug/pprof/heap?debug=1"
sleep 60
done
}
cmd=$1
$cmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment