Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Feb 20, 2024

dumping a InnoDB table containing 1,4 GiB of data ...

<?php // test.php

error_reporting(E_ALL);

require_once __DIR__ . '/vendor/autoload.php';

use Ifsnop\Mysqldump as IMysqldump;

$date = date('Ymd');
$dumpSettings = array(
    'compress' => IMysqldump\Mysqldump::NONE,
    'no-data' => false,
    'add-drop-table' => true,
    'single-transaction' => true,
    'lock-tables' => false,
    'add-locks' => true,
    'extended-insert' => true,
    'disable-foreign-keys-check' => true,
    'skip-triggers' => false,
    'add-drop-trigger' => true,
    'databases' => true,
    'add-drop-database' => true,
    'hex-blob' => true,
    'include-tables' => array('my-table'), // add a table name here
);

$dump = new IMysqldump\Mysqldump("mysql:host=$hostname;dbname=$db", $username, $password, $dumpSettings); // add DB credentials
$dump->start("backup$date.sql");

before this change

mstaab@mst22:/cluster/www/www/www/mysqldump-php$ time php test.php

real    0m41.353s
user    0m30.015s
sys     0m7.903s
mstaab@mst22:/cluster/www/www/www/mysqldump-php$ time php test.php

real    0m43.333s
user    0m31.603s
sys     0m8.279s
mstaab@mst22:/cluster/www/www/www/mysqldump-php$ time php test.php

after this change

mstaab@mst22:/cluster/www/www/www/mysqldump-php$ time php test.php

real    0m37.625s
user    0m26.760s
sys     0m7.848s

mstaab@mst22:/cluster/www/www/www/mysqldump-php$ time php test.php

real    0m37.937s
user    0m26.506s
sys     0m8.259s

the improvement works, because the escape method is called for every column in every row, so the method call overhead is visible

grafik

PHP Version

PHP 8.1.27

Operating System

ubuntu 22 lts

@staabm
Copy link
Contributor Author

staabm commented Feb 29, 2024

committed another small micro optimization, which also improves readability a bit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant