How to optimize golang

(*-*)浩
Release: 2019-12-31 09:49:59
Original
2520 people have browsed it

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无锁使用
Copy after login

# 2. Internet IO Performance Optimization

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!