摘要
在云原生领域,大多数项目都是用Go语言开发的,而Go语言标准库中的Map又是开发过程中常用的内置数据结构。但是,在官方的设计中,Map并不是一种并发安全的数据类型。因此,该文首先介绍了Map的设计,分析了它不是并发安全的原因,其次论述了并发安全的Map的实现方式,包括加锁、Go官方的sync.Map以及自己通过分片加锁实现的方式,并设计了两大类实验,对这几种实现方式进行基准测试,最后根据测试结果进行了分析与技术选型的建议。
In the cloud-native field,most projects are developed in Golang,and the Map in the Golang standard library is a commonly used built-in data structure in the development process.However,in the official design,Map is not a data type of concurrent security.Therefore,this article introduces the design of Map,analyzes the reason why it is not concurrent security,next introduces the implementation of the Map of concurrent security,including locking,Go's official sync.Map and its own way of implementing it through shard locking,then designs two types of experiments to benchmark these implementations,and finally conducts the analysis and recommends technical selection based on test results.
作者
阮正平
蒋林峰
RUAN Zhengping;JIANG Linfeng(Aostar Information Technologies Co.,Ltd.,Chengdu,Sichuan Province,610041 China)
出处
《科技资讯》
2023年第14期22-27,共6页
Science & Technology Information