Comments (2)
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.
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)
- tests fail -- empty base class package HOT 1
- Starman in Production HOT 2
- Implement --max-keepalive-requests HOT 3
- POSIX::setgid not implemented on this architecture HOT 1
- starman hangs on make tests (Win 7, Strawberry perl) HOT 1
- Starman is missing ExtUtils::Config requirement HOT 1
- Support custom proctitles
- Dependency module name misspelling
- plackup: Use of uninitialized value $opt in lc at /home/vagrant/perl5/lib/perl5/Starman/Server.pm line 80.
- Feature request: Ability to run Starman in non-forking mode HOT 1
- How to use with systemd ExecReload and ExecStop? HOT 1
- start_server ignores https/ssl configuration of starman/plackup HOT 1
- allow client errors to be detected HOT 2
- Support for server-side trailer headers with chunk-encoded responses
- on some hosts requests are too slow - any ideas ? HOT 1
- *
- Please add config option to `chmod` a UNIX socket
- --listen and --host options do not support IPv6 addresses HOT 4
- Add worker timeout option HOT 3
- Starman worker zombie processes showing up HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from starman.