Improving mod_perl Driven Site’s Performance — Part IV: Sharing Memory Page 6

執筆者
Stas Bekman
Stas Bekman
Published: Jan 8, 2001
Updated: Nov 10, 2020
2 minute read
ServerWatch のコンテンツおよび製品のおすすめは、編集上の独立性を保っています。パートナーへのリンクをクリックすると、当社が報酬を得る場合があります。 詳細を見る



I’m going to use the Apache::Registry script memuse.pl which
consists of two parts: the first one preloads a bunch of modules (that
most of them aren’t going to be used), the second part reports the
memory size and the shared memory size used by the single child
process that I start. And of course it prints the difference between
the two sizes.

  memuse.pl
  ---------
  use strict;
  use CGI ();
  use DB_File ();
  use LWP::UserAgent ();
  use Storable ();
  use DBI ();
  use GTop ();
  my  = shift;
  ->send_http_header('text/plain');
  my  = GTop->new->proc_mem(20992);
  my   = ->size;
  my  = ->share;
  my   =  - ;
  printf "%10s %10s %10sn", qw(Size Shared Difference);
  printf "%10d %10d %10d (bytes)n",,,;

First I restart the server and execute this CGI script when none of
the above modules preloaded. Here is the result:

     Size   Shared     Diff
  4706304  2134016  2572288 (bytes)

Now I take all the modules:

  use strict;
  use CGI ();
  use DB_File ();
  use LWP::UserAgent ();
  use Storable ();
  use DBI ();
  use GTop ();

and copy them into the startup script, so they will get preloaded.
The script remains unchanged. I restart the server and execute it
again. I get the following.

     Size   Shared    Diff
  4710400  3997696  712704 (bytes)

Let's put the two results into one table:

  Preloading    Size   Shared     Diff
     Yes     4710400  3997696   712704 (bytes)
      No     4706304  2134016  2572288 (bytes)
  --------------------------------------------
  Difference    4096  1863680 -1859584

You can clearly see that when the modules weren't preloaded, the shared
memory pages size were about 1864Kb smaller relative to the case
where the modules were preloaded.

Assuming that you have had 256M dedicated to the web server, if you
didn't preload the modules, you could have:

  268435456 = X * 2572288 + 2134016
  X = (268435456 - 2134016) / 2572288 = 103

103 servers.

Now let's calculate the same thing with modules preloaded:

  268435456 = X * 712704 + 3997696
  X = (268435456 - 3997696) / 712704 = 371

You can have almost 4 times more servers!!!

Remember that I have mentioned before that memory pages gets dirty
and the size of the shared memory gets smaller with time? So I have
presented the ideal case where the shared memory stays
intact. Therefore the real numbers will be a little bit different, but
not far from the numbers in our example.

Advertisement

Also it's obvious that in your case it's possible that the process
size will be bigger and the shared memory will be smaller, since you
will use different modules and a different code. So you won't get this
fantastic ratio, but this example certainly helps to feel the
difference.

References

Stas Bekman

Stas Bekman is a ServerWatch contributor.

ServerWatch Logo

ServerWatch is a top resource on servers. Explore the latest news, reviews and guides for server administrators now.

TechnologyAdvice が所有・運営しています。 © 2026 TechnologyAdvice. 無断転載を禁じます

広告主に関する開示:このサイトに掲載されている製品の一部は、TechnologyAdvice が報酬を受け取っている企業のものです。この報酬は、製品がこのサイトのどこにどのように表示されるか(表示される順序など)に影響する場合があります。TechnologyAdvice は、市場で入手可能なすべての企業やすべての種類の製品を掲載しているわけではありません。