200 likes | 215 Views
CSE451 Section 6: Spring 2006. Web server & preemption. Overview. Server software architecture Preemptive scheduling. Server & client. You want to use Google search What do you do? Open your web browser Load Google web page Type query & use it Some one provides services
E N D
CSE451 Section 6:Spring 2006 Web server & preemption
Overview • Server software architecture • Preemptive scheduling
Server & client • You want to use Google search • What do you do? • Open your web browser • Load Google web page • Type query & use it • Some one provides services • You are the user of those services • Use real world terminologies to call two entities • Server & client
Basic client & server model • Real world • Client goes to the shop & order services • Exchange money & services • Virtual world • Client connect to the server & request services • Both client and server are programs • What do they exchange? • How about salesman? • So does virtual world? Why or why not?
Exchanging data • Simply it is another kind of program • Can a client use all kinds of services? • Can a server serves all kinds of services? • Why or why not? • Every program has different input & output format • We use a protocol between client and server request Client Server response
Protocol • Specification of input & output • Data representation • Input & output & error • Meaning(semantic) • Functionalities • Set of clients/servers understand protocol ‘Z’ • Z client, Z server • Z agent, sometimes… • Protocol categorized by data representation • Binary – SNMP, X.500, DCE RPC, SSL, Kerberos, IIOP… • Text – SMTP, FTP, HTTP, … • XML – SOAP, XML-RPC, …
Issues implementing protocol • Data representation • Integer – byte order problem • Floating point – representation problem • String – character set problem • Structured data – structural representation • Behavior • Implementers interpret the standards in different ways • Client does not behave as server expects • Server does not behave as client expects • Just like man & woman…
Writing server program • Choose core service model • Fork per connection • Process pool • Thread per connection • Thread pool • Thread per request • … • Encoding/decoding messages • Design a state machine of one connection • Implement the behaviors
Web server • Is it a precise term? • Is there a protocol named ‘Web’? • Then what is the protocol? • Hyper Text Transfer Protocol • HTTP server • A program understands requests conforming HTTP and is able to process it and generate results conforming HTTP • Apache, IIS, Jigsaw, TUX, Zeus, …
HTTP Overview • Request • METHOD<SP>REQUEST-URI<SP>HTTP-Version<CRLF>(HEADERS)<CRLF> • Example: GET /index.html HTTP/1.1 • Currently, 8 basic methods are defined • Response • HTTP-Version<SP>Status-Code<SP>Reason-Phrase<CRLF>(HEADERS)<CRLF> • Example: HTTP/1.1 200 OK<CRLF>contents….. • HTTP 1.1 standard • http://www.w3.org/Protocols/rfc2616/rfc2616.html
One client, one request at a time initialization while ( !terminate ) { wait connection read request from network decode request process request encode response write response to network } finalization
One client, multiple requests at a time initialization while ( !terminate ) { wait connection while ( !noRequest ) { read request from network decode request process request encode response write response to network } } finalization
Multiple client, multiple requests at a time – traditional process based server initialization while ( !terminate ) { wait connection fork if ( isChild ) { while ( !noRequest ) { read request from network decode request process request encode response write response to network } exit } } Finalization
Multiple client, multiple requests at a time – traditional thread based server initialization while ( !terminate ) { wait connection thread_create( while ( !noRequest ) { read request from network decode request process request encode response write response to network } ) } finalization
Multiple client, multiple requests at a time – process pool Initialization Pool := fork N processes while ( !terminate ) { lock accepting socket wait connection unlock accepting socket serve client } finalization
Multiple client, multiple requests at a time – thread pool – per connection Initialization Pool := spawn N threads while ( !terminate ) { wait connection assign worker thread to connection } finalization
Multiple client, multiple requests at a time – thread pool – per request thread_create( while ( !notDead ) { read request from network decode request process request encode response write response to network sleep } ) Working context is assigned by the dispatch thread The dispatch thread also wakes up the worker thread
Preemption • Sick of calling yield? • Let the timer do this • Related sources • sthread_preempt.[ch] • Useful functions • sthread_preemption_init • splx • atomic_test_and_set • atomic_clear
How it works? • Interrupt here is actually called signal • Asynchronous integer message • Message value = the type of event • Whenever we get a signal • Push the PC • Jump to the signal handler • Execute signal hander • Return • Continue from where signal caught
Think about… • What should the interrupt handler (signal handler) do? • Program including your thread package can be interrupted any time, any where • Until you disable the interrupt • We provide interrupt en/disable function • Which part of your thread package must be protected? • We provide atomic test & set • Maybe useful to protect your synchronization primitives