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
share a var between workers
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
arjan  
View profile  
 More options Aug 17 2012, 9:04 am
From: arjan <goo...@widlak.nl>
Date: Fri, 17 Aug 2012 06:04:01 -0700 (PDT)
Local: Fri, Aug 17 2012 9:04 am
Subject: share a var between workers

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?

Kind regards,
Arjan.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tatsuhiko Miyagawa  
View profile  
 More options Aug 17 2012, 12:41 pm
From: Tatsuhiko Miyagawa <miyag...@gmail.com>
Date: Fri, 17 Aug 2012 09:41:42 -0700
Local: Fri, Aug 17 2012 12:41 pm
Subject: Re: share a var between workers

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.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nuba Princigalli  
View profile  
 More options Aug 17 2012, 12:49 pm
From: Nuba Princigalli <n...@pauleira.com>
Date: Fri, 17 Aug 2012 13:49:30 -0300
Local: Fri, Aug 17 2012 12:49 pm
Subject: Re: share a var between workers

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:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
arjan  
View profile  
 More options Aug 19 2012, 6:51 pm
From: arjan <goo...@widlak.nl>
Date: Sun, 19 Aug 2012 15:51:58 -0700 (PDT)
Local: Sun, Aug 19 2012 6:51 pm
Subject: Re: share a var between workers

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:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tatsuhiko Miyagawa  
View profile  
 More options Aug 19 2012, 6:56 pm
From: Tatsuhiko Miyagawa <miyag...@gmail.com>
Date: Sun, 19 Aug 2012 15:56:01 -0700
Local: Sun, Aug 19 2012 6:56 pm
Subject: Re: share a var between workers

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:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
arjan  
View profile  
 More options Aug 20 2012, 4:57 am
From: arjan <goo...@widlak.nl>
Date: Mon, 20 Aug 2012 01:57:41 -0700 (PDT)
Local: Mon, Aug 20 2012 4:57 am
Subject: Re: share a var between workers

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:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »