Skip to content

Instantly share code, notes, and snippets.

@nihen
nihen / description
Last active December 26, 2015 03:19
perl で do & forkするとcowにのってるメモリがexit時に再消費?
free -s 0.2 | grep Mem
を実行して眺めつつこのperl scriptを実行すると、子プロセスがexitする時に新たなメモリを消費するのがわかる。
CoWのメモリ分ではないかと思われる。
キモは do と fork の組み合わせ
perl 5.14.4, 5.18.1で確認
↓doは関係なかった
http://nihen.hatenablog.com/entry/2013/10/22/125410
@nihen
nihen / isucon3.psgi
Created October 6, 2013 10:30
これとpublicファイルがあればIsucon3アプリの完成です。 Plack ServerはFeersumで、front httpdはnginxでした。
use 5.14.0;
use utf8;
use Plack::Request;
use File::Basename;
use IO::Handle;
use Encode;
use List::Util qw/sum/;
use POSIX qw/strftime/;
use JSON::XS;
use Plack::Session::State::Cookie;
package MyCounter;
sub new { my $class = shift;bless {@_} => $class }
sub incr { shift->{count}++ }
sub decr { shift->{count}-- }
sub count { shift->{count} }
package main;
use Text::Xslate;
my $tx = Text::Xslate->new(
use strict;
use warnings;
use Test::More;
use SQL::Maker::Condition;
my $w1 = SQL::Maker::Condition->new();
$w1->add(1 => 1);
@nihen
nihen / hoge.pl
Created November 6, 2012 16:06
perl inline
perl -MO=Deparse hoge.pl
# インライン展開される組
sub inline_q() {
q{myline}
}
sub inline_qq() {
qq{myline}
}
@nihen
nihen / isucon2.psgi
Created November 3, 2012 08:56
isucon2
use 5.14.0;
use Plack::Request;
use IO::Handle;
use Encode;
use List::Util qw/sum/;
use POSIX qw/strftime/;
use JSON::XS;
my $json_encoder = JSON::XS->new->latin1;
my $json_decoder = JSON::XS->new->utf8;
@nihen
nihen / cpandupmetaclean
Created October 27, 2012 07:44
cpandupmetaclean
#!/usr/bin/env perl
use strict;
use warnings;
use 5.008001;
use Config qw(%Config);
use File::Find;
use File::Path;
use JSON;
use Getopt::Long;
use version 0.77;
@nihen
nihen / xslate_fork_cache.t
Created October 15, 2012 01:42
xslate and fork and cache
#!perl
use strict;
use warnings;
use Fatal qw(open close);
use Test::More;
use File::Temp qw(tempdir);
use Text::Xslate;
{
@nihen
nihen / result
Created September 28, 2012 18:46
teng_vs_skinny_vs_dbic_vs_dbi
# insert ok 1 - teng ok 2 - skinny ok 3 - dbi ok 4 - dbic # fast_insert ok 5 - teng ok 6 - skinny ok 7 - dbi ok 8 - dbic # single ok 9 - teng ok 10 - skinny ok 11 - dbi ok 12 - dbic # lookup ok 13 - teng ok 14 - skinny ok 15 - dbi ok 16 - dbic # search ok 17 - teng ok 18 - skinny ok 19 - dbi ok 20 - dbic # search_by_sql ok 21 - teng ok 22 - skinny ok 23 - dbi # dbic is not support search_by_sql # search_named ok 24 - teng ok 25 - skinny # dbi is not support search_named # dbic is not support search_named 1..25 DBI: 1.622 DBIx::Class version: 0.08200 Skinny version: 0.0742 Teng version: 0.15 --- insert --- Rate dbic teng skinny dbi dbic 941/s -- -17% -35% -45% teng 1131/s 20% -- -21% -34% skinny 1437/s 53% 27% -- -16% dbi 1706/s 81% 51% 19% -- --- fast_insert --- Rate dbic skinny teng dbi dbic 950/s -- -32% -38% -45% skinny 1399/s 47% -- -9% -19% teng 1540/s 62% 10% -- -11% dbi 172
@nihen
nihen / result
Created September 17, 2012 14:14
teng_vs_skinny
ok 1
ok 2
ok 3
ok 4
ok 5
ok 6
ok 7
1..7
Teng version: 0.15