memprofiler

memprofiler

Build Status codecov

Memprofiler helps to track memory allocations of your Go applications on large time intervals. Go runtime implements multiple memory management optimizations in order to achieve good performance, low heap allocation cost and high degree of memory reuse. Therefore, sometimes it may be tricky to distinguish “normal” runtime behaviour from real memory leak. If you have doubts whether your Go service is leaking, you’re on the right track. Memprofiler aims to be an open source equivalent of stackimpact.com.

Warning: The project is under active development and not ready for usage yet.

Getting started

Memprofiler is a client-server application. Memprofiler client is embedded into your Go service and streams memory usage reports to the Memprofiler server. Memprofiler server stores reports and performs some computations on the data stream to turn it in a small set of aggregated metrics. User will be able to interact with Memprofiler server via simple Web UI.

Components

Client

To use Memprofiler in your application, run client in your main function:

package example

import (
	"time"

	"github.com/sirupsen/logrus"

	"github.com/memprofiler/memprofiler/client"
	"github.com/memprofiler/memprofiler/schema"
	"github.com/memprofiler/memprofiler/utils"
)

func main() {
	// prepare client configuration
	cfg := &client.Config{
		// server address
		ServerEndpoint: "localhost:46219",
		// description of your application instance
		ServiceDescription: &schema.ServiceDescription{
			ServiceType:     "test_application",
			ServiceInstance: "node_1",
		},
		// granularity
		Periodicity: &utils.Duration{Duration: time.Second},
		// logging setting
		Verbose: false,
	}

	// you can implement your own logger
	log := client.LoggerFromLogrus(logrus.New())

	// run profiler and stop it explicitly on exit
	profiler, err := client.NewProfiler(log, cfg)
	if err != nil {
		panic(err)
	}
    profiler.Start()
	defer profiler.Quit()

	// ...
}

Server

To run Memprofiler server, just install it and prepare server config (you can refer to config example).

 ✗ GO111MODULE=on go get github.com/memprofiler/memprofiler
 ✗ memprofiler -c config.yml 
DEBU[0000] Starting storage                             
DEBU[0000] Starting metrics computer                    
INFO[0000] HTTP Frontend server resource                 URL=/schema.MemprofilerFrontend/GetSessions subsystem=frontend
INFO[0000] HTTP Frontend server resource                 URL=/schema.MemprofilerFrontend/GetServices subsystem=frontend
INFO[0000] HTTP Frontend server resource                 URL=/schema.MemprofilerFrontend/GetInstances subsystem=frontend
INFO[0000] HTTP Frontend server resource                 URL=/schema.MemprofilerFrontend/SubscribeForSession subsystem=frontend
INFO[0000] Starting service                              service=backend
INFO[0000] Starting service                              service=frontend
Visit original content creator repository https://github.com/memprofiler/memprofiler

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *