Golang maps 的性能影响是什么?

huangapple go评论83阅读模式
英文:

what is the performance impact of golang maps

问题

在Go语言中,使用哈希表实现了映射(maps)。我正在使用sync包中的锁来读取和写入映射。如果有50,000个请求尝试访问该映射,是否会有性能影响?读取/写入映射的顺序是什么?它的时间复杂度是O(1)吗?

英文:

In golang, maps implemented using hash tables .I am using locks of sync package for readinng and writing in maps.
Is there any performance impact if 50,000 reqests try to access the map ?
What is the order of reading/writing maps?
Is it O(1)?

答案1

得分: 6

这里有两个独立的问题:

  1. Go语言的map性能如何?

可以在这个问题中找到答案:链接

  1. 50000个goroutine在竞争一个map上会有什么性能影响?

这听起来不是一个好主意,但如果没有进行基准测试,你就无法确定。如果你不依赖于立即写入map值的事实,你可以考虑通过带缓冲的通道异步发送map值。

你还可以查看解决类似问题的concurrent-map

英文:

There are two separate issues here:

  1. What is the performance of a Go map?

An answer can be found in this issue

  1. What are the performance implication of 50,000 goroutines contending on a map.

This doesn't sound like a good idea, but you can never know without benchmarking. You might want to consider sending the map values asynchronously through a buffered channel, if you don't depend on the fact that the map value would be written immediately.

You might also want to check out concurrent-map which is solving a similar problem.

huangapple
  • 本文由 发表于 2014年11月27日 16:56:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/27166552.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定