Subject: | Bad algorithmic complexity -> inacceptable performance on big selects |
Date: | Sun, 15 Dec 2013 12:11:14 +0100 |
To: | bug-Net-MySQL [...] rt.cpan.org |
From: | Sylvain Frandaz <sylvain.frandaz [...] kertiostechnologies.com> |
Hi,
I'm using Net::MySQL for a big data program. I had no problems with it
when selecting thousands of rows, or inserting thousands of them.
However, I've noticed that the performance per result line gets worse
the more lines there is to fetch.
Consider the following pseudo-perl code:
$dbConnection->query($mySelectQuery);
$recordIterator = $dbConnection->create_record_iterator();
while (1) {
$timeInMicrosecs = getMicroSeconds();
$record = $recordIterator->each();
$elapsedMicrosecs = getMicroSeconds() - $timeInMicrosecs;
print STDERR "Cost to get ONE record: $elapsedMicrosecsn";
last unless (defined $record);
# Here... treatment using the $record
}
When receiving 1000 result lines in my query, I've measured an average
performance of 226 microseconds per row fetched using each().
When receiving 10000 results, it went up to 3158 microseconds.
When receiving 100000 results, it went up to 40277 microseconds, per
row.
I'm strongly suspecting a N² (or worse) complexity algorithm making
things unbearingly slow for these kind of volumes of data.
I'm aware that this is not a "bug" per se, as the module is
*functionally* ok (it still returns the results, but it does it VERY
slowly), but I guess this performance problem will interest you, as this
module intends to replace the DBI-based approach.
Would you happen to know of a workaround for this problem, or should I
switch to DBI for the time being, and hope for better performance ? I'd
be glad to help improve Net::MySQL, and maybe even code a correction
myself, but I'm currently swamped in a (already late) delivery for a
customer, and can't spare the time right now.
Best regards,
Sylvain FRANDAZ, french Perl user.
--
Sylvain Frandaz
Ingénieur d'études et développement.
+ 33 6 32 85 15 36
sylvain.frandaz@kertiostechnologies.com
www.kertios.com
23 rue Edouard Nieuport
92150 Suresnes