groupcache icon indicating copy to clipboard operation
groupcache copied to clipboard

Group based PeerPicker

Open delphi329 opened this issue 9 years ago • 2 comments

Hi,

This is a question. The newGroup function is private func newGroup(name string, cacheBytes int64, getter Getter, peers PeerPicker) *Group

That means I can't pass my own PeerPicker when creating a group. As such, the default HttpPool's PeerPicker is used. Why is this restriction?

I may not understand groupchache correctly. If so correct me. My understanding is the default PeerPicker is portPicker in HttpPool. It uses consistenthash.Map to hash a string into groupcache peers, whether or not a particular peer has created a particular group or not. Suppose I have three processes running groupcache: p1, p2, and p3. And I have two groups: g1, g2. Assume we have the following peer to group mapping: p1: g1, g2 p2: g2, g3 p3: g1, g3

If in p2 if I call

g2 := groupcache.NewGroup("g2", 10<<20, g2Getter) g2.Get(ctx, "foo", groupcache.StringSink(&s))

and if "foo" is hashed to p3 where there is no group "g2" will that result in "foo" never cached?

I am adding peer/group auto discover with zookeeper, where grouphook will add itself to zk. Then a group based PeerPicker can be written to only hash the key to those peers that have the group. However, since newGroup with user defined picker is private, I can't find a way to set my own group based PeerPicker.

Thanks,

-John

delphi329 avatar Aug 21 '14 09:08 delphi329

I think the assumption is that all peers in the pool expose the same groups. Groups differ eventually in the application's perspective, only by the fetcher function.

So if you have different groups in the same program instance, all instances of the program should expose the same groups. And if these are not instances of the same program, you should have separate pools anyway (this is what I do, BTW).

dvirsky avatar Aug 21 '14 10:08 dvirsky

For those wondering, this pull request adds support for using different peers per group: https://github.com/golang/groupcache/pull/69

mdentonSkyport avatar Aug 03 '16 03:08 mdentonSkyport