Reputation: 1304
I have a PHP script whose load the 1 CPU of 8 CPUs for 100 percent. Can I share CPU resources to run PHP script faster?
Now when I start my PHP script, it load 1 CPU to 100%. But other have 1-5% load. Because of this my script is performed for 40 second.
Can I share the load across all processors, or this impossible?
Upvotes: 0
Views: 607
Reputation: 5306
Firstly: if you're CPU bound for 40 seconds chances are you need to rethink your algorithm or your programming language. PHP IMHO still does best as a user facing, HTML/JSON/whatever output format producing engine. That's why it's built on a shared nothing architecture: one request gets one CPU, computes and terminates. You scale this architecture over multiple CPUs by distributing the requests among them.
That said, if a single request takes 40s to complete, you might have luck with using Worker threads, that will you need to spin off your main thread and which can run on your under-utilized CPUs. But again, that's a whole mountain of complexity to scale - think hard before starting down that route.
A probably easier alternative to do-it-yourself thread management is to fork out work to dedicated worker processes. Gearman is a well known framework to help you with this.
Upvotes: 2
Reputation: 2420
You could use the APC extension http://www.php.net/manual/de/book.apc.php. And store big array's etc. If I am not mistaken this will get stored into the Shared Memory and will be accessable trough all your processors. Also since those variables etc. are cached php won't compile it again that should increase the perfomance of your php application .
Thats the only think I could come up with.
Upvotes: 0