Created
November 5, 2012 17:21
-
-
Save kuniyoshi/4018454 to your computer and use it in GitHub Desktop.
MyISAMのレプリケーションが不整合を起こすかみたかったけどこのくらいだと起きなかった
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 5.10.0; | |
use utf8; | |
use strict; | |
use warnings; | |
use open qw( :utf8 :std ); | |
use Data::Dumper; | |
use DBI; | |
use Parallel::ForkManager; | |
my $MAX_PROCESSES = 50; | |
my $ARTICLE_COUNT = 10_000; | |
my $dbh = DBI->connect( | |
"dbi:mysql:database=msp;mysql_socket=/tmp/mysql.sock", | |
"root", | |
q{}, | |
{ RaiseError => 1 }, | |
) | |
or die $DBI::errstr; | |
$dbh->do( "TRUNCATE TABLE blog" ); | |
$dbh->do( "TRUNCATE TABLE article" ); | |
$dbh->disconnect; | |
my $pm = Parallel::ForkManager->new( $MAX_PROCESSES ); | |
foreach my $blog_id ( 1 .. $MAX_PROCESSES ) { | |
$pm->start | |
and next; | |
my $dbh = DBI->connect( | |
"dbi:mysql:database=msp;mysql_socket=/tmp/mysql.sock", | |
"root", | |
q{}, | |
{ RaiseError => 1 }, | |
) | |
or die $DBI::errstr; | |
$dbh->do( "INSERT INTO blog VALUES()" ); | |
my $sth = $dbh->prepare( "INSERT INTO article (blog_id) VALUES(?)" ); | |
foreach ( 1 .. $ARTICLE_COUNT ) { | |
$sth->execute( $blog_id ); | |
} | |
$pm->finish; | |
} | |
$pm->wait_all_children; | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment