Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE451 Section 6: Spring 2006 Web server & preemption.

Similar presentations


Presentation on theme: "CSE451 Section 6: Spring 2006 Web server & preemption."— Presentation transcript:

1 CSE451 Section 6: Spring 2006 Web server & preemption

2 Overview  Server software architecture  Preemptive scheduling

3 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

4 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?

5 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 Client Server request response

6 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, …

7 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…

8 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

9 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, …

10 HTTP Overview  Request METHOD REQUEST-URI HTTP- Version (HEADERS) Example: GET /index.html HTTP/1.1 Currently, 8 basic methods are defined  Response HTTP-Version Status-Code Reason- Phrase (HEADERS) Example: HTTP/1.1 200 OK contents…..  HTTP 1.1 standard http://www.w3.org/Protocols/rfc2616/rfc2616.html

11 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

12 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

13 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

14 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

15 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

16 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

17 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

18 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

19 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

20 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


Download ppt "CSE451 Section 6: Spring 2006 Web server & preemption."

Similar presentations


Ads by Google