 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
James Cohen's Blog: Poor Man's Parallelization for Batch Processing Jobs
by Chris Cornutt May 18, 2011 @ 11:56:31
James Cohen has a quick post about what he calls a "poor man's parallelization" for working with batch jobs. It takes in parameters that tell it which set of jobs to run through when looping.
One common problem that I've seen time and time again with batch processing jobs (generally cronjobs) is that when they're written they run quickly. Over time their workload grows until eventually it's unacceptably slow. [...] To create a simple of way of separating the jobs in a consistent way we can use the modulus operator. It just calculates the remainder of two numbers. It's a common arithmetic operator in almost all languages so this technique is pretty portable.
His proof-of-concept script takes in two parameters, the starting job number and the number to increment. His example is user IDs, but this type of script could be used for anything with an ID number. The script is then run from the command line with the parameters of your choosing.
voice your opinion now!
batch processing separation modulus
David Müller's Blog: Parallel processing in PHP
by Chris Cornutt March 31, 2011 @ 13:41:37
In a recent post to his blog David Müller has taken a look at parallel processing in PHP using a few different methods - system calls, fork, and curl.
Since PHP does not offer native threads, we have to get creative to do parallel processing. I will introduce 3 fundamentally different concepts to emulate multithreading as good as possible.
For each of the technologies mentioned above, he provides a simple bit of sample code that does simple tasks like echoing out strings and writing to files. He also includes some benchmarks (take them with a grain of salt) of the three different methods showing how many iterations they could run through in ten seconds. He includes the benchmarking script if you'd like to try it out yourself.
voice your opinion now!
parallel processing tutorial system fork curl benchmark
IBM developerWorks: Efficient mathematical processing using Scilab through PHP
by Chris Cornutt March 22, 2010 @ 11:55:56
New on the IBM developerWorks, there's an article looking at using the Scilab software integrated into PHP to perform some more complicated mathematical processing.
Scripting languages like Ruby, Python, and PHP power modern-day server-side Web development. These languages are great because you can easily and rapidly build Web sites. However, their downfall is their inefficiency with complicated algorithms, such as those found in mathematics and the sciences. [...] In this article, we'll investigate one particular way to merge the power of a particular bit of scientific software - Scilab - with the ease of development and Web-friendliness of a server-side language: PHP.
Your script uses the Scilab tool from the command line, called via something like exec, and parsing the output to spit the results back out to the viewer. They show how to create two pages with form elements for allowing the user to interact with the script and one that helps you generate a graph based on some results.
voice your opinion now!
scilab mathematical processing tutorial
PHPClasses.org Blog: Distributing PHP processing with Gearman
by Chris Cornutt November 23, 2009 @ 12:58:10
On the PHPClasses blog there's a new post looking at using the Gearman framework with PHP via a PECL extension.
Gearman is a generic framework to distribute processing jobs to separate processes in the same machine or other machines in a cluster. It allows your application to perform tasks in parallel, balance the processing load, and even invoke code written in other languages. The "Gearman" word is an anagram of "manager". Its purpose is solely to dispatch jobs that need to be executed, but Gearman just by itself does not do anything useful.
In his example he sets up a simple "Hello World" processing queue including the command line to start up the Gearman server and the PHP you'll need to push in a request, grab the status and see the percentage of it that's been completed.
voice your opinion now!
distributed processing gearman
Padraic Brady's Blog: The Mysteries Of Asynchronous Processing With PHP - Part 2 (CLI applications)
by Chris Cornutt September 30, 2009 @ 08:32:01
In the second part of his series looking at asynchronous processing in PHP applications, Padraic Brady lays the ground work for the third part and shows how to work with command line Zend Framework applications.
Part 2 is a tangential detour into how to make a Zend Framework based application accessible from the command line before we delve into examples using this in future parts of the series. If you are not a Zend Framework user, I'm sure you can find relevant material online for your own preferred framework though the ZF pieces may still have some usefulness in understanding the approach from an MVC perspective.
In his examples he skips over the basics of using a command line application and jumps right to things like argument handling, creating a custom router and making a custom "calling script" to handle the configuration of the CLI application.
voice your opinion now!
asynchronous processing zendframework cli
Juozas Kaziukenas' Blog: Prevent scripts from being killed
by Chris Cornutt March 26, 2009 @ 13:18:26
Juozas Kaziukenas has a helpful tip you can use on those long-running scripts to keep going - the set_time_limit function.
I have some very time consuming scripts running through CRON - some nice web scrapping jobs. They are not processing-intense, but rather slow because of slow websites. All these jobs are really hard to divide in to separate scripts (another article), so one script should have no limits to run for hours. However, web servers don't like it by default.
He show how you can use the set_time_limit function to free your script of the timeout limitation (which can be a good and bad thing) or having your script output something, like a "processing" message, as it runs through the loop to keep the timeout away. You can also use the ignore_user_abort function to continue the process even if the user hits the stop button or otherwise closes the request.
voice your opinion now!
timeout user settimelimit ignoreuserabort processing
Ibuildings Blog: Boost performance with parallel processing
by Chris Cornutt January 23, 2009 @ 07:51:05
On the Ibuildings blog today there's a new post from Martin Roest looking at parallel processing in PHP scripts and how it can help you with performance and simplifying your applications.
The idea of parallel processing is when you take an atomic transaction or operation called a 'process' and run a couple of those at the same time. [...] In this example I had a PHP CLI script. The purpose of this script was to process remote documents and save it local. It fetched the document from a remote location, processed it and saved the result local - let's call this the transaction. Transactions were done sequentially. It took about 1 second for a transaction to complete and the script had to do roughly 3500 transactions.
Obviously, this script/testing method was not very effective, so he went searching for an alternative. The best option came in the shape of forking processes - spawning off a separate script (via PHP's forking functionality) to do the work on one or multiple entries. It uses the pcntl_fork and pcntl_waitpid functions to spawn and manage these children. Once they're all finished - working in parallel - they return back to the main script to wait for the slower ones to catch up.
voice your opinion now!
performance boost parallel processing ibuildings fork pcntlfork pcntlwaitpid
John Lim's Blog: Parallel Processing in PHP
by Chris Cornutt September 22, 2008 @ 08:47:14
John Lim has two new posts covering parallel processing in PHP and how to use this "divide and conquer" idea to not only speed up your code but to make it more maintainable down the road.
In the first post:
One problem we were having is that some of our batch processing jobs were taking too long to run. In order to speed the processing, we tried to split the processing file into half, and let a separate PHP process run each job. [...] Here is our technique for running multiple parallel jobs in PHP. In this example, we have two job files: j1.php and j2.php we want to run.
The code is included for the job files and the "controller" that manages them. In the second article, he builds on this and shows a more practical example - finding the median of a set of records out of a database.
voice your opinion now!
parallel processing tutorial divide conquer
|
Community Events
Don't see your event here? Let us know!
|