Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: PSGI / Plack

by Logicus (Initiate)
on Aug 18, 2011 at 01:46 UTC ( [id://920832]=note: print w/replies, xml ) Need Help??


in reply to Re: PSGI / Plack
in thread PSGI / Plack

Do you mind if I ask why not under apache?

Replies are listed 'Best First'.
Re^3: PSGI / Plack
by jdrago999 (Pilgrim) on Aug 19, 2011 at 00:26 UTC

    Do you mind if I ask why not under apache?

    One example is a job queue server. Because you could run into a race condition where two simultaneous requests to the server fetch the same job from the queue, one solution is to have a single process server responding to requests for new jobs. Because there is only one process listening, you can guarantee that once a job is assigned to one client it will not be assigned to any other clients.

    If the job queue server ran under Apache, it might be more difficult to lock and synchronize the job queue while a job is assigned to a client requesting a job, because of Apache's multi-process/thread model.

    Another example is a wrapper to a program which can only handle one request at a time - like skype's dbus api. I used a Plack/PSGI app to host the code that actually makes the skype dbus api call. I don't expect the application to get *that* much load, but forcing everything through a single thread of execution in this case worked for me.

    NOTE: In the above examples I'm using plackup which allows me to run everything inside a single process. Starman for example is another PSGI server which is high performance and will let you run in a multi-thread/process model like you get with Apache httpd. Having the ability to choose between execution styles is very powerful - especially when it requires absolutely no change to your own code.

    Another reason to handle some jobs in an out-of-apache process (yet persistent) is for performance. Say I have to use some memory hog module or read in large files which causes my memory footprint to grow. I can't really do that in all of my apache processes because I might run out of RAM. Using a PSGI server like plackup or starman to host the memory hog in a persistent environment will give you better performance than executing the same code from a system(...) call, and you can also play with the maximum number of running threads your memory hog can use, further preventing memory problems. If I had to run everything in my Apache httpd processes I might quickly run out of RAM on web applications which deal with video encoding for example.

    Also if you find yourself in need of deploying updates to your code, a PSGI-based application which allows you to execute a few commands (handle the upload of new files, extract them into place, restart apache, etc) simply could not be done from within Apache. Not reliably anyway.

Re^3: PSGI / Plack
by Your Mother (Archbishop) on Aug 18, 2011 at 02:10 UTC

    Here is an example of such a simplistic standalone app: Re: Networking Perl — and some commentary/discussion: Need Help in Understanding Some Code - Map and Scalar Questions.

    When you run something like that with an engine like Starman (or Twiggy or plackup or…) you get a hot-restartable, hot-worker-assignable, little speed-demon with a tiny footprint that can be tested easily. Apache is deep and venerable but there are many ways to skin the HTTP cat. Many app developers today deploy on nginx or lighttpd instead for example. They do not have the feature bag apache does but they outperform it handily on several levels in simple webservice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://920832]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-03-29 14:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found