英文:
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
这里有两个独立的问题:
- Go语言的map性能如何?
可以在这个问题中找到答案:链接
- 50000个goroutine在竞争一个map上会有什么性能影响?
这听起来不是一个好主意,但如果没有进行基准测试,你就无法确定。如果你不依赖于立即写入map值的事实,你可以考虑通过带缓冲的通道异步发送map值。
你还可以查看解决类似问题的concurrent-map。
英文:
There are two separate issues here:
- What is the performance of a Go map?
An answer can be found in this issue
- 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论