Skip to content

Instantly share code, notes, and snippets.

@sanposhiho
Last active June 7, 2020 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanposhiho/1a8a9e93ed9eabc5fea3145dbfb210a0 to your computer and use it in GitHub Desktop.
Save sanposhiho/1a8a9e93ed9eabc5fea3145dbfb210a0 to your computer and use it in GitHub Desktop.
Cheat Sheet on Performance Tuning

Set up!

Go 1.13

pprof

app.go

import (
+        _ "net/http/pprof"

...


func main() {
+        go func() {
+                log.Println(http.ListenAndServe("localhost:6060", nil))
+        }()
#bench回す
$ go tool pprof http://localhost:6060/debug/pprof/profile?seconds=60
Fetching profile over HTTP from http://localhost:6060/debug/pprof/profile?seconds=60
Saved profile in /home/isucon/pprof/pprof.isubata.samples.cpu.001.pb.gz
File: isubata
Type: cpu
Time: Jun 5, 2020 at 10:54am (UTC)
Duration: 1mins, Total samples = 4.76s ( 7.93%)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) peek main. -cum

https://christina04.hatenablog.com/entry/golang-pprof-basic

alp

$ wget https://github.com/tkuchiki/alp/releases/download/v0.3.1/alp_linux_amd64.zip
$ sudo apt-get install unzip
$ unzip alp_linux_amd64.zip
$ mv alp /usr/local/bin/

/etc/nginx/nginx.conf

http {

        ##
        # Logging Settings
        ##

    log_format ltsv "time:$time_local"
                "\thost:$remote_addr"
                "\tforwardedfor:$http_x_forwarded_for"
                "\treq:$request"
                "\tstatus:$status"
                "\tmethod:$request_method"
                "\turi:$request_uri"
                "\tsize:$body_bytes_sent"
                "\treferer:$http_referer"
                "\tua:$http_user_agent"
                "\treqtime:$request_time"
                "\tcache:$upstream_http_x_cache"
                "\truntime:$upstream_http_x_runtime"
                "\tapptime:$upstream_response_time"
                "\tvhost:$host";

        access_log /var/log/nginx/access.log ltsv;
$ sudo systemctl restart nginx.service
# bench回してlog溜める
$ sudo alp -f /var/log/nginx/access.log
$ sudo alp -f /var/log/nginx/access.log --sum -r #SUMの降順

https://muttan1203.hatenablog.com/entry/how_to_setup_alp

pt-query-digest

$ wget https://www.percona.com/downloads/percona-toolkit/2.2.17/deb/percona-toolkit_2.2.17-1.tar.gz
$ tar xf percona-toolkit_2.2.17-1.tar.gz
$ cd percona-toolkit-2.2.17
$ sudo perl Makefile.PL && sudo make && sudo make install

https://thinkit.co.jp/article/9617

/etc/mysql/mysql.conf.d/mysqld.cnf

[mysqld]
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 0 
log_queries_not_using_indexes = 1 # index使ってないクエリを出力
$ sudo systemctl restart mysql
$ sudo systemctl restart isubata.golang.service
$ sudo pt-query-digest --limit 10 /var/log/mysql/slow.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment