Home>Article>Backend Development> How to optimize golang

How to optimize golang

(*-*)浩
(*-*)浩 Original
2019-12-31 09:49:59 2452browse

How to optimize golang

Common routines: asynchronous, de-locking, reuse, zero copy, batch, in addition to avoid premature optimization and optimize the business logic level first

1.cpu Time Optimization(Recommended Learning:Go)

make时提前预估size 临时的map、slice采用sync.Pool 大于32Kb也可用sync.Pool 不滥用goroutine,减少gc压力 不滥用mutex,减少上下文切换 []byte与string临时变量转换用unsafe 减少reflect、defer使用 atomic无锁使用

# 2. Internet IO Performance Optimization

批量接口支持 http 长连接 redis pipeline db、redis连接池 增加缓存 大量数据压缩传输

The above is the detailed content of How to optimize golang. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn