写go的一些经验
如果你的服务依赖其他的服务接口,在条件允许的时候,建议 依赖服务的接口 nginx层关闭gzip。
因为对应开启了gzip的接口,ioutil.ReadAll
读取内容时,会调用gzip进行数据解压,在高qps的时候,会消耗比较高的io
如果不能修改nginx层,那么可以 通过设置header 来 Accept-Encoding: 0
来禁止nginx自动gzip。 【标准http服务器都支持。】
具体协议见: https://tools.ietf.org/html/rfc2616#section-14.2
建议使用 github.com/json-iterator/go 代替原生 json 进行json序列化和反序列化, 在qps较高时,json的序列化和反序列化 比较耗io,如有可能,使用
protocol buffer 做服务间的数据传输协议,取代json
尽量使用 strings.Join
或 strings.Builder
减少内存重新分配
To Windows from macOS
brew install mingw-w64.
CGO_ENABLED=1 CXX=x86_64-w64-mingw32-g++ CC=x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64 go build
To Windows from debian or ubuntu
sudo apt-get install gcc-mingw-w64
CGO_ENABLED=1 CXX=x86_64-w64-mingw32-g++ CC=x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64 go build