Presentation is loading. Please wait.

Presentation is loading. Please wait.

Rob Saccoccio FastCGI Rob Saccoccio

Similar presentations

Presentation on theme: "Rob Saccoccio FastCGI Rob Saccoccio"— Presentation transcript:

1 Rob Saccoccio
FastCGI Rob Saccoccio

2 FastCGI is.. A language and server independent, scalable, open extension to CGI that provides high performance and persistence A protocol for data interchange between a web server and a FastCGI application The set of libraries that implement the protocol Enough of that ..

3 Web Server - CGI Relationship
stdin CGI stdout stderr

4 Web Server - FastCGI Relationship
full-duplex socket Server API based solutions embed the application in the web server. FastCGI Protocol

5 Backend FastCGI Server
Web Server socket FastCGI Application socket Of course because TCP sockets can be used, the application doesn’t have to be cohosted with the webserver. This can be a big advantage if your web server is exposed and your application requires access to sensitive/protected data behind a firewall. If your application is really heavy and the goal is just to distribute it for performance purposes, you could certainly run it on the web server over Unix domain sockets as well. And of course you can see how this can continue to scale. FastCGI Protocol

6 Piles of Servers FastCGI Protocol Web Server socket
FastCGI Application Using a DNS round-robin or another more sophisticated HTTP distribution approach you can have a pile of front-end web servers working with a pile of back-end FastCGI applications. Of course, this sort of capability isn’t unique to FastCGI, what makes it different and worthwhile is that its an open solution. FastCGI is totally reasonable request to make of a web server vendor. Of course, this crowd probably isn’t using anything but Apache or another open source solution so you could implement it there as well. Many of FastCGI applications interface to a database. The database(s) can run on another tier of servers. FastCGI Protocol

7 FastCGI Application Organization
Initialization Response Loop { Response Handler }

8 Perl FCGI API accept() – Accepts a new FastCGI connection request, implicitly finishes the current request flush() – Flushes output buffers finish() – Finishes the current request finish() can be used to complete a request and perform other (maintenance related tasks between requests because the accept() is an implicit finish Lincoln Stein’s CGI module also can be used A new FCGI API is in the works that object oriented, its being developed to support Perl Threads.

9 Hello World - Perl use FCGI; $count = 0; while (FCGI::accept() == 0) {
print "Content-type: text/html\r\n“, "\r\n“, "<h1>Hello World</h1>\n“, "Request “, ++$count, “ from server “, $ENV{'SERVER_NAME'}; } This too will do both CGI and FastCGI depending on how it was invoked.

10 Hello World – Perl,
use CGI::Fast qw(:standard); $count = 0; while (new CGI::Fast) { print header, h1(“Hello World"), "Request “, ++$count, “ from server “, $ENV{'SERVER_NAME'}; } You can also use the object oriented CGI interface.

11 How Fast? What’s the fork/exec mean to performance?
Compare a tiny fcgi_stdio application in both CGI and FastCGI mode. #include "fcgi_stdio.h“ main(void) { while (FCGI_Accept() == 0) { printf("Content-type: text/html\r\n“ "\r\n“ "<h1>FastCGI Hello</h1>"); } Apology for non-Perl. If there’s time, we can run a quick example.

12 Pretty Useless Statistics (PUS)
Using Apache’s ab (Apache benchmark) program with 20 simultaneous requests, 100/1000 total requests Data represents the number of requests/sec tiny1 sleeps for 1 sec in the middle of handling 1tiny sleeps for one second at initialization tiny.c tiny1.c 1tiny.c Static File (968) CGI 184 16 13 FastCGI 516 1 409 Its how it works in the real world. Machine Stats: and idle PII 350, 128M, Apache 1.3.6 Much of the benefit of FastCGI isn’t literally in the “fast”. Its in the persistence and distributed nature. Someone recently wrote to the developers list: CGI is faster for sending large responses.. The difference in speeds between the CGI and FastCGI in tiny.c show the relevance of the fork()/exec().

13 Considerations How long will a typical request take? Are there any external dependencies? What type of load will the application have? How much data is sent to/from the client? Run as many processes/threads as you need Don’t send content if a redirect will do (e.g. banner ads) Both the module and the lib use 8K buffers. In the module there’s also the Apache buffers (4K).

14 Reasons for Using FastCGI
No learning curve, everyone knows CGI Same binary works with Netscape, IIS, OpenMarket, and Apache Same code works across SPARC and Intel Allows mix-n-match OS/servers Choice of standard programming languages Flexible deployment No vendor tie or proprietary languages

15 Which Solution? Whether to use FastCGI, an embedded interpreter, a server API, or an application server depends on the project, personal experience and preferences. They’re all fast and persistent. Oreilly’s “Apache Modules” book provide a short but nice discussion of each of the approaches.

16 Summary FastCGI is a protocol and the set of libraries that implements it FastCGI provides a fairly low level toolkit for developing fast, persistent, and portable solutions

17 FastCGI Servers Apache - mod_fastcgi (free)
Zeus - Microsoft & Netscape – FastServ plug-in

18 Links The FastCGI Home Page These slides
I’ll post these slides when I get back later in the week.

Download ppt "Rob Saccoccio FastCGI Rob Saccoccio"

Similar presentations

Ads by Google