Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion share a var between workers

Received: by 10.42.167.72 with SMTP id r8mr2058273icy.15.1345222629476;
        Fri, 17 Aug 2012 09:57:09 -0700 (PDT)
X-BeenThere: psgi-plack@googlegroups.com
Received: by 10.50.178.73 with SMTP id cw9ls2323405igc.4.canary; Fri, 17 Aug
 2012 09:57:09 -0700 (PDT)
Received: by 10.50.12.234 with SMTP id b10mr1523093igc.1.1345222628987;
        Fri, 17 Aug 2012 09:57:08 -0700 (PDT)
Received: by 10.50.95.9 with SMTP id dg9msigb;
        Fri, 17 Aug 2012 09:49:31 -0700 (PDT)
Received: by 10.68.228.227 with SMTP id sl3mr887546pbc.5.1345222171145;
        Fri, 17 Aug 2012 09:49:31 -0700 (PDT)
Received: by 10.68.228.227 with SMTP id sl3mr887544pbc.5.1345222171092;
        Fri, 17 Aug 2012 09:49:31 -0700 (PDT)
Return-Path: <nuba...@gmail.com>
Received: from mail-pb0-f45.google.com (mail-pb0-f45.google.com [209.85.160.45])
        by gmr-mx.google.com with ESMTPS id vo7si469191pbc.1.2012.08.17.09.49.30
        (version=TLSv1/SSLv3 cipher=OTHER);
        Fri, 17 Aug 2012 09:49:30 -0700 (PDT)
Received-SPF: pass (google.com: domain of nuba...@gmail.com designates 209.85.160.45 as permitted sender) client-ip=209.85.160.45;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of nuba...@gmail.com designates 209.85.160.45 as permitted sender) smtp.mail=nuba...@gmail.com; dkim=pass header...@gmail.com
Received: by mail-pb0-f45.google.com with SMTP id rp12so3704978pbb.4
        for <psgi-plack@googlegroups.com>; Fri, 17 Aug 2012 09:49:30 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=mime-version:sender:in-reply-to:references:date
         :x-google-sender-auth:message-id:subject:from:to:content-type;
        bh=hDDsVRR0f5MNkkWGOTfaQOc8y3RlOS+tzzuQadCjEpU=;
        b=gYhTijPWmfl6fKFpn1ekvcrPEqN2aWq4+mrZQEYnws7SSO8GRbD8/vKi4YHfrIMiv7
         3gSA/BfgZbFPWDLPTaG/mdceRqWv3SdFWR1cRf88GCakgLbcfokX6ryLpJYQdAaHKSAg
         P/Vi12j3Hc4ilh1jNQvsQKwHFLk84Ha2i6lH0ioCcWDMInMF71/qjF+yvAe1bP+DzsPa
         VlGquAK3fk1LRxhxi+Fnz2Bt6GzkBiDfcT267J9tWHPsyioxPTHysrs1LtEKwjA88ijI
         4YHsrKd/Qpnd9UopY0y7pcE2pMNSqMKMBXM5pN54dPr+H8loWoAHFc1owa0DZ9EROCwR
         A4Og==
MIME-Version: 1.0
Received: by 10.68.200.8 with SMTP id jo8mr12765674pbc.148.1345222170732; Fri,
 17 Aug 2012 09:49:30 -0700 (PDT)
Sender: nuba...@gmail.com
Received: by 10.142.229.1 with HTTP; Fri, 17 Aug 2012 09:49:30 -0700 (PDT)
In-Reply-To: <6E200C29-67ED-4DB0-9DBD-4A87B74DC...@gmail.com>
References: <ab73020d-da6f-4f2e-9877-a5b046673e7f@googlegroups.com>
	<6E200C29-67ED-4DB0-9DBD-4A87B74DC...@gmail.com>
Date: Fri, 17 Aug 2012 13:49:30 -0300
Message-ID: <CAMGJnyubZKuPnxPyAGTzM0u0u+6ptdXsWCOGtiScwr6zYki...@mail.gmail.com>
Subject: Re: share a var between workers
From: Nuba Princigalli <n...@pauleira.com>
To: psgi-plack@googlegroups.com
Content-Type: multipart/alternative; boundary=047d7b15b175a168d204c778f1c9

--047d7b15b175a168d204c778f1c9
Content-Type: text/plain; charset=ISO-8859-1

Hi Arjan,

Redis' been my "shared-memory of choice" for quite some time, might want to
check it out:
* simple case http://redis.io/commands/incr
* with the counter in a hash http://redis.io/commands/hincrby

Have fun,

Nuba

On Fri, Aug 17, 2012 at 1:41 PM, Tatsuhiko Miyagawa <miyag...@gmail.com>wrote:

