geeky notes on web (drupal) and .net (c#) programming, whichever prevails at the moment

 

All commits tagged "drupal 7"

 

How to speed up drupal's slow batch processing

I have a task to import pretty huge drupal 5 site into drupal 7. I decided to create a specific import module that would import old drupal site content one by one. Perfect candidate to perform this job seemed to be a drupal's Batch API.

What I've later discovered is that for huge tasks like mine (import several thousands of items) is very slow, probably because of overhead that is created by drupal bootstrap. The thing is that batch api creates a list of functions and parameters for those functions upfront and then executes them one by one. Each step includes the drupal bootstrap with all the regular page processing, and that's what making the overall batch processing slow. I've measured my import function call lasts 0.8s..1s and the overhead is about 5s, for almost every call.

If only it could do series of my import function calls in one session.

Digging the batch API I found this line (file includes/batch.inc, function _batch_process()):

 // If we are in progressive mode, break processing after 1 second.
 if ($batch['progressive'] && timer_read('batch_processing') > 1000) {
   // Record elapsed wall clock time.
   $current_set['elapsed'] = round((microtime(TRUE) - $current_set['start']) * 1000, 2);
   break;
 }

After I changed that 1000 milliseconds in the 'if' condition to something like 30000 ms, I found that the process of importing became ~5 times higher! The source code is pretty self explanatory: if the process takes longer than 1 second, it breaks the execution and waits for another call. I will probably reset this value back when the site goes into production, but for now it is what I was looking for.

}