473,473 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

PHP CLI & Forking children

I'm new to multi-process programming, should one avoid forking
children from children of a parent?

I'd like to spawn 10 children from the parent and each of those
children spawns another 5 children which process chunks of data (200
rows) with heavy usage of CPU and regexp

Sep 29 '07 #1
10 2155
On Sat, 29 Sep 2007 03:12:19 -0700, qw*******@googlemail.com wrote:
>I'm new to multi-process programming, should one avoid forking
children from children of a parent?

I'd like to spawn 10 children from the parent and each of those
children spawns another 5 children which process chunks of data (200
rows) with heavy usage of CPU and regexp
So you're spawning 500 processes? Do you have a very large number of CPUs to
run them on? Otherwise only a few will actually be running at any time, and
you'll be losing useful throughput to overhead, surely.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Sep 29 '07 #2
On Sep 29, 3:49 pm, Andy Hassall <a...@andyh.co.ukwrote:
So you're spawning 500 processes? Do you have a very large number of CPUs to
run them on? Otherwise only a few will actually be running at any time, and
you'll be losing useful throughput to overhead, surely.
Maybe the example I gave was bad :) How about PHP script with launches
4 children, with each child forking another 5 children (20 processes)

Would this development headaches or possible extra bugs?

Sep 29 '07 #3
qw*******@googlemail.com wrote:
On Sep 29, 3:49 pm, Andy Hassall <a...@andyh.co.ukwrote:
> So you're spawning 500 processes? Do you have a very large number of CPUs to
run them on? Otherwise only a few will actually be running at any time, and
you'll be losing useful throughput to overhead, surely.

Maybe the example I gave was bad :) How about PHP script with launches
4 children, with each child forking another 5 children (20 processes)

Would this development headaches or possible extra bugs?
Just wondering - why do you need to fork processes, anyway? There's a
lot of overhead in doing it, and if they're all CPU bound anyway you
aren't going to gain anything (unless you have a potload of CPU's).

Forking is good if you have different processes using different
resources. But when they have to contend for the same resource,
performance often goes down.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 29 '07 #4
On Sep 29, 7:51 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Just wondering - why do you need to fork processes, anyway? There's a
lot of overhead in doing it, and if they're all CPU bound anyway you
aren't going to gain anything (unless you have a potload of CPU's).

