Fine Tuning Python WSGI and ASGI applications for Flask, Django, and FastAPI
Firstly covering the simpler of the two options, the ASGI/WSGI web server that goes between your Python code in the web framework and the users who have a web browser:
Gunicorn is the most popular WSGI server
Uvicorn is an ASGI server. It is both a standalone server as well as a plugin for Gunicorn
Hypercorn is an alternative that supports both WSGI and ASGI
Please add info into DOC how to run PSGI under CGI · Issue #566 · plack/Plack · GitHub
Please put this into synopsys of 'plackup' $ SCRIPT_NAME='/' REQUEST_METHOD='GET' SERVER_NAME='www.test' SERVER_PORT='5000' plackup -s CGI t.pl
Also:
https://github.com/plack/Plack/issues/598
https://github.com/plack/Plack/issues/147
https://github.com/plack/Plack/pull/159/files
https://github.com/plack/Plack/pull/217
https://github.com/plack/Plack/pull/235
Moving from CGI to PSGI and Starman
Moving from an old CGI application to Plack/PSGI in CGI mode and to running it in the Starman application server.
Modern Perl CGI | Aristotle [blogs.perl.org]
A modernisation of this using Plack is straightforwardly equivalent:
#!/usr/bin/env perl
use strict;
use warnings;
use Plack::Request;
use Encode::Simple;
use JSON::MaybeXS;
my $app = sub {
my $req = Plack::Request->new($_[0]);
my $input = eval { decode 'UTF-8', $req->parameters->{'input'} };
[ 200, [ 'Content-Type', 'application/json; charset=UTF-8' ], [ encode_json { output => uc $input } ] ];
};
This is now a full PSGI app and as such gains all the same additional deployment options of the Mojolicious example. To deploy it as a CGI script you add this line at the bottom:
use Plack::Handler::CGI; Plack::Handler::CGI->new->run($app);
In all it takes about twice as long to load as the CGI.pm example, compared to the Mojolicious example taking about 7× as long. In exchange you get all the benefits of the PSGI ecosystem – without losing any of the strengths of deploying as a CGI script, unlike the Mojolicious example.