> On Aug 17, 2012, at 6:04 AM, arjan wrote:
>
> If I use Starman with this code:
>
>    my $counter = 0;
>
>    my $app = sub {
>        my $senv        = shift;
>        $counter++;
>        return [ 200, [ 'Content-Type' => 'text/html' ], [ "counter:
> $counter" ] ];
>    };
>
> Each worker gets it's own copy of $counter. The value of $counter depends
> on the worker serving the request.
>
> Would it be somehow possible to share a variable between workers?
>
>
> use memcache or some other shared memory mechanism.
>
>
>  --
>
>
>
>

--047d7b15b175a168d204c778f1c9
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div>Hi Arjan,</div><div><br></div><div>Redis&#39; been my &quot;shared-mem=
ory of choice&quot; for quite some time, might want to check it out:</div><=
div><div><div>* simple case <a href=3D"http://redis.io/commands/incr">http:=
//redis.io/commands/incr</a></div>
<div>* with the counter in a hash <a href=3D"http://redis.io/commands/hincr=
by">http://redis.io/commands/hincrby</a></div><div><div><br></div><div>Have=
 fun,</div><div><br></div><div>Nuba</div><div><br><div class=3D"gmail_quote=
">
On Fri, Aug 17, 2012 at 1:41 PM, Tatsuhiko Miyagawa <span dir=3D"ltr">&lt;<=
a href=3D"mailto:miyag...@gmail.com" target=3D"_blank">miyag...@gmail.com</=
a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0=
 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style=3D"word-wrap:break-word"><div><div class=3D"h5"><div><span style=
=3D"text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:-w=
ebkit-auto;font-style:normal;font-weight:normal;line-height:normal;border-c=
ollapse:separate;text-transform:none;font-size:medium;white-space:normal;fo=
nt-family:Helvetica;word-spacing:0px"><span style=3D"text-indent:0px;letter=
-spacing:normal;font-variant:normal;text-align:-webkit-auto;font-style:norm=
al;font-weight:normal;line-height:normal;border-collapse:separate;text-tran=
sform:none;font-size:medium;white-space:normal;font-family:Helvetica;word-s=
pacing:0px"><div style=3D"word-wrap:break-word">
<span style=3D"text-indent:0px;letter-spacing:normal;font-variant:normal;te=
xt-align:-webkit-auto;font-style:normal;font-weight:normal;line-height:norm=
al;border-collapse:separate;text-transform:none;font-size:medium;white-spac=
e:normal;font-family:Helvetica;word-spacing:0px"><span style=3D"text-indent=
:0px;letter-spacing:normal;font-variant:normal;text-align:-webkit-auto;font=
-style:normal;font-weight:normal;line-height:normal;border-collapse:separat=
e;text-transform:none;font-size:medium;white-space:normal;font-family:Helve=
tica;word-spacing:0px"><div style=3D"word-wrap:break-word">
<span style=3D"text-indent:0px;letter-spacing:normal;font-variant:normal;te=
xt-align:-webkit-auto;font-style:normal;font-weight:normal;line-height:norm=
al;border-collapse:separate;text-transform:none;font-size:medium;white-spac=
e:normal;font-family:Helvetica;word-spacing:0px"><div style=3D"word-wrap:br=
eak-word">
<span style=3D"text-indent:0px;letter-spacing:normal;font-variant:normal;te=
xt-align:-webkit-auto;font-style:normal;font-weight:normal;line-height:norm=
al;border-collapse:separate;text-transform:none;font-size:medium;white-spac=
e:normal;font-family:Helvetica;word-spacing:0px"><div style=3D"word-wrap:br=
eak-word">
<span style=3D"text-indent:0px;letter-spacing:normal;font-variant:normal;te=
xt-align:-webkit-auto;font-style:normal;font-weight:normal;line-height:norm=
al;border-collapse:separate;text-transform:none;font-size:medium;white-spac=
e:normal;font-family:Helvetica;word-spacing:0px"><div style=3D"word-wrap:br=
eak-word">
<div>On Aug 17, 2012, at 6:04 AM, arjan wrote:</div></div></span></div></sp=
an></div></span></div></span></span></div></span></span></div></div></div><=
div><div><div class=3D"h5"><br><blockquote type=3D"cite"><div>If I use Star=
man with this code:<br>
<br> =A0=A0=A0my $counter =3D 0;<br><br> =A0=A0=A0my $app =3D sub {<br> =A0=
=A0=A0=A0=A0=A0=A0my $senv =A0=A0=A0=A0=A0=A0=A0=3D shift;<br> =A0=A0=A0=A0=
=A0=A0=A0$counter++; =A0=A0=A0<br> =A0=A0=A0=A0=A0=A0=A0return [ 200, [ &#3=
9;Content-Type&#39; =3D&gt; &#39;text/html&#39; ], [ &quot;counter: $counte=
r&quot; ] ];<br>
 =A0=A0=A0};<br><br>Each worker gets it&#39;s own copy of $counter. The val=
ue of $counter depends on the worker serving the request. <br><br>Would it =
be somehow possible to share a variable between workers?<br></div></blockqu=
ote>
<div><br></div></div></div><div>use memcache or some other shared memory me=
chanism.</div></div><span class=3D"HOEnZb"><font color=3D"#888888"><br><div=
><br></div></font></span></div><span class=3D"HOEnZb"><font color=3D"#88888=
8">

<p></p>

-- <br>
=A0<br>
=A0<br>
=A0<br>
</font></span></blockquote></div><br></div></div></div></div>

--047d7b15b175a168d204c778f1c9--