DBI connection pooling and preforking HTTP servers
Clone this wiki locally
Short answer: Use DBIx::Class or DBIx::Connector to make things work when preloading apps
Preforking HTTP servers usually have an option to preload your application in the startup. Starlet does it by default and Starman can be enabled to use
--preload-app option. If your application setup connects to the database using DBI, the connection made during the setup will be eventually shared by forked children and things will break.
If you use DBIx::Class or DBIx::Connector module from CPAN, it will disconnect after the setup and reconnect on first request. If your application setup doesn't make DBI connections at all, you don't need to worry about it.
The easy way to confirm whether your application setup makes a database connection is to run:
DBI_TRACE=1 perl -e 'print do $ARGV' app.psgi