Skip to content

Instantly share code, notes, and snippets.

@kuniyoshi
Created November 5, 2012 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuniyoshi/4018454 to your computer and use it in GitHub Desktop.
Save kuniyoshi/4018454 to your computer and use it in GitHub Desktop.
MyISAMのレプリケーションが不整合を起こすかみたかったけどこのくらいだと起きなかった
#!/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