Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: When does it make sense to preload modules when starting Starman?

by Corion (Patriarch)
on Oct 28, 2021 at 10:26 UTC ( [id://11138140]=note: print w/replies, xml ) Need Help??


in reply to When does it make sense to preload modules when starting Starman?

IMO it makes sense to preload modules if these modules take a long time to initialize and you have a good chance of sharing their data among the forked copies.

Examples I can think of are caching some (largish) resources in memory, or modules that autogenerate lots of code.

Database connections sound interesting, but usually, DBI database handles need to be reinitialized after a fork() call, so that won't work.

  • Comment on Re: When does it make sense to preload modules when starting Starman?
  • Download Code

Replies are listed 'Best First'.
Re^2: When does it make sense to preload modules when starting Starman?
by karlgoethebier (Abbot) on Oct 28, 2021 at 11:08 UTC
    "... modules take a long time to initialize..."

    Ja, ja or yes sure as you like. This is what common sense tells us.

    But consider this funny little study i recently posted:

    # app.psgi use strict; use warnings; use Plack::Request; use Plack::App::URLMap; use JSON::Tiny qw(encode_json); my $slash = sub { my $env = shift; my $json = encode_json {nose => 'cuke'}; my $status = 200; my $request = Plack::Request->new($env); my $headers = [ 'Content-Type' => 'application/json', 'Content-Length' => length $json, ]; my $body = [ $json ]; [ $status, $headers, $body ]; }; my $urlmap = Plack::App::URLMap->new; $urlmap->mount( "/" => $slash ); my $app = $urlmap->to_app; __END__

    Preloading the Plack stuff? JSON::Tiny might be cheap but who knows.

    It is really difficult to find answers for these questions.

    And what if i daemonize Starman? The switches for this task are confusing.

    Thanks for your kind reply and best regards, Karl.

    P.S.: I asked the author. Probably he will enlight us.

    «The Crux of the Biscuit is the Apostrophe»

      > > "... modules take a long time to initialize..."

      > It is really difficult to find answers for these questions.

      Is it? To benchmark initialization, measure time in BEGIN, CHECK and INIT blocks.

      From what I heard is Moose a good candidate.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        "...From what I heard...Moose..."

        I do not plan no more to go for another mysterious traveller. Once upon a time i gave it a try and abandoned all hope afterwards as hostile takeover was my first impression. Your mileage may vary. Best regards, Karl

        «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11138140]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-18 23:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found