I don't know if this would have too much overhead, but why couldn't you
use a database?  For example, mysql commits writes to a linked list
cache, and if you are reading and writing as often as it sounds, your
reads probably won't ever hit the disk.  It waits as long as possible
before flushing to disk.

Having said that, the cost of your process startups may be high,
with ::DBI in every child.  Shrug.  I probably don't think enough before
I start coding, but you could whip something up pretty quick this way.
Is it Rob Pike that says "...tune for performance after you're done
coding, so you know where the bottleneck is..." or somesuch?

::IPC sounds pretty sane too...

Linc
>                                  From: 
>         zentara
>         <[EMAIL PROTECTED]>
>                                    To: 
>         beginners@perl.org
>                               Subject: 
>         Re: how to share variable
>         across multi-processes
>                                  Date: 
>         Wed, 01 Feb 2006 06:55:05 -0500
>         
>         On Tue, 31 Jan 2006 11:13:16 -0500 (EST),
>         [EMAIL PROTECTED] (Jeff
>         Pang) wrote:
>         
>         >hi,Zentara,
>         >I know little about perl's thread,so I am not certain to make
>         it run successfully under thread mode.
>         >In fact,my program is not complicated.It accept the following
>         data-line from about 200 clients:
>         >
>         >1_uee002##_01_100g836j:2048000:get
>         >
>         >and use these elements to build a hash:
>         >
>         >    my %records;
>         >    my ($mid,$size,$type) = split(/:/,$line);
>         >    my $timestamp = time();
>         >    $records{$mid}->{$timestamp}+=$size;
>         >
>         >When a request is coming,I want to fork a child process to
>         handle it.
>         >
>         >    my $child = fork();
>         >    die "can't fork:$!" unless defined $child;
>         >    if ($child==0)
>         >    {
>         >        do_something_to_hash();
>         >    }
>         >
>         >here,I want to modify the global hash %records in each
>         child.These modifications include insert,modify,or delete
>         items.
>         >
>         >Now I just use single process to resolve the problem,since I
>         have not get a way to get the variable be shared across
>         multi-processes.and,I watched that when the server have run
>         for one whole day,it used about 60M memory.
>         >
>         >Following Zentara and Chas's advices,I know there are at
>         least three ways to do that:
>         >
>         >1)Threads;
>         >2)IPC::Shareable;
>         >3)tie the hash to DBM,and write to local filesystem.
>         >
>         >I'll try those ways apartly.Thanks for all.
>         
>         There is another "tried-tested-and-true" method for handling
>         your IPC,
>         ....sockets.  To me, if you are forking from a parent, that
>         would be the
>         most solid way to do it.
>         
>         Set up a server in your parent to receive input on a certain
>         socket, say
>         13333(choose any unused socket).
>         
>         Then when you fork your clients, include socket code in them,
>         to connect
>         to 13333, and write their data to it. When the parent receives
>         the data,
>         process it somehow according to your needs.
>         
>         Socket code is the conventional way of doing IPC.
>         
>         The hardest part would be setting up a loop that both waits
>         for
>         incoming new connections, and receives data from existing
>         child processes. But there are many examples out there.
>         
>         
>         
>         
>         
>         
>         
>         
>         
>         
>         
>         
>         -- 
>         I'm not really a human, but I play one on earth.
>         http://zentara.net/japh.html
>         
> 
> 
> 
> 
> 
> 
> email message
> attachment
> (beginners_81076.ezm)
> 
>                                  From: 
>         Jeff Pang <[EMAIL PROTECTED]>
>                              Reply-To: 
>         Jeff Pang <[EMAIL PROTECTED]>
>                                    To: 
>         beginners@perl.org
>                               Subject: 
>         Re: how to share variable
>         across multi-processes
>                                  Date: 
>         Wed, 1 Feb 2006 07:47:50 -0500
>         (EST)
>         
>         hello,
>         You have misunderstood my meanings.
>         I fork the child process in socket server's parent process,and
>         the socket server accept the requests from socket
>         clients,which are distributed in about 200 different hosts.
>         I don't do the IPC communication of child-to-parent socket.:-)
>         
>         -----Original Message-----
>         >From: zentara <[EMAIL PROTECTED]>
>         >Sent: Feb 1, 2006 6:55 AM
>         >To: beginners@perl.org
>         >Subject: Re: how to share variable across multi-processes
>         >
>         >On Tue, 31 Jan 2006 11:13:16 -0500 (EST),
>         [EMAIL PROTECTED] (Jeff
>         >Pang) wrote:
>         >
>         >>hi,Zentara,
>         >>I know little about perl's thread,so I am not certain to
>         make it run successfully under thread mode.
>         >>In fact,my program is not complicated.It accept the
>         following  data-line from about 200 clients:
>         >>
>         >>1_uee002##_01_100g836j:2048000:get
>         >>
>         >>and use these elements to build a hash:
>         >>
>         >>    my %records;
>         >>    my ($mid,$size,$type) = split(/:/,$line);
>         >>    my $timestamp = time();
>         >>    $records{$mid}->{$timestamp}+=$size;
>         >>
>         >>When a request is coming,I want to fork a child process to
>         handle it.
>         >>
>         >>    my $child = fork();
>         >>    die "can't fork:$!" unless defined $child;
>         >>    if ($child==0)
>         >>    {
>         >>        do_something_to_hash();
>         >>    }
>         >>
>         >>here,I want to modify the global hash %records in each
>         child.These modifications include insert,modify,or delete
>         items.
>         >>
>         >>Now I just use single process to resolve the problem,since I
>         have not get a way to get the variable be shared across
>         multi-processes.and,I watched that when the server have run
>         for one whole day,it used about 60M memory.
>         >>
>         >>Following Zentara and Chas's advices,I know there are at
>         least three ways to do that:
>         >>
>         >>1)Threads;
>         >>2)IPC::Shareable;
>         >>3)tie the hash to DBM,and write to local filesystem.
>         >>
>         >>I'll try those ways apartly.Thanks for all.
>         >
>         >There is another "tried-tested-and-true" method for handling
>         your IPC,
>         >....sockets.  To me, if you are forking from a parent, that
>         would be the
>         >most solid way to do it.
>         >
>         >Set up a server in your parent to receive input on a certain
>         socket, say
>         >13333(choose any unused socket).
>         >
>         >Then when you fork your clients, include socket code in them,
>         to connect
>         >to 13333, and write their data to it. When the parent
>         receives the data,
>         >process it somehow according to your needs.
>         >
>         >Socket code is the conventional way of doing IPC.
>         >
>         >The hardest part would be setting up a loop that both waits
>         for
>         >incoming new connections, and receives data from existing
>         >child processes. But there are many examples out there.
>         >
>         >
>         >
>         >
>         >
>         >
>         >
>         >
>         >
>         >
>         >
>         >
>         >-- 
>         >I'm not really a human, but I play one on earth.
>         >http://zentara.net/japh.html
>         >
>         >-- 
>         >To unsubscribe, e-mail: [EMAIL PROTECTED]
>         >For additional commands, e-mail: [EMAIL PROTECTED]
>         ><http://learn.perl.org/>
>         <http://learn.perl.org/first-response>
>         >
>         >
>         
>         
>         --
>         Jeff Pang
>         NetEase AntiSpam Team
>         http://corp.netease.com
>         
-- 
ACHTUNG!!!

Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
-- 
ACHTUNG!!!

Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to