Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

You have several deployment solutions, but they all boil down to an initial choice between two main options:

  1. You can serve the app through Apache, so it appears to be just one more "page" on your current web server; or

  2. You can serve the app through a stand-alone server, in which case it will be running on a different port (or even on a different host if you liked). Optionally, Apache can be configured to use mod_rewrite/mod_proxy to make the app appear like you've used choice #1 above.

If you want to serve your app through Apache, mod_perl is usually a fairly simple way to set it up, and a reasonably efficient way to run it, but you've already ruled that out. You can accomplish something similar using FastCGI, though I've always found that trickier to set up.

The final Apache-based way is to deploy a PSGI script as CGI. Just rename your .psgi file to .cgi, mark it as executable (chmod +x), and make sure it includes this shebang line:

#!/usr/bin/env plackup

Now it's just a regular CGI script, albeit one that uses Plack a lot internally. See Plack::Handler::CGI for details. This is a really easy deployment option, which works just about anywhere. However, because your whole PSGI app needs to be loaded for each request, it's not an especially efficient solution. (For simple apps that don't load a bajillion modules, it's often perfectly acceptable.)

Using a stand-alone server though is generally the most popular option. There are various PSGI servers on CPAN, including Starman and HTTP::Server::PSGI (which comes bundled with Plack). They each have different performance profiles. Generally speaking, you trade CPU for memory. The faster ones take up more memory. The smaller ones are slower. Test out a few, and see which one performs best for your app.

As you have noted, you'll want to run this as a background process, and probably do things like monitor it, to check that it doesn't crash (and automatically restart it if it does crash), and have it auto-restart after a hardware reboot, and so on.

For this I strongly recommend using Ubic to create /etc/rcX.d/-style services. In particular, you'll want the Ubic::Service::Plack plugin (or if you deploy via Starman, Ubic::Service::Starman is another option).

For my personal site, I use an interesting blend of Perl solutions. Most of the site are static HTML pages, generated from Atom by a Perl script, and served though Apache. The e-mail contact form is a PSGI app deployed via CGI. My SPARQL endpoint is another PSGI app running on a stand-alone HTTP::Server::PSGI server, using Ubic to keep it running, and with some custom Ubic plugins to monitor its memory usage, and restart it if the process gets too big. Over-engineering much?

Anyway, I'll stop rambling, but I hope this has been of some help.

TL;DR: use Ubic


In reply to Re: Change cgi script to PSGI app by tobyink
in thread Change cgi script to PSGI app by mohan2monks

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-24 16:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found