Git Product home page Git Product logo

autopprof's Introduction

autopprof

Run tests Release

Automatically profile the Go applications when CPU or memory utilization crosses specific threshold levels against the Linux container CPU quota and memory limit.

Once you start the autopprof, the autopprof process will periodically check the CPU and memory utilization of the Go applications. If the resource utilization crosses the specified threshold for each type of resource, the autopprof will automatically profile the application (heap or cpu) and report the profiling report to the specific reporter ( e.g. Slack).

CPU Profile Report Example Memory Profile Report Example
profiling example cpu profiling example mem

Installation

go get -u github.com/daangn/autopprof

Usage

If your application is running on non-linux systems, you should check the ErrUnsupportedPlatform error returned from autopprof.Start() and handle it properly.

package main

import (
	"errors"
	"log"

	"github.com/daangn/autopprof"
	"github.com/daangn/autopprof/report"
)

func main() {
	err := autopprof.Start(autopprof.Option{
		CPUThreshold: 0.8, // Default: 0.75.
		MemThreshold: 0.8, // Default: 0.75.
		Reporter: report.NewSlackReporter(
			&report.SlackReporterOption{
				App:     "YOUR_APP_NAME",
				Token:   "YOUR_TOKEN_HERE",
				Channel: "#REPORT_CHANNEL",
			},
		),
	})
	if errors.Is(err, autopprof.ErrUnsupportedPlatform) {
		// You can just skip the autopprof.
		log.Println(err)
	} else if err != nil {
		log.Fatalln(err)
	}
	defer autopprof.Stop()

	// Your code here.
}

You can create a custom reporter by implementing the report.Reporter interface.

Benchmark

Benchmark the overhead of watching the CPU and memory utilization. The overhead is very small, so we don't have to worry about the performance degradation.

You can run the benchmark test with this command.

./benchmark.sh
BenchmarkLightJob-5                    	49444164	       245.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkLightJobWithWatchCPUUsage-5   	48884026	       250.1 ns/op	       0 B/op	       0 allocs/op
BenchmarkLightJobWithWatchMemUsage-5   	49036617	       246.3 ns/op	       0 B/op	       0 allocs/op
BenchmarkHeavyJob-5                    	   59010	      203759 ns/op	       0 B/op	       0 allocs/op
BenchmarkHeavyJobWithWatchCPUUsage-5   	   58915	      204054 ns/op	       2 B/op	       0 allocs/op
BenchmarkHeavyJobWithWatchMemUsage-5   	   58850	      204764 ns/op	       2 B/op	       0 allocs/op

License

Apache 2.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.