Web Server Architectures

download Web Server Architectures

of 17

Transcript of Web Server Architectures

  • 7/31/2019 Web Server Architectures

    1/17

    Web ServerArch i tec tu res

    CS 4244: Internet Programming

    Dr. Eli TilevichBased on Flash: An Efficient and Portable Web Server, Vivek S. Pai, PeterDruschel, and Willy Zwaenepoel, 1999 Annual Usenix Technical Conference,Monterey, CA, June 1999.

  • 7/31/2019 Web Server Architectures

    2/17

    Design Goa ls

    Performance & Quality of Service (Systems) Good respons iveness; low la t enc y Good c oncur rency

    Can support multiple clients simultaneously High t hroughput

    Grac efu l degradat ion

    Low mem ory c onsum pt ion

    Ease of development (Software Engineering) Sim ple t o underst and, f ine-t une, add new features,

    debug, e t c .

  • 7/31/2019 Web Server Architectures

    3/17

    What Web Servers Do

    In response to a Web client request(e.g., http://google.com/index.html) a Web server: netw ork c onnec t ion

    t he request (index .h tm l ) f i le from d isk o r runs a dynam ic c on ten t

    generator

    c ont ent (headers and body) bac k

    http://google.com/index.htmlhttp://google.com/index.html
  • 7/31/2019 Web Server Architectures

    4/17

    Single-Threaded Web Server

    One process sequentially handles all client connections

    Simple requires no synchronization Does not scale (one client at a time)

    AcceptConnection

    Parse HTTPRequest

    Read File or

    generate contentSend Data

  • 7/31/2019 Web Server Architectures

    5/17

    Opt imizat ions?

    Caching Pat hnam e t rans la t ion

    Som e dynam ic c on ten t

    Fi le operat ions

  • 7/31/2019 Web Server Architectures

    6/17

    Addi t ional Feat ures of Web Servers

    Logging Security (e.g., access control)

    Traffic analysis

    Require centralized data structures to implement

  • 7/31/2019 Web Server Architectures

    7/17

    Main Server Arc h i t ec t ures

    Multi-process (Apache on Unix) Multi-threaded (Apache on NT/XP)

    Single process event driven (Zeus, thttpd)

    Asymmetric multi-process event-driven (Flash)

  • 7/31/2019 Web Server Architectures

    8/17

    Mul t i -Proc ess Arc h i t ec t ure

    Utilizes multiple processors

    Easy to debug

    Can pre-fork a pool of processes

    Inter Process Communication is difficult and expensive

    High memory cost, context switches

    AcceptConnection

    Parse HTTPRequest

    Read File or

    generate contentSend Data

    Accept

    Connection

    Parse HTTP

    Request

    Read File or

    generate content

    Send Data

    Process 1

    Process N

  • 7/31/2019 Web Server Architectures

    9/17

    Mul t i -Threaded Arc h i t ec t ure

    Utilizes multiple threads, good performance

    Easy to change threading policies

    Need to synchronize, to avoid data races

    Resources utilization (kernel and user-level): m emory consumpt ion, c on tex t sw i tc hes, s ta r tup

    Blocking I/O can cause deadlocks

    AcceptConnection

    Parse HTTPRequest

    Read File or

    generate contentSend Data

  • 7/31/2019 Web Server Architectures

    10/17

    Sing le Proc ess Even t -Dr iven

    Use a selector to check for ready file descriptors

    Uses a finite state machine to determine how to move to the next

    processing stage

    No context switching, no synchronization, single address space

    Modern OS do not provide adequate support for asynchronous disk

    operations

    AcceptConnection

    Parse HTTPRequest

    Read File or

    generate contentSend Data

    Event Dispatcher

  • 7/31/2019 Web Server Architectures

    11/17

    Asym m et r ic Mul t i -Proc ess Event -Dr iven

    Similar to Single Process Event-Driven but with helpers

    for blocking I/O (e.g., disk requests)

    AcceptConnection

    Parse HTTPRequest

    Read File or

    generate contentSend Data

    Event Dispatcher

    Helper 1 Helper N

  • 7/31/2019 Web Server Architectures

    12/17

    Real Work load (On Solar is )

  • 7/31/2019 Web Server Architectures

    13/17

    Perform anc e in WAN(Adding Cl ient s)

  • 7/31/2019 Web Server Architectures

    14/17

    Per form anc e Com par isonMP MT SPED AMPED

    Disk

    Blocking

    +(only one

    proc.)

    + - (wholeserver proc.

    blocks)

    +

    Memory

    Cons.

    -(separate

    mem. spaceper proc.)

    + + +

    Disk

    Usage

    + + - (one diskrequest at a

    time)

    +

  • 7/31/2019 Web Server Architectures

    15/17

    Chal lenges of Using Threads

    Need for synchronization Deadlocks, starvation

    Race conditions

    Scheduling can be tricky

  • 7/31/2019 Web Server Architectures

    16/17

    Chal lenges of Using Event s

    Only one process/thread is used High latency for long running handlers

    Control flow is obscure

    Difficult to write, understand, and modify

  • 7/31/2019 Web Server Architectures

    17/17

    Hybrid Approac h

    SEDA: Staged Event-Driven Architecture

    , Mat t Welsh , David Cul le r, and EricBrew er . In Proc eedings o f t he Eight eent h Sym posium onOpera t ing Syst em s Prin c ipl es (SOSP-18), Banff , Canada,

    Oc t ober , 2001.

    Uses thread pools and events

    Events organized into stages

    Each stage has a thread pool

    Load conditioning; graceful degradation