FastCGI Rob Saccoccio

Slides:



Advertisements
Similar presentations
Mod_perl High speed dynamic content. Definitions Apache – OpenSource httpd server Perl – OpenSource interpreted programming language mod_perl – OpenSource.
Advertisements

E-Commerce CMM503 – Lecture 8 Stuart Watt Room C2.
Enabling Secure Internet Access with ISA Server
Overview Environment for Internet database connectivity
Rob Saccoccio FastCGI Rob Saccoccio
CS 22: Enhanced Web Site Design - Week 8Slide 1 of 15 Enhanced Web Site Design Stanford University Continuing Studies CS 22 Mark Branom
Lecture plan Information retrieval (from week 11)
CGI & HTML forms CGI Common Gateway Interface  A web server is only a pipe between user-agents  and content – it does not generate content.
METALOGIC s o f t w a r e © Metalogic Software Corporation DACS Developer Overview DACS – the Distributed Access Control System.
Adding Dynamic Content to your Web Site
TCP/IP Protocol Suite 1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 22 World Wide Web and HTTP.
COEN 445 Communication Networks and Protocols Lab 4
Copyright 2004 Monash University IMS5401 Web-based Systems Development Topic 2: Elements of the Web (g) Interactivity.
Technical Architectures
15 Chapter 15 Web Database Development Database Systems: Design, Implementation, and Management, Fifth Edition, Rob and Coronel.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic Server Side Web Technologies: Part 2.
1 CS6320 – Why Servlets? L. Grewe 2 What is a Servlet? Servlets are Java programs that can be run dynamically from a Web Server Servlets are Java programs.
How Clients and Servers Work Together. Objectives Learn about the interaction of clients and servers Explore the features and functions of Web servers.
1 Java Server Pages Can web pages be created specially for each user? What part does Java play?
Chapter 6: Hostile Code Guide to Computer Network Security.
CGI Programming Languages Web Based Software Development July 21, 2005 Song, JaeHa.
Server-side Technologies
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 24 – Web Servers (PWS, IIS, Apache, Jigsaw) Outline 24.1Introduction 24.2Microsoft Personal.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
HTTP; The World Wide Web Protocol
Apache Server The Apache Server Apache is a WWW server that implements the HTTP protocol. Apache runs as a daemon. This means that it is a resident.
Introduction to ASP.NET. Prehistory of ASP.NET Original Internet – text based WWW – static graphical content  HTML (client-side) Need for interactive.
Chapter 33 CGI Technology for Dynamic Web Documents There are two alternative forms of retrieving web documents. Instead of retrieving static HTML documents,
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
Nic Shulver, Intro: Developing Server Applications What is a server? Many types of server – File server – file: networked file.
Implementing ISA Server Publishing. Introduction What Are Web Publishing Rules? ISA Server uses Web publishing rules to make Web sites on protected networks.
第十四章 J2EE 入门 Introduction What is J2EE ?
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
1 In the good old days... Years ago… the WWW was made up of (mostly) static documents. –Each URL corresponded to a single file stored on some hard disk.
1 Apache. 2 Module - Apache ♦ Overview This module focuses on configuring and customizing Apache web server. Apache is a commonly used Hypertext Transfer.
CHEN Ge CSIS, HKU March 9, Jigsaw W3C’s Java Web Server.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 7: HTTP and CGI Fundamentals of Web Programming.
10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0.
2-1 WEB DATABSE INTERFACING Colorado Technical University IT420.
Chapter 6 Server-side Programming: Java Servlets
1 Welcome to CSC 301 Web Programming Charles Frank.
1 © Copyright 2000 Ethel Schuster The Web… in 15 minutes Ethel Schuster
1 CS122B: Projects in Databases and Web Applications Spring 2015 Notes 03: Web-App Architectures Professor Chen Li Department of Computer Science CS122B.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
3.14 Work List IOC Core Channel Access. Changes to IOC Core Online add/delete of record instances Tool to support online add/delete OS independent layer.
© 2004 OPNET Technologies, Inc. All rights reserved. OPNET and OPNET product names are trademarks of OPNET Technologies, Inc. ARMing Apache David Carter.
Server to Server Communication Redis as an enabler Orion Free
Form Data Encoding GET – URL encoded POST – URL encoded
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
More than one site? Use multiple configuration files Use multiple configuration files  httpd –d {path}  Assumes “conf/httpd.conf” Logging transactions.
Apache Web Server Architecture Chaitanya Kulkarni MSCS rd April /23/20081Apache Web Server Architecture.
Lecture 19 Overview. Hyper Text Transfer Protocol HTTP is the protocol that supports communication between web browsers and web servers. – A “Web Server”
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
(ITI310) By Eng. BASSEM ALSAID SESSIONS 10: Internet Information Services (IIS)
Introduction to the new mainfame © Copyright IBM Corp., All rights reserved. Chapter 14a: z/OS HTTP Server.
TCP/IP Protocol Suite 1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 22 World Wide Web and HTTP.
CS122B: Projects in Databases and Web Applications Spring 2017
CS122B: Projects in Databases and Web Applications Winter 2017
Distributed Control and Measurement via the Internet
WWW and HTTP King Fahd University of Petroleum & Minerals
Netscape Application Server
MapServer In its most basic form, MapServer is a CGI program that sits inactive on your Web server. When a request is sent to MapServer, it uses.
Chapter 27 WWW and HTTP.
CS122B: Projects in Databases and Web Applications Winter 2018
CS122B: Projects in Databases and Web Applications Spring 2018
Architecture of the web
CS122B: Projects in Databases and Web Applications Winter 2019
Presentation transcript:

