Detecting Leaky Objects

Overview

Recently dandv noticed that MojoMojo processes were possibly leaking memory. An semi-formal investigation was done in order to look into this further. This paper describes what was done to determine that there was indeed a leek, and that the Syntax::Highlight::Engine::Kate module was causing the majority of it. Jam Tangan Murah timbangan Penumbuh Rambut Bisnis Modal Kecil

Verifying a Leak.

The process I used to verify a leak was such:

  • Start a window with top running. Monitor the RES column (RAM used) for mojomojo_server.pl
  • Start an instance of MojoMojo using the development server:
    script/mojomojo_server.pl
  • Make one request to http://localhost:3000/ (get MojoMojo fully loaded on the root page).
  • Note the MB of usage by the perl process behind MojoMojo (often around 115MB is what it started at).
  • Make 100 request of the root page (http://localhost:3000/) using the Apache Benchmark utility ab:
    ab -n 100 http://localhost:3000/
  • Note the amount of RAM used by the MojoMojo perl process,

Tracking Objects Not Destroyed

A nifty module called Devel::Leak::Object allows one to see what objects have not been garbage collected. It will list the object class and how many objects of the class type are left upon exit of the program.

Create MojoMojo::Controller::Root::exit() action

In order to useDevel::Leak::Object on MojoMojo we need a way to exit from the process so that we can get the results. To exit from the MojoMojo server we setup an exit action1. This action will run based on an environment variable being set2. Here's the code:

sub exit : Local {
    my ($self$c) = @_;
    if ($ENV{MOJOMOJO_EXIT_OK}) {
        exit(0);
    }
    else {
       # $c->stash( template => 'error.tt' );
        $c->res->status (403); # forbidden
        $c->res->body('EXIT NOT OK');
        $c->detach();
    }
}

Set Environment Variable to Enable exit()

Notice the exit() action only exits when the environment variable MOJOMOJO_EXIT_OK is set. This is done from bash as:

export MOJOMOJO_EXIT_OK = 1

Start MojoMojo with Devel::Leak::Object Enabled

perl -MDevel::Leak::Object=GLOBAL_bless script/mojomojo_server.pl -d

This tracks all objects3.

Generate Data

We will generate data for the object tracking report by making requests as we did before:

Make Requests

ab -n 100 http://localhost:3000/

Exit MojoMojo Process

Use the exit action (MojoMojo remaps /exit to /.exit) to terminate the MojoMojo process and get the object tracking report. Request:

http://localhost:3000/.exit

Object Report

What appears on STDOUT4 is the report which looks like this:

leak_report.txt

On the first run of 100 requests (using ab) it was not apparent which module(s) might be leaking. But when I made another test run with a different amount of requests, 50, two lines stood out:

Syntax::Highlight::Engine::Kate          50
Syntax::Highlight::Engine::Kate::Perl    50

What I discovered was that these two modules were leaving an object behind for every request. i.e. when I ran ab -n 100 http://localhost:3000/ I saw 100 of these objects leftover. When I ran ab -n 50 http://localhost:3000/ I saw 50 of these objects leftover. In contrast all other object were independent of the number of requests made to the MojoMojo server.

Examine How MojoMojo Uses Syntax::Highlight::Engine::Kate

Now that we have a smoking gun for the leaky module, I wanted to test the memory leak rate without it. I scanned the MojoMojo code base for use of the module and found it used in:

  • MojoMojo::Controller::PageAdmin
  • MojoMojo::Formatter::SyntaxHighlight
  • MojoMojo::Formatter::DocBook::Colorize

I focused my attention on SyntaxHighlight and its method _kate(). This method was being called from another method format_content(). What I found was:

  • with my $kate = _kate() being declared inside format_content(), the RAM usage increased by 15MB/100 requests

Reduced Leakage Solution

When I mentioned this leak to Marcus, he suggested scoping the $kate variable to the package instead of just the subroutine. In doing so, what I found was:

  • with my $kate scoped to package (outside format_content), the RAM usage dropped to 2-3MB/100 request. This translates to decreasing the memory leak to ~1/5 the original amount.

Further Investigation

In the edit() action of PageAdmin a new Syntax::Highlight::Engine::Kate object is created. It may be leaky as well.

Footnotes

Jasa SEO Jasa SEO Murah Jasa SEO Murah Jasa SEO Jasa Adwords Jasa Google Adwords Google Adwords Sepatu Online Toko Sepatu Online Sepatu Sepatu Murah Sepatu Safety Sepatu Futsal Cheapes Hostgator Coupon Link Booking Televisori offerte Notebook Offerte Berita Terkini Internet Marketer Muda Internet Marketer Indonesia Portatile Apple RDAnet Lorks Karikatur Bisnis Modal Kecil Bisnis UKM Berita Terbaru Iklan Baris Jasa SEO Jasa SEO Murah SEO Indonesia Konsultan SEO SEO Belajar SEO Kursus SEO Kursus SEO Murah Jam Tangan Casio Jam Tangan Casio Jam Tangan Murah Jam Tangan Grosir Baju Terbaru Grosir Baju Baju Terbaru Grosir Baju Murah Bisnis Online Belajar SEO Kerupuk Kerupuk kulit Social Bookmark Dofollow Social Bookmark Kumpulan Puisi Kirim Puisi Penumbuh Rambut Penumbuh Rambut timbangan WBC Wonogiri Jasa SEO Murah Jasa SEO Jam Tangan Murah Jam Tangan Murah Kata Gaul

Cupu Berita Terbaru Android Store Upinson Berita Terkini Edo Ziedo Aplikasi Symbian Sepatu Safety Upin Upin Tablet Android Sepatu Murah Upinson Blogger Radio Streaming SEO Star Upinson Cinta EDU Jasa SEO Sepatu Murah Sepatu Murah Sepatu Murah Penumbuh Rambut Penumbuh Rambut Penumbuh Rambut Penumbuh Rambut Penumbuh Rambut Penumbuh Rambut Penumbuh Rambut

Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman Laku.com Belanja Online Grosir Eceran Murah dan Aman villa bali seminyak accommodation seminyak villa rental villa ubud bali villa in seminyak bali driver
seminyak villa pemanas air pulau tidung jam tangan tas branded rental mobil semarang kursi roda jual kursi roda souvenir jogja dealer daihatsu depok dealer daihatsu tangerang tutorial wordpress :: Hot News :: Toko Bunga :: Online Store :: Seminyak bali :: Grosir Baju muslim :: Grosir Baju Batik :: Hosting Murah :: Villa Bali rental :: Group Om Onny :: Jawara Iklan :: Jago Iklan :: Jasa Iklan :: Juara Iklan :: Jawa Iklan :: Jaringan Iklan :: Jaguar Iklan :: All Iklan :: Directory :: Tas Branded :: Souvenir Pernikahan :: Busana Online :: Review :: Naila :: Naura :: Karangan Bunga Pekanbaru :: Karangan Bunga Medan :: Toko Parcel Medan :: Toko Parcel Surabaya :: Toko Parcel Jogja :: Serba-serbi :: Toko Parcel :: Berita Unik :: Toko Abon :: Tips :: Blog :: All tips :: Coba :: sinergi :: bisnis :: om onny jasa seo jasa seo murah jasa seo jasa seo murah jasa seo murah jasa seo murah jasa seo murah


  1. This example is inspired from the review of Devel::Leak::Object on CPAN Ratings ↩

  2. This provides us a way to prevent the exit action from being triggered in production by the general public. ↩

  3. Actually only objects loaded after bless has been overloaded with GLOBAL_bless. See the documention for more details, but it is simply a matter of when the leak tracking becomes available. There may be objects loaded before it's cocked and loaded. ↩

  4. Report output goes to STDERR in patched version 0.92 of Devel::Leak::Object. ↩

My tags:
 
Popular tags:
 
Powered by Catalyst