Either by force of sheer popularity, or with the use of something like Devel module, try and enable this module on a site with 100,000 nodes.

Watch the rest of your evening magically melt away as, before you have a chance to say anything, it initiates a batch process, one node at a time, which will then last for the next 17 hours.

So not cool.

Why is this not happening at cron time like other expensive operations, such as the search index?

Comments

avpaderno’s picture

Status: Active » Postponed (maintainer needs more info)

I thought the batch operations were introduced to avoid time outs, and allow a long operation to be completed in as less time as possible.
If this is not the case, then the code must be changed.

I am not sure I understand something about the CRON hook; what does avoid it causes an HTTP timeout?

avpaderno’s picture

Title: Auto-starting batch process on enabling module is *really* not cool » Auto-starting batch process on enabling module can create problems

There is also a Drupal module that auto-starts a batch operation on modules installation; I am not sure the started operations are so time consuming (the operations are related to importing the translations of the strings used by the modules being installed), but they could also be done during CRON tasks execution.

I am not saying that my code is correct; I am only trying to understand the correct way to implement the code (code that has been created basing on what Drupal does).

webchick’s picture

Priority: Normal » Critical
Status: Postponed (maintainer needs more info) » Active

The problem is not the batch operation, per se, it's the fact that it launches itself upon enabling the module.

As a user, when I enable a module, I expect it to do some basic stuff like set up some database tables, expose some settings pages, and then basically immediately kick me back to the modules page so I can keep going on with my day. If there are time-consuming operations that need to occur, those things should happen either a) during cron, like search.module does, or b) upon button press somewhere in the settings page that clearly notes "this will take a long time," like rebuilding the node permissions table does.

This way, people would not click this button unless they were in a good place where they could tie up their computer for 4+ hours, unlike when you're quickly clicking through and enabling modules trying to get a site's functionality built, where it comes as a very nasty surprise. Worse, there appears to be no way to restart this process if it fails for whatever reason (like, for example, your Internet connection cuts out or your browser dies in the middle of processing). For this reason, I'm bumping to critical.

I killed the process only a little way in due to the fact that I had other things to do last night, but judging from the rate of the progress bar, this would've taken at least 4 hours to finish on my site. Therefore, I think this is not the kind of thing you ever want done in a browser window; browsers crash, windows get accidentally closed, etc. So I would advocate moving instead to the model that search.module uses, since building a search index is another operation that can take hours (or days) to complete.

Search module works by having a settings page at admin/settings/search with an indicator of indexing completion (99% of the site has been indexed. There are 7 items left to index.) and lets you specify how many items to index during a cron run (10, 20, 50, 100, 500, etc.). This way, if your cron jobs are not completing because of other things running in the background, you can try bumping the number down.

search_cron() is pretty straight-forward; just registers a small shutdown function to keep the totals up to date, and calls hook_update_index in every module, which includes node_update_index(), which does some fancy logic for weighting and then adds its results to the search index.

However, since that would probably be a big architectural change, and since everyone on this earth wants a 6.x release of this module as soon as possible, an interim fix would be to move the batch processing to the settings page with a progress indicator and a button to start/re-start it if it fails. This is the current approach that Calais module's bulk processing takes, although that maintainer is moving to a cron-based model as well since bulk-tagging legacy content is another potential 4+ hour operation.

avpaderno’s picture

Component: xmlsitemap_node.module » Code

Effectively, the batch process depends too much from the client side that could have any kind of problems, with the consequence that the batch operation would be interrupted before it gets completed (thanks for pointing out that).

Using the cron approach (which has been suggested in the past, but I thought the batch operations were a better solution) it would be possible to back port the code to the Drupal 5 branch.

As temporary solution, I am removing the batch operation code executed during the installation / updating of the modules; the modules are still able to add links in the site map when a node is edited, and it's possible to update the site map using bulk operations (even if it's not a practical way).

Thanks for the report, and for the accurate analysis of the problem.

webchick’s picture

No problem at all! Thanks for dealing with my snarky frustration last night. :D

avpaderno’s picture

Status: Active » Fixed

The code has been removed, and the CHANGELOG.txt file has been updated.
I will not look for the feature request opened by earnie, and I will re-open it again.

I guess that this issue should be considerate fixed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.