Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:35692 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50432 invoked by uid 1010); 21 Feb 2008 14:47:12 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 50416 invoked from network); 21 Feb 2008 14:47:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Feb 2008 14:47:12 -0000 Authentication-Results: pb1.pair.com smtp.mail=indeyets@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=indeyets@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 216.239.58.187 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: indeyets@gmail.com X-Host-Fingerprint: 216.239.58.187 gv-out-0910.google.com Received: from [216.239.58.187] ([216.239.58.187:39970] helo=gv-out-0910.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 06/0A-21621-DEE8DB74 for ; Thu, 21 Feb 2008 09:47:11 -0500 Received: by gv-out-0910.google.com with SMTP id s4so13354gve.37 for ; Thu, 21 Feb 2008 06:47:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=JYfZ7HEBkO9k24O8YoAwn/QlXgII3VQSTNpmO1MxfdY=; b=BF8xrNob2k3OpnvGTyw0x7RRPDNUUrryKoT6bbUc12Ph+cFy3A+EJaMM9Qwrr+XrtyDL1wxJzk9TRFqfFuvu10ki9XmcmeyA1Eg9Aw+J1KyRg5RL9ORGJ32TcmXhSRhMa6t9dS8yoBUpVj7+UM1KkgKRJB87Lu8rXOLpgdfXTgg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ijXeHdpvA0+mslOrC+m3McXwVMekxlqASIMyMEfQbgdvU2DxjUInTnfx77gzrwbBXFT4rC+Ppg0nXYJMw51vAOxmzK3UG1pb2w5GkjizqR+/QoXHUuZxCpHzWnu9Z+bgzWxb6HfcyyBSqydA9YS4hrmjw7QYHzUU5XAha7GKRVg= Received: by 10.150.215.16 with SMTP id n16mr3184246ybg.104.1203605222137; Thu, 21 Feb 2008 06:47:02 -0800 (PST) Received: by 10.150.57.12 with HTTP; Thu, 21 Feb 2008 06:47:02 -0800 (PST) Message-ID: Date: Thu, 21 Feb 2008 17:47:02 +0300 To: nrixham@gmail.com Cc: internals@lists.php.net In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <7A.50.10952.9A16DB74@pb1.pair.com> Subject: Re: [PHP-DEV] Multi-threading From: indeyets@gmail.com ("Alexey Zakhlestin") On 2/21/08, Nathan Rixham wrote: > Thankyou for taking the time to shed some light on the mater for me; I'd > missed the all vital "sharing resources" part of the concept, probably > because (if I'm correct in saying) php shares memory of > variables/classes/resources between parent and child processes until a > write occurs, at which point a new version of the aforementioned is > created. [please correct if wrong]. pcntl_fork() uses fork() call which is implemented in OS. Forked process is a copy of parent process, which means, that it occupies similiar amount of memory. Each time you "fork" your memory usage gets bigger > Would I therefore be correct in assuming the following: > > In PHP we can create mutli-process(tasking) applications that have most > of the benefits of multi-threaded applications and less bugs. > > I'm working on the premise that a processor can only run so fast, so > multithreading say 100k calculations would not speed up and application, > if anything it would add overhead, and slow it down. The only way to > speed up such an application would be to throw more hardware at the > problem (be it servers or processors). If your task is CPU-bound, you can't do much, but give it more hadrware. (we are not talking about optimization of algorithms here) > Meaning that the only time multi-process/multi-threading would have any > positive bearing on an application would be when dealing with things > such as external resources, due to the slower access times of these > external resources we find threads/processes "waiting" for the resource > to be usable (fully downloaded/opened) - in such a situation > multi-threading has it's distinct advantages. > > However forking an app (?multi-process) can already achieve the same > results, the only difference being that we may have a few duplicate > classes/variables around the application doing it this way (subject to > us not taking the time to define all "shared" resources in the parent > process. Multithreading can be dramatially good for memory-bound tasks. It is possible to say (although, this is oversimplification), that threads are "light processes". They allow to execute a lot of parallel tasks with less overhead > If I'm correct in all of the above, then I'd personally think that we > don't need multithreading in PHP, however a neat(er) predefined method > of interprocess communication would be beneficial. -- Alexey Zakhlestin http://blog.milkfarmsoft.com/