Forking is good if you have different processes using different
resources. But when they have to contend for the same resource,
performance often goes down.
Instead of writing a PHP script that downloads 2 million headers from
a newsgroup in a single connection (which will cause PHP to crash
anyway as it'll reach 500MB+ memory usage), I thought it would be
better to launch 4 processes do download it in chunks of 50,000
headers - with 4 connections to the same NNTP server.

Sep 29 '07 #5
On Sep 29, 8:32 pm, qwerty...@googlemail.com wrote:
Instead of writing a PHP script that downloads 2 million headers from
a newsgroup in a single connection (which will cause PHP to crash
anyway as it'll reach 500MB+ memory usage), I thought it would be
better to launch 4 processes do download it in chunks of 50,000
headers - with 4 connections to the same NNTP server.
I admit I should be using Perl or C for these tasks, but I know PHP
and I'm used to using its functions.

Sep 29 '07 #6
qw*******@googlemail.com wrote:
On Sep 29, 7:51 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Just wondering - why do you need to fork processes, anyway? There's a
lot of overhead in doing it, and if they're all CPU bound anyway you
aren't going to gain anything (unless you have a potload of CPU's).

Forking is good if you have different processes using different
resources. But when they have to contend for the same resource,
performance often goes down.

Instead of writing a PHP script that downloads 2 million headers from
a newsgroup in a single connection (which will cause PHP to crash
anyway as it'll reach 500MB+ memory usage), I thought it would be
better to launch 4 processes do download it in chunks of 50,000
headers - with 4 connections to the same NNTP server.
Which means you'll be downloading 500MB+ anyway - just in different
processes.

Or you could get some headers and cache them to disk, processing them later.

But which newsgroup has 2M+ headers? Glad I don't have to read that
one! :-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 29 '07 #7
qw*******@googlemail.com wrote:
On Sep 29, 8:32 pm, qwerty...@googlemail.com wrote:
>Instead of writing a PHP script that downloads 2 million headers from
a newsgroup in a single connection (which will cause PHP to crash
anyway as it'll reach 500MB+ memory usage), I thought it would be
better to launch 4 processes do download it in chunks of 50,000
headers - with 4 connections to the same NNTP server.

I admit I should be using Perl or C for these tasks, but I know PHP
and I'm used to using its functions.
Nothing wrong with using PHP for this. It will be slower than a
compiled language like C, but most of your time will be spent waiting on
I/O anyway. So it shouldn't be that much slower.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 29 '07 #8
On Sat, 29 Sep 2007 12:32:24 -0700, qw*******@googlemail.com wrote:
>On Sep 29, 7:51 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Just wondering - why do you need to fork processes, anyway? There's a
lot of overhead in doing it, and if they're all CPU bound anyway you
aren't going to gain anything (unless you have a potload of CPU's).

Forking is good if you have different processes using different
resources. But when they have to contend for the same resource,
performance often goes down.

Instead of writing a PHP script that downloads 2 million headers from
a newsgroup in a single connection (which will cause PHP to crash
anyway as it'll reach 500MB+ memory usage),
Well, presumably you're doing something with this data, like saving it to a
file or database? In which case you stream it from the network into the
database, rather than read it *all* into memory, and only *then* start saving
it?
>I thought it would be
better to launch 4 processes do download it in chunks of 50,000
headers - with 4 connections to the same NNTP server.
Yes, it may well be worth doing this to get better throughput (depending where
the bottleneck is), but I wouldn't have thought that the memory limit's the
issue, so long as you're streaming the data through.

I'm still not quite sure about the second level of forking you have in there
though; so there's 1 initial parent, 4 children reading from the server, but
then each has multiple children processing this data? Unless you have masses of
CPUs, you're unlikely to gain anything at that level; the 4 2nd level processes
may as well do the processing as they stream the data in from the network?

(As always, It Depends).
Back to the general question though, when you start forking, you've got child
process management to work out. One child process is relatively easy, more than
one means you have to do a bit more work to send (and receive) signals and
other IPC stuff (since you have to work out *which* child process you're
talking to), and work out what happens if either a child, or a parent process
terminates unexpectedly, or hangs. More than two processes and more than one
level of parent/child doesn't really get any more complicated as such, but
there's more processes to go wrong :-)

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Sep 29 '07 #9
Hello,

on 09/29/2007 07:12 AM qw*******@googlemail.com said the following:
I'm new to multi-process programming, should one avoid forking
children from children of a parent?

I'd like to spawn 10 children from the parent and each of those
children spawns another 5 children which process chunks of data (200
rows) with heavy usage of CPU and regexp
Here you may find several classes that can simplify that task for you:

http://www.phpclasses.org/php_fork

http://www.phpclasses.org/daemon

http://www.phpclasses.org/clsdaemonize

--

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
Oct 4 '07 #10
On Oct 4, 1:00 am, Manuel Lemos <mle...@acm.orgwrote:
Here you may find several classes that can simplify that task for you:

http://www.phpclasses.org/php_fork

http://www.phpclasses.org/daemon

http://www.phpclasses.org/clsdaemonize
Thanks Manuel for the good links.

Oct 4 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: sathia | last post by:
Hi, I have this table:   CREATE TABLE `osservatorio` (   `id` int(10) unsigned NOT NULL auto_increment,   `testo` varchar(255) NOT NULL default '',   `parent` int(11) default NULL,...
0
by: Eric S. Johansson | last post by:
I was working on a filter for postfix and instead of using the "fork a new python process on every message" route, I decided to use the SMTP interface instead and try forking after having started...
0
by: SRam | last post by:
I a writing Forking Server for a Small application.. This is code for multiplexing my $listen = IO::Socket::INET->new(Proto => 'tcp',LocalPort => 2323, Listen => 1, Reuse => 1) or die $!; ...
6
by: Otto Wyss | last post by:
I've the following function declaration: wxTree GetLastChild (const wxTree& item, long& cookie) const; I'd like to make the cookie parameter optional, i.e. "long& cookie = ....", without...
10
by: Immortalist | last post by:
Various aquisition devices that guide learning along particular pathways towards human biases. And as E.O. Wilson might say mental development appears to be genetically constrained. (1) Language...
13
by: CoreyWhite | last post by:
When playing games, perhaps the most simple is tic-tac-toe. The game has two simple strategies, one is defensive and the other offensive. It is not hard at first to learn how to tie games when...
2
by: Gilles Ganault | last post by:
Hello I'd like to rewrite the following Perl script in Python: http://www.voip-info.org/wiki/view/Asterisk+NetCID It seems like the following doesn't actually fork, so Asterisk is stuck...
2
by: harishashim | last post by:
I sure hope this question is relevent to comp.lang.c++ . I have my doubt but here I go! I have very code that do as follows pid_t pId = fork(); //Very large body of code codeline1();
3
by: Scottman | last post by:
I am writing a server daemon that forks a child for every incoming request. The child process terminates when the client closes the connection. My problem is that I am unsure how to prevent the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.