Last active
December 19, 2015 11:09
-
-
Save ledjon/5945688 to your computer and use it in GitHub Desktop.
Perl script to do a fast inserts into MySQL table to test auto_increment speed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use DBI; | |
use Parallel::ForkManager; | |
# create table t1a (id int4 auto_increment primary key) engine = innodb; | |
# create table t1b (id int4 auto_increment primary key) engine = myisam; | |
# run as "time ./mysql.pl t1a" or "time ./mysql.pl t1b" | |
my $seq = shift or die "Please provide sequence name as arg #1\n"; | |
my $dbh = DBI->connect("DBI:mysql:seqtest;mysql_read_default_file=~/.my.cnf", "", "", { RaiseError => 1 }) or die("Could not connec to db\n"); | |
$dbh->do("truncate table $seq"); | |
my $pm = Parallel::ForkManager->new(10); | |
for ( my $i = 0; $i < 1000; $i++ ) | |
#for ( my $i = 0; $i < 1; $i++ ) | |
{ | |
my $pid = $pm->start and next; | |
# now am child | |
my $d = $dbh->clone; | |
for( 1..10000 ) | |
{ | |
# $d->do("select nextval(?)", undef, $seq); | |
$d->do("insert into $seq values (null)"); | |
} | |
$pm->finish; | |
} | |
# we are purely parent at this point | |
$pm->wait_all_children; | |
warn("done!\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment