Part of the EllisLab Network
   
 
DataMapper & ORM performance
Posted: 18 June 2009 04:41 AM   [ Ignore ]  
Summer Student
Avatar
Total Posts:  24
Joined  06-21-2007

I’m currently working on a eshop platform built on CI 1.6.3. There is a system similar to DataMapper.
I’m seeing a huge rise in required resources. In particular I had to raise php’s memory limit to be able to get the complete list of products (around 500 of them).

Has anyone noticed anything similar working with DataMapper or any similar ORM implementation ?
I’d like to hear your opinions on this.

Profile
 
 
Posted: 18 June 2009 09:57 AM   [ Ignore ]   [ # 1 ]  
Grad Student
Avatar
Rank
Total Posts:  83
Joined  04-27-2007

why would u want need to get 500 products in one go ?

Profile
 
 
Posted: 19 June 2009 05:28 AM   [ Ignore ]   [ # 2 ]  
Summer Student
Avatar
Total Posts:  24
Joined  06-21-2007

So I can display them afterwards with the tablesorter jquery plugin

Profile
 
 
Posted: 19 June 2009 05:42 AM   [ Ignore ]   [ # 3 ]  
Research Assistant
RankRankRank
Total Posts:  363
Joined  04-05-2007

Seems to me that you should be using pagination and using jquery to get the pages by calling sections of data as required using ajax. Unless you really need to display all 500 in one go.

Profile
 
 
Posted: 19 June 2009 05:52 AM   [ Ignore ]   [ # 4 ]  
Summer Student
Avatar
Total Posts:  24
Joined  06-21-2007

I agree. However it’s completely irrelevant to the issue of DataMapper performance.

Profile
 
 
Posted: 19 June 2009 06:32 AM   [ Ignore ]   [ # 5 ]  
Research Assistant
RankRankRank
Total Posts:  363
Joined  04-05-2007

Well as it makes a new object per row its not surprising that it uses alot of memory. It looks like it was never designed for returning alot of rows. I suggest using plain queries or just active record queries for it.

Profile
 
 
Posted: 01 July 2009 05:10 AM   [ Ignore ]   [ # 6 ]  
Grad Student
Avatar
Rank
Total Posts:  87
Joined  07-07-2008

@vang

i’m currently working with datamapper and i’ve been working on similar issues with memory consumption on large queries.

How are you loading your data into your views? When i’m working with a single Object, i typically load it directly, like

$post = new Post();
    
$post->where('id',2)->get();
    
$viewdata = $this->load->view('post',array('post'=>$post), TRUE);

Although yes when dealing with a large number of rows, the ‘all’ array can get just as large, and a lot of that has to do with the fact that each object in the array is an instance of Datamapper. If you load the all array into a view, you will be essentially copying the array of datamaps. One thing i’ve tried to use to sort out just the data is the _to_array() function.

$post = new Post();
    
$post->get(); // get all posts
    
    
foreach($post->all as $p)
    
{
        $this
->load->view('post',$p->_to_array());
    
}

this way, you’re not copying the entire instance to the view, just the data. Plus the returned array will nicely insert the variable names, so each $p->title becomes $title in your view.

Next, if you’re using a template library or something that stores and ‘renders’ the view data, that process may also be making copies of your data, which multiplies with each row you send to it.

I struggled for a bit because i wanted to use datatables/tablesorter, but i opted to have sorting/paging done on the server side (with ajax as an option). The client side functionality is nice, but yes if your results grow to 1000+ rows etc, you’ll be faced with either huge memory consumption by the sheer amount of data (at least on first run if you have caching on) and then have to resort to server side paging anyway at some point.

Lastly, i would recommend using some sort of opcode caching utility if you are not already, such as eaccellerator. I was delighted to see my scripts reduce memory consumption from 3+ megs to 500k at the flip of that switch.

cheers,

CC

Profile
 
 
Posted: 04 July 2009 03:59 AM   [ Ignore ]   [ # 7 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  740
Joined  08-03-2006

If you use _to_array(), it will duplicate all the data anyway (+ it needs parsing the object to array) as PHP does not copy object -> array by reference (I mean in the internals, arrays are copy-on-write).

So I recommend passing the objects by reference instead (default in PHP 5), as you won’t create duplicate sets of data with that method.

 Signature 

RapidDataMapper: My new ORM, is now released!

IgnitedRecord: Old ORM

MPTtree: A model to handle trees in a database.

YAYParser - Yet Another YAML Parser

Profile
 
 
Posted: 05 July 2009 03:12 AM   [ Ignore ]   [ # 8 ]  
Grad Student
Avatar
Rank
Total Posts:  87
Joined  07-07-2008

yeah i actually switched from passing the enitre object to a ‘list’ view, which ran the foreach loop, and instead creating a header view and then loading a ‘single item’ view for each instance in the all array. I noticed my memory consumption dropped about 25% right away. The other thing is that i can reuse the ‘single item’ view again for other purposes. I do the same thing for form views, etc. I’m sort of building a crud style base controller for adminning datamaps and this seems the way to go so far. I don’t use the _to_array() method much myself except in specific instances like copying user data to session etc. so it is handy.

Sometime it would be nice to rework datamapper for optimized usage, perhaps integrate some sort of datamap-level caching scheme. Also i wonder if storing the validation/model config externally would help, i separated the validtion into its own class and it helps memory consumption quite a bit when not needed (read vs write) plus it cleans up the code
n

Profile
 
 
Posted: 06 July 2009 12:28 PM   [ Ignore ]   [ # 9 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  327
Joined  08-29-2008

Check out DMZ

the newest version has some caching, I have no idea how much it helps but its bound to do something…

 Signature 

421 Entertainment :: YAAS - Yet Another Authentication System :: Error Logger

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 721, on January 06, 2010 09:38 AM
Total Registered Members: 119125 Total Logged-in Users: 61
Total Topics: 125465 Total Anonymous Users: 4
Total Replies: 660486 Total Guests: 465
Total Posts: 785951    
Members ( View Memberlist )
Newest Members:  kracha95tanjahagresifBlunklenarezecomodlostunlockedmarcusbrody10ghadbanRachelRiley