A question of groupcache

272 views
Skip to first unread message

Tw

unread,
Jul 31, 2013, 3:36:20 AM7/31/13
to golang-nuts
Hi all gophers,

Today I read groupcache src, and have a question in it:

In groupcache.go: *Group.load method, why it loads value from peers
firstly and then loads from local?

If we have the result in local (haven't in maincache yet), we don't need
to load from peers, just load it from local and populate it into maincache.

Is there somthing I misunderstanded or missed?

Brad Fitzpatrick

unread,
Aug 1, 2013, 7:15:16 PM8/1/13
to Tw, golang-nuts
The main entry point is called Get.

Get calls lookupCache (which sees if it's local already), and on miss calls load.

So load is only called if it's not local already.  Then it figures out which peer should be responsible for that key.  Only if it finds no peer, or that peer fails, does it then try to compute the answer locally.





--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Tw

unread,
Aug 1, 2013, 8:37:49 PM8/1/13
to Brad Fitzpatrick, golang-nuts
Assume the answer can be computed locally, but isn't in cache yet!
1) Get calls lookupCache -- failed
2) load from peers -- failed
3) compute the answer locally and put it in cache -- succeed

I think the step 2 should be after step 3 so the right sequence maybe 1
-> 3 -> 2.
> send an email to golang-nuts+unsubscribe@__googlegroups.com
> <mailto:golang-nuts%2Bunsu...@googlegroups.com>.
> For more options, visit https://groups.google.com/__groups/opt_out
> <https://groups.google.com/groups/opt_out>.
>
>
>

Brad Fitzpatrick

unread,
Aug 1, 2013, 8:39:01 PM8/1/13
to Tw, golang-nuts
Everything could be computed locally.

That doesn't mean it should be.

Tw

unread,
Aug 1, 2013, 8:41:12 PM8/1/13
to Brad Fitzpatrick, golang-nuts
But the overhead of loading from peer is higher than loading it locally

On Fri 02 Aug 2013 08:39:01 AM CST, Brad Fitzpatrick wrote:
> Everything could be computed locally.
>
> That doesn't mean it should be.
>
>
>
> On Thu, Aug 1, 2013 at 5:37 PM, Tw <tw198...@gmail.com
> <mailto:tw198...@gmail.com>> wrote:
>
> Assume the answer can be computed locally, but isn't in cache yet!
> 1) Get calls lookupCache -- failed
> 2) load from peers -- failed
> 3) compute the answer locally and put it in cache -- succeed
>
> I think the step 2 should be after step 3 so the right sequence
> maybe 1 -> 3 -> 2.
>
>
> On Fri 02 Aug 2013 07:15:16 AM CST, Brad Fitzpatrick wrote:
>
> The main entry point is called Get.
>
> Get calls lookupCache (which sees if it's local already), and
> on miss
> calls load.
>
> So load is only called if it's not local already. Then it
> figures out
> which peer should be responsible for that key. Only if it
> finds no
> peer, or that peer fails, does it then try to compute the
> answer locally.
>
>
>
> On Wed, Jul 31, 2013 at 12:36 AM, Tw <tw198...@gmail.com
> <mailto:tw198...@gmail.com>
> <mailto:tw198...@gmail.com <mailto:tw198...@gmail.com>>>
> wrote:
>
> Hi all gophers,
>
> Today I read groupcache src, and have a question in it:
>
> In groupcache.go: *Group.load method, why it loads value from
> peers firstly and then loads from local?
>
> If we have the result in local (haven't in maincache yet), we
> don't need to load from peers, just load it from local and
> populate it into maincache.
>
> Is there somthing I misunderstanded or missed?
>
> --
> You received this message because you are subscribed to
> the Google
> Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails
> from it,
> send an email to
> golang-nuts+unsubscribe@__goog__legroups.com
> <http://googlegroups.com>
> <mailto:golang-nuts%__2Buns...@googlegroups.com
> <mailto:golang-nuts%252Buns...@googlegroups.com>__>.
> For more options, visit
> https://groups.google.com/____groups/opt_out
> <https://groups.google.com/__groups/opt_out>

Kyle Lemons

unread,
Aug 1, 2013, 8:54:14 PM8/1/13
to Tw, Brad Fitzpatrick, golang-nuts
On Thu, Aug 1, 2013 at 5:41 PM, Tw <tw198...@gmail.com> wrote:
But the overhead of loading from peer is higher than loading it locally

That's not generally the sort of data that groupcache is intended to cache, then, I think.

To put a very fine point on it: If you have a number of servers that will have consistent hotspots and your data is expensive to compute (often because it must be retrieved remotely) and for which you want to avoid thundering herds, groupcache is for you.  If any of those is not the case, there are probably better solutions (e.g. memcache).
  
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Brad Fitzpatrick

unread,
Aug 1, 2013, 8:54:47 PM8/1/13
to Tw, golang-nuts
I don't think you're understanding the point of groupcache.

The network imposes some communication cost, but it's small.  Its relative size depends on the difficulty of computation, sure, but the network as a whole has more memory than your machine.





On Thu, Aug 1, 2013 at 5:41 PM, Tw <tw198...@gmail.com> wrote:

Tw

unread,
Aug 1, 2013, 8:59:19 PM8/1/13
to Brad Fitzpatrick, golang-nuts
Ah, Thanks Brad and Lemons, I understood it now.

On Fri 02 Aug 2013 08:54:47 AM CST, Brad Fitzpatrick wrote:
> I don't think you're understanding the point of groupcache.
>
> The network imposes some communication cost, but it's small. Its
> relative size depends on the difficulty of computation, sure, but the
> network as a whole has more memory than your machine.
>
>
>
>
>
> On Thu, Aug 1, 2013 at 5:41 PM, Tw <tw198...@gmail.com
> <mailto:tw198...@gmail.com>> wrote:
>
> But the overhead of loading from peer is higher than loading it
> locally
>
>
> On Fri 02 Aug 2013 08:39:01 AM CST, Brad Fitzpatrick wrote:
>
> Everything could be computed locally.
>
> That doesn't mean it should be.
>
>
>
> On Thu, Aug 1, 2013 at 5:37 PM, Tw <tw198...@gmail.com
> <mailto:tw198...@gmail.com>
> <mailto:tw198...@gmail.com>>>__>
>
> wrote:
>
> Hi all gophers,
>
> Today I read groupcache src, and have a question
> in it:
>
> In groupcache.go: *Group.load method, why it loads
> value from
> peers firstly and then loads from local?
>
> If we have the result in local (haven't in
> maincache yet), we
> don't need to load from peers, just load it from
> local and
> populate it into maincache.
>
> Is there somthing I misunderstanded or missed?
>
> --
> You received this message because you are
> subscribed to
> the Google
> Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving
> emails
> from it,
> send an email to
> golang-nuts+unsubscribe@__goog____legroups.com
> <http://goog__legroups.com>
> <http://googlegroups.com>
>
> <mailto:golang-nuts%____2Bun...@googlegroups.com
> <mailto:golang-nuts%25__2Bun...@googlegroups.com>
>
> <mailto:golang-nuts%__252Bunsubscribe@googlegroups.__com
> <mailto:golang-nuts%25252Bun...@googlegroups.com>>__>.
> For more options, visit
> https://groups.google.com/______groups/opt_out
> <https://groups.google.com/____groups/opt_out>
Reply all
Reply to author
Forward
0 new messages