Giter Club home page Giter Club logo

Comments (2)

miyagawa avatar miyagawa commented on August 15, 2024

This is a bit tricky. I guess what we want to do is a) preload the app by default and allows users to regsiter hooks and b) Do not preload the app but loads them in a forked children. By 'and' i mean users should be able to choose which.

A patch like http://gist.github.com/346693 in Starman and then write a Delayed loader for Plack like:

package Plack::Loader::Delayed;
use strict;
use parent qw(Plack::Loader);

sub preload_app {
    my($self, $builder) = @_;
    $self->{builder} = $builder;
}

sub run {
    my($self, $server) = @_;
    $server->{psgi_app_builder} = $self->{builder};
    $server->run(sub { die "-L Delayed should be combined with Starman" });
}

would do b) with starman -L Delayed. The loader is currently coded to die other than Straman but could be made generic to compile the app in the first run. That way your .psgi is evaluated per child, which nukes copy-on-write but you could also preload modules (not applciations) with -M command line options, like you do with Shotgun loader.

Doing a) is more complicated since most of the time a PSGI application coderef encloses more information about the application you run, with a configuration info etc. and because PSGI application is a code ref, it's not easy to define a generic way to access those information. The easiest and hackiest thing you can do is to send a fake HTTP request to the PSGI app like:

use MyApp;
my $app = MyApp->new;
sub {
    my $env = shift;
    $app->init if $env->{'starman.after_fork'};
    $app->run_psgi($env);
};

and then create a new PSGI env in the child init hook to send to the app. It's clever but a gross hack and I want to avoid this kind of thing.

from starman.

miyagawa avatar miyagawa commented on August 15, 2024

I'm fine with -L Delayed + child_init_hook patch as long as -M option allows preloading modules, since this technique can be applied and reused in other servers such as Starlet.

The other way to implement this is to take -c option or whatever in starman command line rather than plackup -s Starman and parse the config file which is just a perl DSL file to register hooks. Those solutions could also co-exist.

from starman.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.