Profiling memory usage of a Go app

net/http/pprof is a powerful package for profiling. This video introduces how to use it to do memory profiling. Let me write down the steps.

  1. Import the package in your go web project (it doesn’t have to be a web app). Just add this…

I created a docker container for a golang app, based on debian 7 image. Everything works well until it visits https. The error is x509: failed to load system roots and no roots provided.

I thought there might be something that should be configured for golang. But actually, it is nothing about golang. It’s about SSL certificates. For debian, /etc/ssl/certs/ca-certificates.crt is the root certificates. But the offical debian 7 image does not contain it. Installing ca-certificates via apt-get solved the problem. (You can manually copy /etc/ssl/certs/ca-certificates.crt from another linux OS too.)

Dockerfile:

FROM debian:7
RUN apt-get update \
&& apt-get install -y --force-yes --no-install-recommends \
apt-transport-https \
curl \
ca-certificates \
&& apt-get clean \
&& apt-get autoremove \
&& rm -rf /var/lib/apt/lists/*

Originally published at vinceyuan.github.io on September 8, 2015.

When you build Docker images many times, you will find it is very necessary to manage images with tags.

If you build an image without a tag, the default tag ‘latest’ is created automatically.

docker build -t company/myimage .

The complete name is company/myimage:latest

When you need to update a new version of company/myimage, you don't need to create an image company/myimage_v2. You should create an image with the same name and a new tag.

docker build -t company/myimage:v2 .

And set it latest

docker tag -f company/myimage:v2 company/myimage:latest

So your new image has two tags: v2 and latest. When you start a container based on company/myimage, company/myimage:latest will be used.

Originally published at vinceyuan.github.io on June 8, 2015.

Aijin Yuan (Vince)

iOS/Android/Web developer. UX engineering lead at Grab. Singapore/Hong Kong/Shanghai

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store