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: 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 ; 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: <6E200C29-67ED-4DB0-9DBD-4A87B74DC...@gmail.com> Date: Fri, 17 Aug 2012 13:49:30 -0300 Message-ID: Subject: Re: share a var between workers From: Nuba Princigalli 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 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
Hi Arjan,

Redis' been my "shared-mem= ory of choice" for quite some time, might want to check it out:
<= div>
* 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 <<= a href=3D"mailto:miyag...@gmail.com" target=3D"_blank">miyag...@gmail.com> wrote:
On Aug 17, 2012, at 6:04 AM, arjan wrote:
<= div>

If I use Star= man with this code:

=A0=A0=A0my $counter =3D 0;

=A0=A0=A0my $app =3D sub {
=A0= =A0=A0=A0=A0=A0=A0my $senv =A0=A0=A0=A0=A0=A0=A0=3D shift;
=A0=A0=A0=A0= =A0=A0=A0$counter++; =A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0return [ 200, [ = 9;Content-Type' =3D> 'text/html' ], [ "counter: $counte= r" ] ];
=A0=A0=A0};

Each worker gets it's own copy of $counter. The val= ue 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 me= chanism.


--
=A0
=A0
=A0

--047d7b15b175a168d204c778f1c9--