Skip to content

Instantly share code, notes, and snippets.

View nekokak's full-sized avatar

Atsushi Kobayashi nekokak

View GitHub Profile
#! /usr/locla/bin/perl
use strict;
use warnings;
use Benchmark qw(:all);
use DBI;
my $dbh = DBI->connect('dbi:mysql:hoge', 'test', 'test');
cmpthese(50000, {
set => sub {
$dbh->do('set global innodb_flush_log_at_trx_commit=0');
#! /usr/locla/bin/perl
use strict;
use warnings;
use Benchmark qw(:all);
use DBI;
my $dbh = DBI->connect('dbi:mysql:hoge', 'test', 'test');
cmpthese(50000, {
set => sub {
$dbh->begin_work;
## Test::More wrapper
{
no strict 'refs'; ## no critic
for my $sub (qw/is is_deeply like isa_ok isnt unlike/) {
my $proto = prototype("Test::More::${sub}");
my $code = set_prototype(sub {
push @_, $test_block_name if @_ == 2;
goto \&{"Test::More::${sub}"};
} , $proto);
$ cat irchttpd.pl
#!/usr/bin/perl
use strict;
use warnings;
use AnyEvent::IRC::Client;
use AnyEvent::JSONRPC::Lite::Server;
use AnyEvent;
my $channel = "#irctest";
@nekokak
nekokak / humu
Created February 18, 2010 06:17
sub search {
container('db')->resultset_with_pager('MySQLFoundRows');
}
sub search1 {
my $self = shift;
my $rs = $self->search;
# 検索条件なんかを追加する
}
sub search2 {
my $self = shift;
#! /usr/bin/perl
use strict;
use warnings;
use Imager;
my $file = shift;
my @frames = Imager->read_multi( file => $file );
my @new_frames;
for my $frame (@frames) {
use strict;
use warnings;
use Plack::Request;
use Imager::QRCode qw(plot_qrcode);
use MIME::Base64;
sub {
my $env = shift;
my $r = Plack::Request->new($env);
mysql> EXPLAIN SELECT job.id, job.arg, job.uniqkey, job.func_id, job.grabbed_until, job.retry_cnt, job.priority, func.name AS funcname FROM job INNER JOIN func ON job.func_id = func.id WHERE (func.name IN ('Idou::Worker::Test')) AND (job.grabbed_until <= '1275387047') AND (job.run_after <= '1275387047') ORDER BY job.priority DESC LIMIT 30;
+----+-------------+-------+-------+---------------+---------+---------+-------+-------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+---------+---------+-------+-------+----------------+
| 1 | SIMPLE | func | const | PRIMARY,name | name | 767 | const | 1 | Using filesort |
| 1 | SIMPLE | job | range | func_id | func_id | 4 | NULL | 99997 | Using where |
+----+-------------+-------+-------+---------------+---------+---------+-------+-------+----------------+
2 rows in set (0.00 sec)
mysql> EXPLAIN SELECT job.id, job.arg, job.uniqkey, job.func_id, job.grabbed_until, job.retry_cnt, job.priority, func.name AS funcname FROM job INNER JOIN func ON job.func_id = func.id WHERE (func.name IN ('Idou::Worker::Test','Idou::Worker::Test1','Idou::Worker::Test2','Idou::Worker::Test3','Idou::Worker::Test4','Idou::Worker::Test5','Idou::Worker::Test6')) AND (job.grabbed_until <= '1275387047') AND (job.run_after <= '1275387047') ORDER BY job.priority DESC LIMIT 30;
+----+-------------+-------+-------+---------------+---------+---------+--------------+------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+---------+---------+--------------+------+----------------------------------------------+
| 1 | SIMPLE | func | range | PRIMARY,name | name | 767 | NULL | 7 | Using where; Using temporary;
for find_job
before:
+----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------+
| 1 | SIMPLE | job | ALL | func_id | NULL | NULL | NULL | 1 | Using where; Using filesort |
+----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------+
1 row in set (0.00 sec)