FastCGI Rob Saccoccio

Overview •Why FastCGI? •The Protocol •The API •Characteristics •mod_fastcgi •Summary

Dynamic Content Rules •Sites are handling unprecedented loads and generating more dynamic content •This highlights the limitations of the Common Gateway Interface (CGI) and has spawned many solutions •FastCGI was developed by Open Market in ’96 as an open solution.

CGI Weaknesses •Slow •Inherently bad for tasks that require persistent data •Doesn’t scale

CGI Strengths •Easy to use and understand •Language, platform, and server independent •Server-safe (CGIs run in a separate process) •Open standard

FastCGI Design Goals •Speed! •Eliminate CGI’s weaknesses –Scalable –Persistent •Build on CGI’s strengths –Simple, Open Standard with an easy migration path –Server, Language, & OS independent –Server Isolation

Speed! •Common Gateway Interface (CGI) requires a fork/exec per request •Very large and interpreted applications can be slow to start •Initialization such as logging on to databases, connecting to remote machines, or parsing static files can be slow

Persistence •HTTP is stateless •Persistence eliminates per-request fork/exec and application initialization delays •Persistence allows data caching (e.g. lookups, responses, calculations) •Web based applications, targeted marketing, shopping carts

Server Independence •An ideal solution isn’t server specific •Server APIs –Apache, ISAPI, NSAPI, mod_perl, etc. –Bind the solution to the server –Are generally complex or undocumented –Embed the application in the server itself

Server Independence Cont’d •Application Servers –SilverStream, HAHT, ColdFusion, etc. –Are often server independent (possibly via FastCGI), but bind a solution to the application server and its development environment –Commercial application servers can represent a non-trivial $ outlay

Language & OS Independence •An ideal solution doesn’t require the use of a specific language •FastCGI application development libraries in C, C++, Perl, Python, Java, TCL •The language/library provides the OS independence

CGI-like •Easy to use and understand •Leverage existing knowledge, tools, and installation base •Allow simple migration from CGI •Isolated from server •Ubiquitous?

Scalable •N-tier, load distribution •Mix-n-match OSs

Open Standard •Non-proprietary, no royalties •Anyone can implement it •Anyone can improve it

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

Web Server - CGI Relationship Web ServerCGI stdin stdout stderr

Web Server - FastCGI Relationship Web ServerFastCGI full-duplex socket FastCGI Protocol

Web Server socket FastCGI Application socket Backend FastCGI Server FastCGI Protocol

Web Server socket FastCGI Application socket Web Server socket FastCGI Application socket Piles of Servers FastCGI Protocol

•All data is wrapped in the protocol •A simple standard header precedes every Protocol Data Unit (PDU) •The header describes the type of data and its length

PDU Types •Begin Request •Name-Value Stream •Stdin Stream •Stdout Stream •Stderr Stream •End Request

FastCGI Header Reserved Padding Length Content Length Request Id PDU Type Protocol Version = one byte

Typical PDU Flow - To FastCGI Application To FastCGI Application Begin NV {X} NV Data NV {0} Stdin {X} Stdin Data Stdin {0}...

Typical PDU Flow - From FastCGI Application End Stdout {X}Stdout Data Stdout {0}... Stderr {X}Stderr Data Stdout {X}Stdout Data Stderr {0} To Web Server

FastCGI Roles •Responder •Authorizer •Filter

Responder Role •The fundamental FastCGI role •Functionally identical to CGI •Supported by all FastCGI capable servers

Authorizer Role •Provides a means of controlling access to a site, a page, or something in between •Typically, this involves some form of authentication, but this isn’t required •It has server dependent significance

Filter Role •Allows “processing” of a file before it is sent •Intended to support: –Format conversions –Dynamic documents (embedded code) –Applying templates: e.g. headers, footers, backgrounds •Conceptually this could support dynamic content chaining, but without server support has limited utility

FastCGI Applications •Application Organization Initialization Response Loop { Response Handler } •Eliminate leaks •Review 3 rd party libraries/modules •Compress functionality

Perl FCGI API •accept() – Accepts a new FastCGI connection request, implicitly finishes the current request •flush() – Flushes output buffers •finish() – Finishes the current request

Hello World - Perl use FCGI; $count = 0; while (FCGI::accept() == 0) { print "Content-type: text/html\r\n“, "\r\n“, " Hello World \n“, "Request “, ++$count, “ from server “, $ENV{'SERVER_NAME'}; }

