On Mon, Mar 22, 2010 at 10:01 PM, Larry Garfield <larry@xxxxxxxxxxxxxxxx> wrote: > On Monday 22 March 2010 10:51:14 pm Tommy Pham wrote: >> Threading is one of the 2 two main reasons why I moved to Java & >> asp.net (C#). I've built a PHP based web crawler about 10 years ago. >> I ran into some problems: cookies, form handling and submission, >> threading, and application variables. I later found some solutions >> for cookies, form handling & submission. But no solution for >> threading and application variables. Thus the move. Here's a simple >> example of one of the many uses for threading. For an e-commerce >> site, when the shopper requests for a category (ID), you can have a >> thread to get all subcategories for that category, another thread to >> get any assigned products, another thread to fetch all manufacturers >> listed under that category, another thread to fetch any filters (price >> ranges, features, specs, etc) set by the store owner that would fall >> under that category, etc... versus what PHP currently doing now: >> fetch subcategories, then fetch assigned products, then fetch >> manufacturers, etc.... Performance would increase ten fold because of >> parallel (threading) operations versus serial operations. Add that to >> application variable (less memory usage and CPU cycles due to >> creating/GC of variables that could be used for an entire application >> regardless of requests & sessions), you have an excellent tool. >> >> Regards, >> Tommy > > Threading is also much more difficult to program for safely, because thread > order is non-deterministic. Do you really want to unleash hoards of > marginally competent programmers on a threaded enviornment? :-) Marginally competent? I think some, if not many, on this list will disagree with that ;) > > Also, the architecture you describe above is fine if you're scaling a single > server really big. PHP is designed to scale the other direction: Just add > more servers. There's no data shared from one request to another, so there's > no need to share data between web heads. Throw a load balancer in front of it > and spin up as many web servers as you need. Load balancer is used when the server is overloaded with requests and upgrade has reached it's limit. That's not the same thing as a simple request where multiple answers are needed as in my example. If you're thinking of implementing something like my example across multiple servers (where each server will fetch an answer for a simple request) via another method, then you're going to face similar issues as threading ie session/request sync which is equivalent to thread safety/sync/deadlock but now it's worse because it's spread across network where performance issues comes in because internal system IO > (network IO + internal system IO). > > The "shared nothing" design is very deliberate. It has design trade-offs like > anything else. > > PHP is a web-centric language. It's not really intended for building tier-1 > daemon processes, just like you'd be an idiot to try and code your entire web > app in C from the start. Of course since C was engineered to create OSes and (text based) apps when SMP/MC is unheard of. But we're now in the digital era where SMP/MC is very common place. In fact, trying to buy a new desktop/laptop now without a multicore becomes very difficult and undesired. Why not make use of the SMP/MC? :) PHP seems strive and somewhat 'imitate' languages like java & asp.net. Not trying to go off topice but for example: namespace (namespace in asp.net and packages in java). For many of us that don't use namespace now or even when it's not yet implemented, we (PHP web app dev) already implement our own version of it - subfolders. So why not copy or imitate the features that would be more beneficial if not more usability ie threading? PHP is already ahead of java & asp.net in terms of generics, not strong typed. Regards, Tommy > > --Larry Garfield > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php