Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.2.0

Request #18752 Performance problem retrieving search result + patch
Submitted: 2011-08-23 20:39 UTC
From: montagut Assigned: beni
Status: Closed Package: Net_LDAP2 (version 2.0.11)
PHP Version: 5.3.0 OS: GNU/Linux Debian
Roadmaps: (Not assigned)    
Subscription  


 [2011-08-23 20:39 UTC] montagut (Xavier Montagutelli)
Description: ------------ There's a serious performance problem fetching results from a search. When doing a very simple search on a directory with around 50.000 entries, getting the results with the "shiftEntry" methods takes a very long time, compared to using the native PHP functions. With Xdebug, I have identified the bottleneck. Each call to "shiftEntry" calls "count", and this one calls "ldap_count_entries". I suppose this function goes through all the remaining results to give the count, so calling it inefficient. It can safely be removed, patch attached Test script: --------------- Test script (to run in command line mode) : https://docs.google.com/leaf?id=0ByWMI5PuRIdwNDU5MDdmMGQtNTdiZC00MTYyLWI3YmQtMzIwZTU0YmQ1YzZj&hl=fr Actual result: -------------- 1. Using PHP native LDAP functions Number of entries : 22402 Search time : 2 seconds Building list from search result : 0 seconds 2. Using Net_LDAP2 object Number of entries : 22402 Search time : 2 seconds Building list from search result : 15 seconds

Comments

 [2011-08-23 20:46 UTC] montagut (Xavier Montagutelli)
 [2011-08-24 11:24 UTC] beni (Benedikt Hallinger)
-Status: Open +Status: Verified -Assigned To: +Assigned To: beni
 [2011-08-24 11:45 UTC] beni (Benedikt Hallinger)
Confirmed this. However this would involve an API change. The better way is surely to cache the call to ldap_count_entries and return the count from that cache. I added a fix to count(). Please fetch the latest SVN version (revision xxx) and verify that your bug is solved now. Thanks for improving Net_LDAP2!
 [2011-08-24 11:46 UTC] beni (Benedikt Hallinger)
ok, it looks like the pear svn is down currently, so the fix is not in. i will add it as patch un til i can commit the change.
 [2011-08-24 11:48 UTC] beni (Benedikt Hallinger)
 [2011-08-24 12:42 UTC] beni (Benedikt Hallinger)
Its in SVN now. Please test.
 [2011-08-24 17:51 UTC] montagut (Xavier Montagutelli)
 [2011-08-24 18:01 UTC] montagut (Xavier Montagutelli)
Your patch is not correct, it misses the underscore in the "count_entries" variable. Once corrected with the patch missingUnderscoreForCountCache, it works better. Here are the numbers : # php liste-net-ldap2.php 1. Using PHP native LDAP functions Number of entries : 22407 Search time : 2 seconds Building list from search result : 0 seconds 2. Using Net_LDAP2 object Number of entries : 22407 Search time : 2 seconds Building list from search result : 8 seconds Net_LDAP2 is always much slower than the native LDAP functions, but we have reduced the difference (from 15 s to 8 s). But, why do you want to maintain the call to the "count" method at the beginning of "shiftEntry" ? My first patch could be improved by testing the result of ldap_first_entry to get rid of this call. If there are no result, it returns false. So the call to "count" is useless. Both patches could be inserted, as they serve different purposes in fact.
 [2011-08-24 18:13 UTC] beni (Benedikt Hallinger)
-Status: Verified +Status: Closed
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better. Hello again, thanks for your help! I implemented both patches now, so the code should run faster.