[11/15/2011] Server Types: ------------- (1) Iterative Server: each client request is processed in its entirety before accepting the next. Use (1) if connection time frames are very short; avoids overhead and complexity; ensure mutual exclusion (2) Concurrent "fork" server: clients handled via dedicated child processes; server can "serve things up" to multiple clients in parallel Use (2) for relatively few connections that do extensive reading/writing over relatively long periods of time (deal with zombie processes) (3) Concurrent "thread" server: clients handled via dedicated child threads; server can "serve things up" to multiple clients in parallel (3) is similar to (2), though threads are lightweight; need to deal with synchronization (4) Pre-forked server: create a static/dynamic pool of child processes at server startup; each process is assigned (on demand by the controlling parent) a client request to handle Overhead in parent/child communications; synchronization (5) Pre-threading server: create a static/dynamic pool of child threads at server startup; each process is assigned (on demand) a client request to handle What if the process crashes? we lose everything (6) C select server -- i.e. uses the select() system call: listen on multiple descriptors in a single process What if the process crashes? we lose everything Daemons (or Windows) services: -- processes running 24/7 in the background -- not associated with any controlling terminal -- typically the process runs as root or superuser -- started at machine startup via /etc/rc scripts -- start a server process: forks; parent dies; child changes its cwd to / ---- signal handlers are set up (ignore signals) ---- close all file descriptors (0, 1, 2) ---- redirect to /dev/null --- log messages go to syslogd daemon General client/server design issues: -- single point(s) of failure -- bottlenecks -- server overloads -- cost $$$ -- complexity (maintenance) -- synchronization -- extensibility -- reliability -- ability to swap in different components (e.g. DBMS) -- scalability -- e.g. Google LDX #20 LOOP ... DEX BNE LOOP ; branch if x not-equal-to 0 BNE #-18 ; go back 18 bytes