Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthortom
     
    Hi,

    somehow my application seems to be _very_ slow in terms of database operations compared to using plain php mysql functions. Fetching larger collections from my tables tremendously increases response times. I'm using findBySql with queries that have execution times of about 150ms, but page loading takes several seconds, without complicated computations for the resulting collection (just an html table with one <a> for each record). Above 10 records, it gets unbearable.

    Is the code that constructs objects from database results just so slow?

    Regards,
    Tom
    • CommentAuthortom
     
    Just did some more testing. With mysql_query()/mysql_fetch_array() the response takes 2 seconds with a resultset of >9000 records. With akelos, it takes 15 secs.

    :[
    •  
      CommentAuthorbermi
     

    Tom, findBySql instantiates results which obviously takes CPU time and memory.

    But you probably don't want keep 9000 models loaded in memory.

    FYI Ak::db returns an ADODB connection so you can do something like:

    $conn = Ak::db();
    $recordSet = &$conn->Execute('select * from products');
    $ProductInstance =& new Product();
    while (!$recordSet->EOF) {
        $Product = $ProductInstance->instantiate($ProductInstance->getOnlyAvailableAtrributes($recordSet->fields), false);
        // Do something with $Product
        $recordSet->MoveNext();
    }
    
    • CommentAuthortom
     
    Oh, the method is named getOnlyAvailableAtrributes(), not getOnlyAvailableAttributes().
    • CommentAuthortom
     

    Ok, this way it may save a lot of memory, but still the models get instantiated, right? Suppose that's what takes so much time.

    However, I saved some seconds by just grabbing the fields from the recordSets, without instantiating AkActiveRecords:

    $conn = Ak::db();
    $recordSet = &$conn->Execute('select * from products');
    $ProductInstance =& new Product();
    while (!$recordSet->EOF) {
        $this->my_products[] = $recordSet->fields;
        $recordSet->MoveNext();
    }
    

    Also, I removed the 9000 calls to UrlHelper::url_for() in my view, creating the URLs manually. Not as beautiful, but faster.

    It's feasible now with the 9000 records, but it still takes a couple of seconds. I better display some kind of progress indicator in my view while the result is loading...

    Thanks!

    Tom