How to build an update CLI script without memory problem ?

Author Message

Bertrand Dunogier

Wednesday 18 November 2009 9:15:20 am

Hi Kristof !

Well, such an iterator would indeed be a good idea. But based on how developement is organized, and on real life, I think that applying this to ezPersistentObject is a bit optimistic, especially since it is based to be heavily modified soon.

What we will probably start with is a global in-memory cache API, maybe linked to memcache and other cache mechanisms, so that we don't have all these hardcoded global calls everywhere. The iterator idea, with automatic cleanup, etc, is a very good point though.

I'm very eager to hear any idea you might have in that area though !

Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier

Gaetano Giunta

Thursday 19 November 2009 1:13:38 am

A low-hanging fruit that might be preliminary work to cache refactoring: tag in comments all methods that cache results with a custom phpdoc tag

Principal Consultant International Business
Member of the Community Project Board

Mark Simon

Thursday 19 November 2009 1:52:35 am

Wher writing CLI scritps I try to keep the fetch on the "outside of the for/foreach" as small as possible.

Best way would be a SQL fetch with all the nodes I need.
(The advantage is: I can use LIMIT to run the script for a part of the result. Change the offset and append the next result to the output file.)

If You need to use the fetch functions, I would try the 'load_data_map' paramter like this:

$parentNodeID = 5;

$users =& eZContentObjectTreeNode::subTreeByNodeId( 
      array( 'ClassFilterType' => 'include',
  'ClassFilterArray' => array( 'user' ),
  'SortBy' => array( 'published', false),
                'LoadDataMap' => false
 ),          
      $parentNodeID);

$i = 0;
foreach( $users as $user ) {
      $usrObj = eZContentObject::fetch( $user->attribute('contentobject_id') );      
      $dataMap =& $usrObj->attribute( 'data_map' );

      ... do something

      unset( $dataMap );
      unset( $usrObj );
}

'inside' the foreach fetch the datamap and unset all variables that are being used.

www.all2e.com

Kristof Coomans

Sunday 06 December 2009 1:26:10 am

@Bertrand which kind of changes are you talking about, regarding eZPersistentObject? Is this for the 4.3 development cycle? Or for "Project V"? I did not see anything about this on the roadmap.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Bertrand Dunogier

Sunday 06 December 2009 2:20:15 am

ProjectV ? Never heard of that. I've heard of Big Balls though. End of private joke.

This change is something we've been talking about, and I also know it has already been partially implemented by a member of the team. There is nothing concrete yet, but it is clear that managing in-memory cache the way we currently do in eZ is a poor approach. This needs to be consolidated with a system wide API, but it's definitely not my role to decide when it is gonna be done. Sorry :(

Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 15:56:50
Script start
Timing: Jan 18 2025 15:56:50
Module start 'layout'
Timing: Jan 18 2025 15:56:50
Module start 'content'
Timing: Jan 18 2025 15:56:51
Module end 'content'
Timing: Jan 18 2025 15:56:51
Script end

Main resources:

Total runtime0.9530 sec
Peak memory usage4,096.0000 KB
Database Queries66

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0065 588.6016152.6563
Module start 'layout' 0.00650.0035 741.257839.9375
Module start 'content' 0.01000.9416 781.1953647.5391
Module end 'content' 0.95150.0014 1,428.734418.2266
Script end 0.9529  1,446.9609 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.3789160.0002
Check MTime0.00170.1826160.0001
Mysql Total
Database connection0.00070.076410.0007
Mysqli_queries0.874691.7715660.0133
Looping result0.00070.0751640.0000
Template Total0.914996.020.4575
Template load0.00250.260520.0012
Template processing0.912495.745520.4562
Template load and register function0.00020.022410.0002
states
state_id_array0.00340.357610.0034
state_identifier_array0.00190.204620.0010
Override
Cache load0.00220.2322260.0001
Sytem overhead
Fetch class attribute can translate value0.00060.063540.0002
Fetch class attribute name0.00070.072790.0001
XML
Image XML parsing0.01551.628940.0039
class_abstraction
Instantiating content class attribute0.00000.0020100.0000
General
dbfile0.01411.4765340.0004
String conversion0.00000.001240.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
5content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
7content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 21
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs