I'm currently running Apache/mod_perl with a PSGI-application invoked by Plack::Handler::Apache2. The problem we have is each Apache process consumes a connection to the PostgreSQL database, which is expensive. To solve this, we plan to run the PSGI-application separate from Apache, and let all Apache processes communicate with it over a UNIX domain socket. What setup would you recommend in my case?
My plan is to run it using plackup:
plackup -s FCGI -E production --nproc 100 --daemonize --listen /tmp/myapp.sock \
/usr/local/bin/myapp.psgi
I asked the author of Plack, Tatsuhiko Miyagawa, if plackup -s FCGI is recommended for production purposes. He provided the following answer:
"while it could be used for production, i usually recommend using other specialized servers such as Starman, Starlet or uwsgi. FCGI is an exception because we don't have a specific FCGI daemon other than the default Plack::Handler. We have a plan to split out FCGI out of Plack core and make that a separate installation."
Now, until FCGI is splitted out of Plack, the question is therefore, what is the best possible way to run a PSGI application using FastCGI outside of Apache?
If you insist on using the FastCGI protocol, you can make Apache connect to an external FastCGI server using mod_fastcgi
and the FastCgiExternalServer
directive (note that mod_fcgid
does not support this mode of operation). This should work with the FCGI handler built into Plack.
But as Tatsuhiko said, it's recommended to use a server like Starman or Starlet that works as reverse proxy over HTTP. So you would use mod_proxy
on the Apache side. With Apache 2.4.7, it's also possible to communicate over Unix domain sockets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With