Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mapobj.IterBuffered performance question #57

Open
runner365 opened this issue Jul 26, 2017 · 0 comments
Open

mapobj.IterBuffered performance question #57

runner365 opened this issue Jul 26, 2017 · 0 comments
Labels

Comments

@runner365
Copy link

Hi, first of all. Thanks for the good map code for golang, we love it and use it in our project:
https://github.com/runner365/livego
and we find one question about IterBuffered performance in concurrent-map.
func (m ConcurrentMap) IterBuffered() <-chan Tuple {
chans := snapshot(m)
....
}
and in function snapshot:
func snapshot(m ConcurrentMap) (chans []chan Tuple) {
.....
for index, shard := range m {
go func(index int, shard *ConcurrentMapShared) {
// Foreach key, value pair.
shard.RLock()
chans[index] = make(chan Tuple, len(shard.items))
wg.Done()
for key, val := range shard.items {
chans[index] <- Tuple{key, val}
}
shard.RUnlock()
close(chans[index])
}(index, shard)
}
......
}
in function snapshot, There is a loop while run 32 goroutine each time, even if there are only one or two items in ConcurrentMap。And I think the 32 goroutine do not help to run faster.
When I use IterBuffered function in my project, it cost a lot of cpu even if there are a little number of item in c-map.
so I modify it:
func snapshot(m ConcurrentMap) (chans []chan Tuple) {
.....
for index, shard := range m {
go func(index int, shard *ConcurrentMapShared) {
// Foreach key, value pair.
shard.RLock()
chans[index] = make(chan Tuple, len(shard.items))
wg.Done()
for key, val := range shard.items {
chans[index] <- Tuple{key, val}
}
shard.RUnlock()
close(chans[index])
}(index, shard)
}
}
after modification the performance increase a lot(more than 50% in my project)
my fored site: https://github.com/runner365/concurrent-map
please let us know whether it's right to modify in the way above.
thanks again, and best regard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants