Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

the Dancer advent calendar says that:

Use Starman's --preload-app option to enable this (but be aware that this can cause Bad Things to happen if resources like database connections or other sockets are opened by your app at compile time, as they will be unintentionally shared amongst child processes.

what is actually meant by that? when a url is requested my route is calling the model which opens a database connection, does sql and closes the connection.
So this is done at runtime. when would calling database connection at compile time then ? also calling connect_cached would cause any problems under a preforked server like starman?

Replies are listed 'Best First'.
Re: Dancer calling database connection
by Anonymous Monk on Sep 18, 2015 at 21:34 UTC

    what is actually meant by that? when a url is requested ...

    Basically its this use YouApp; YourApp->to_psgi; where to_psgi returns an $app

    This shouldn't result in DBI->connect being called; If it does docs say don't use preload

    Then later when a user makes http request to .../foo $app->() gets called

    But to be sure if it can work or not, try it

    also calling connect_cached would cause any problems under a preforked server like starman?

    Probably not, but its easy to test

    Remember to turn on https://metacpan.org/pod/DBI#AutoInactiveDestroy