Your SlideShare is downloading. ×

Apache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-Thon

6,092

Published on

Apache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-Thon

Apache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-Thon

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,092
On Slideshare
0
From Embeds
0
Number of Embeds
20
Actions
Shares
0
Downloads
4
Comments
0
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. ALFCYAPC::Asia 2013 Tokyo 前夜祭 LT-thon Masahiro Nagano @kazeburo
  • 2. Me • 長野雅広 Masahiro Nagano • @kazeburo • PAUSE: KAZEBURO • Operations Engineer, Site Reliability • LINE Corp. Development support on LINE Familly, livedoor
  • 3. ALFC =
  • 4. Apache::LogFormat::Compiler
  • 5. Convert
  • 6. ‘%h %l %u %t "%r" %>s %b’
  • 7. to perl-code
  • 8. my $code = <<EOF; sub { my ($env,$res,$length,$reqtime,$time) = @_; $time = time() if ! defined $time; my @lt = localtime($time);; my $t = sprintf '%02d/%s/%04d:%02d:%02d:%02d %s', $lt[3], $abbr[$lt[4]], $lt[5]+1900, $lt[2], $lt[1], $lt[0], $tz; q!! . ($env->{REMOTE_ADDR} || '-') . q! ! . '-' . q! ! . ($env->{REMOTE_USER} || '-') . q! ! . "[" . $t . "]" . q! "! . _safe($env->{REQUEST_METHOD}) . " " . _safe($env- >{REQUEST_URI}) . " " . $env->{SERVER_PROTOCOL} . q!" ! . $res->[0] . q! ! . (defined $length ? $length : '-') . q!! } EOF
  • 9. and compile
  • 10. my $log_line = eval $code; $log_line->($env,$res);
  • 11. SYNOPSIS
  • 12. my $log_handler = Apache::LogFormat::Compiler->new( '%h %l %u %t "%r" %>s %b' ); warn $log_handler->log_line($env,$res);
  • 13. use Plack::Builder; use Time::HiRes qw/gettimeofday tv_interval/; use Apache::LogFormat::Compiler; my $log_handler = Apache::LogFormat::Compiler->new( '%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i" %D' ); my $compile_log_app = builder { enable sub { my $app = shift; sub { my $env = shift; my $t0 = [gettimeofday]; my $res = $app->(); my $reqtime = int(tv_interval($t0) * 1_000_000); $env->{psgi.error}->print($log_handler->log_line( $env,$res,6,$reqtime, $t0->[0])); } }; $app };
  • 14. OR
  • 15. Plack::Middleware::AxsLog yet another AccessLog Middleware
  • 16. use Plack::Builder; builder { enable 'AxsLog', combined => 1, response_time => 1; $app };
  • 17. OR
  • 18. Plack::Middleware::AccessLog Plack (1.0023~)
  • 19. Benchmark
  • 20. 0 10000 20000 30000 40000 50000 60000 51262 8826 Plack-1.0022 Plack-1.0029 Req/Sec
  • 21. A

×