Message from discussion
share a var between workers
Date: Mon, 20 Aug 2012 01:57:41 -0700 (PDT)
From: arjan <goo...@widlak.nl>
To: psgi-plack@googlegroups.com
Message-Id: <1f40e9af-0061-41e8-8c9f-9885ff22c529@googlegroups.com>
In-Reply-To: <1FF94BFC-2F86-4A0D-BDD3-494CD0F47BA9@gmail.com>
References: <ab73020d-da6f-4f2e-9877-a5b046673e7f@googlegroups.com> <6E200C29-67ED-4DB0-9DBD-4A87B74DC4DE@gmail.com> <CAMGJnyubZKuPnxPyAGTzM0u0u+6ptdXsWCOGtiScwr6zYkiWdw@mail.gmail.com> <f4445f55-b098-4920-a853-15159b926c6e@googlegroups.com>
<1FF94BFC-2F86-4A0D-BDD3-494CD0F47BA9@gmail.com>
Subject: Re: share a var between workers
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_48_29712760.1345453061701"
------=_Part_48_29712760.1345453061701
Content-Type: multipart/alternative;
boundary="----=_Part_49_25304467.1345453061701"
------=_Part_49_25304467.1345453061701
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Dear Tatsuhuko,
Thank you, I understand. So, I should be ok, with any non-forking solution,
like Twiggy.
Kind regards,
Arjan
Op maandag 20 augustus 2012 00:56:01 UTC+2 schreef Tatsuhiko Miyagawa het
volgende:
>
> Static data can be shared by initializing them on the parent process
> (inside your app, with --preload-app option) and then referenced safely via
> the workers, but you can't update the data in the parent without using some
> kind of IPC mechanism. It's not just a problem with Starman it's a generic
> thing with forking multi processes.
>
>
> --
> Tatsuhiko Miyagawa
>
>
>
> On Aug 19, 2012, at 3:51 PM, arjan wrote:
>
> Hi Nuba,
>
> Thanks, I know redis, it's really cool.
>
> But I'm not looking for anything database-like, I want to make a server that has a large hash of bit::vectors and serves information about that collection. Hence I need access to an instantiated variable with instantiated objects. The counter was just a simple example to demonstrate the problem with implementing this with starman.
>
> So I should either find out how to share it between workers, or I should find some single process solution perhaps.
>
> Kind regards,
> Arjan.
>
>
>
> Op vrijdag 17 augustus 2012 18:49:30 UTC+2 schreef Nuba Princigalli het
> volgende:
>>
>> 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 <miya...@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.
>>>
>>>
>>>
>>> --
>>>
>>>
>>>
>>>
>>
>>
> --
>
>
>
>
>
>
------=_Part_49_25304467.1345453061701
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Dear Tatsuhuko,<br><br>Thank you, I understand. So, I should be ok, with an=
y non-forking solution, like Twiggy.<br><br>Kind regards,<br>Arjan<br><br>O=
p maandag 20 augustus 2012 00:56:01 UTC+2 schreef Tatsuhiko Miyagawa het vo=
lgende:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.=
8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div style=3D"word-wrap=
:break-word">Static data can be shared by initializing them on the parent p=
rocess (inside your app, with --preload-app option) and then referenced saf=
ely via the workers, but you can't update the data in the parent without us=
ing some kind of IPC mechanism. It's not just a problem with Starman it's a=
generic thing with forking multi processes.<div><br></div><div><div><span =
style=3D"border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;fo=
nt-style:normal;font-variant:normal;font-weight:normal;letter-spacing:norma=
l;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform=
:none;white-space:normal;word-spacing:0px;font-size:medium"><span style=3D"=
border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:=
normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-he=
ight:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;whi=
te-space:normal;word-spacing:0px;font-size:medium"><div style=3D"word-wrap:=
break-word"><span style=3D"border-collapse:separate;color:rgb(0,0,0);font-f=
amily:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;le=
tter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:=
0px;text-transform:none;white-space:normal;word-spacing:0px;font-size:mediu=
m"><span style=3D"border-collapse:separate;color:rgb(0,0,0);font-family:Hel=
vetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spac=
ing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-=
transform:none;white-space:normal;word-spacing:0px;font-size:medium"><div s=
tyle=3D"word-wrap:break-word"><span style=3D"border-collapse:separate;color=
:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;fon=
t-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit=
-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0=
px;font-size:medium"><div style=3D"word-wrap:break-word"><span style=3D"bor=
der-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:nor=
mal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-heigh=
t:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-=
space:normal;word-spacing:0px;font-size:medium"><div style=3D"word-wrap:bre=
ak-word"><span style=3D"border-collapse:separate;color:rgb(0,0,0);font-fami=
ly:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;lette=
r-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px=
;text-transform:none;white-space:normal;word-spacing:0px;font-size:medium">=
<div style=3D"word-wrap:break-word"><div><br>--</div><div>Tatsuhiko Miyagaw=
a</div></div></span></div></span></div></span></div></span></span></div></s=
pan><br></span><br>
</div>
<br><div><div>On Aug 19, 2012, at 3:51 PM, arjan wrote:</div><br><blockquot=
e type=3D"cite"><pre>Hi Nuba,
Thanks, I know redis, it's really cool.=20
But I'm not looking for anything database-like, I want to make a server tha=
t has a large hash of bit::vectors and serves information about that collec=
tion. Hence I need access to an instantiated variable with instantiated obj=
ects. The counter was just a simple example to demonstrate the problem with=
implementing this with starman.=20
So I should either find out how to share it between workers, or I should fi=
nd some single process solution perhaps.
Kind regards,
Arjan.
</pre>
<br><br>Op vrijdag 17 augustus 2012 18:49:30 UTC+2 schreef Nuba Princig=
alli het volgende:<blockquote class=3D"gmail_quote" style=3D"margin:0;margi=
n-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Hi Arjan,</d=
iv><div><br></div><div>Redis' been my "shared-memory of choice" for quite s=
ome time, might want to check it out:</div><div><div><div>* simple case <a =
href=3D"http://redis.io/commands/incr" target=3D"_blank">http://redis.io/co=
mmands/incr</a></div>
<div>* with the counter in a hash <a href=3D"http://redis.io/commands/hincr=
by" target=3D"_blank">http://redis.io/commands/<wbr>hincrby</a></div><div><=
div><br></div><div>Have fun,</div><div><br></div><div>Nuba</div><div><br><d=
iv class=3D"gmail_quote">
On Fri, Aug 17, 2012 at 1:41 PM, Tatsuhiko Miyagawa <span dir=3D"ltr"><<=
a>miya...@gmail.com</a>></span> wrote:<br><blockquote class=3D"gmail_quo=
te" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"=
>
<div style=3D"word-wrap:break-word"><div><div><div><span style=3D"text-inde=
nt:0px;letter-spacing:normal;font-variant:normal;text-align:-webkit-auto;fo=
nt-style:normal;font-weight:normal;line-height:normal;border-collapse:separ=
ate;text-transform:none;font-size:medium;white-space:normal;font-family:Hel=
vetica;word-spacing:0px"><span style=3D"text-indent:0px;letter-spacing:norm=
al;font-variant:normal;text-align:-webkit-auto;font-style:normal;font-weigh=
t:normal;line-height:normal;border-collapse:separate;text-transform:none;fo=
nt-size:medium;white-space:normal;font-family:Helvetica;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"><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><br><blockquote type=3D"cite"><div>If I use Starman with this=
code:<br>
<br> my $counter =3D 0;<br><br> my $app=
=3D sub {<br> my $senv &nb=
sp; =3D shift;<br> &nb=
sp; $counter++; <br> &=
nbsp; return [ 200, [ 'Content-Type' =3D> 'text/html' ], [ "c=
ounter: $counter" ] ];<br>
};<br><br>Each worker gets it's own copy of $counter. Th=
e value of $counter depends on the worker serving the request. <br><br>Woul=
d it be somehow possible to share a variable between workers?<br></div></bl=
ockquote>
<div><br></div></div></div><div>use memcache or some other shared memory me=
chanism.</div></div><span><font color=3D"#888888"><br><div><br></div></font=
></span></div><span><font color=3D"#888888"><div><br></div>
-- <br>
<br>
<br>
<br>
</font></span></blockquote></div><br></div></div></div></div>
</blockquote><div><br></div>
-- <br>
<br>
<br>
<br>
</blockquote></div><br></div></div></blockquote>
------=_Part_49_25304467.1345453061701--
------=_Part_48_29712760.1345453061701--