Hello World – Perl, CGI.pm use CGI::Fast qw(:standard); $count = 0; while (new CGI::Fast) { print header, h1(“Hello World"), "Request “, ++$count, “ from server “, $ENV{'SERVER_NAME'}; }

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“ " FastCGI Hello "); }

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.c1tiny.ctiny1.c Static File(968) CGI FastCGI (1 process)

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. images)

mod_fastcgi •Authorizer and Responder Roles •Process Management •Static and dynamic servers •Suexec wrapper support

mod_fastcgi Directives •FastCgiServer •FastCgiExternalServer •FastCgiConfig •FastCgiIpcDir •FastCgiSuexec •FastCgiAuthenticator •FastCgiAuthorizer •FastCgiAccessChecker

FastCgiServer •FastCgiServer filename [option …] •Defines a FastCGI application to be started and managed by mod_fastcgi •Optional arguments for identifying: –Connection characteristics - socket type, backlog depth, blocking or non-blocking connect(), timeouts, flush, passed headers –Application invocation: process priority, process count, environment, start and restart delays

FastCgiExternalServer •FastCgiExternalServer filename -host host:port [options..] FastCgiExternalServer filename -socket filename [options..] •Defines a FastCGI application that is managed external to mod_fastcgi •Requires identifying the whereabouts of the socket •Optional arguments for identifying: –Connection characteristics - blocking or non-blocking connect(), timeouts, flush, passed headers

FastCgiConfig •FastCgiConfig [options..] •Controls the characteristics of “dynamic” handling •Determines how and when dynamic FastCGI applications are spawned and killed based on demand (response delay) •Optional arguments for identifying: –Connection characteristics – backlog depth, blocking or non- blocking connect(), timeouts, flush, start delay, passed headers –Application invocation – process priority, process counts, environment, start and restart delays, auto update –Process Manager characteristics – gain, intervals, thresholds,

FastCgiIpcDir •FastCgiIpcDir directory •Specifies a directory for the Unix Domain sockets •The default is /tmp/fcgi - this is sometimes problematic (cron jobs doing cleanup)

FastCgiSuexec •FastCgiSuexec On | Off | filename •Enables the use of a wrapper that is used to invoke the FastCGI applications •Typically the wrapper is “suid root” and is used to run the applications with different a user/group specified by a convention or file •Works in conjunction with Apache’s suexec User and Group directives

Auth Directives •FastCgiAuthenticator, FastCgiAuthorizer, FastCgiAccessChecker share their syntax but function in different Apache phases •The authorizer can be dynamic or static •The –compat option forces compliance with the FastCGI specification (less variables are made available to handlers)

Auth Directives Cont’d. •All are considered FastCGI Authorizers, but the FCGI_APACHE_ROLE variable is set to differentiate them •Each of the directives also have an associated Authoritative directive that allows other modules a crack at the phase

FastCgiAccessChecker •FastCgiAccessChecker filename [-compat] •AccessCheckers determine whether to grant access based on “other” data (e.g. client IP, presence of a valid cookie, time of day, etc.) •Access is independent of and takes place before user authentication and authorization

FastCgiAuthenticator •FastCgiAuthenticator filename [-compat] •FastCgiAuthenticators authenticate users by name and password •Uses HTTP Basic authentication •The user’s password is made available in the REMOTE_PASSWORD variable •Can be used with the core authorizers directives, such as “ requires valid-user ”

FastCgiAuthorizer •FastCgiAuthorizer filename [-compat] •FastCgiAuthorizers determine whether to grant an authenticated user access •Can be used in conjunction with any authenticator •The user’s password is not passed to the FastCGI application

Example Configuration # Config used for dynamic applications FastCgiConfig -initial-env PATH=/usr/bin -maxClassProcesses 10 -startDelay 1 # Start/manage 10 copies of my-fcgi-app FastCgiServer fcgi-bin/my-fcgi-app -processes 10 # Send requests for my-ext-fcgi-app to db-server for handling FastCgiExternalServer fcgi-bin/my-ext-fcgi-app -host db-server:5018 # All requests in this directory are FastCGI SetHandler fastcgi-script # Dynamic FastCGI applications require this flag to be on Options ExecCGI

Example Configuartion Cont’d. # All requests ending with these extensions are FastCGI AddHandler fastcgi-script.fcg.fcgi.fpl # Identify it as an access checker (it looks for a valid cookie) FastCgiAccessChecker htdocs/killer-app/authorizer # Start/manage the kill-app authorizer FastCgiServer htdocs/killer-app/authorizer # Pass all requests through the (dynamic FastCGI) sanitizer Action default-handler fcgi-bin/sanitizer.fcgi

•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 Reasons for Using FastCGI

Which Solution? •Whether to use FastCGI, an embedded interpreter, server API, or application server depends on the project, personal experiences and preferences. •They’re all fast and persistent.

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

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

Thanks •Sven Verdoolaege •Jonathan Roy •Bill Snapper •Infinite Technology, Inc.

Links.. •The FastCGI Home Page – •These slides –