性能优化:
CPU:
1去除不必要的序列化、反序列化;
2控制goroutine数量,避免goroutine泄露
3提升cpu利用率,使用中断机制让cpu以更少代价IO
内存:
1减少GC:减少string值拷贝,使用[]byte;string.stringbuilder
2struct类型字段顺序
3预分配内存:slice,map
4slice、map不保存指针类型
5使用原子化操作
disk:
减少磁盘随机读写io
工具
go tool pprof
go tool trace
go build -gcflags=”-m”
GODEBUG=”gctrace=1”
go get benchmark