Scribe notes for lecture on 12/1/05

Authors: Yi Hu, Brian Keh, Michael Cheung

Asynchronous RPC (Remote Procedure Call)

Suppose the following scenario.

There is a thin client consisting of a screen, a keyboard, and a mouse. Let’s denote the thin client as computer A.

There is another computer, called computer B which application runs on computer (B). But the result displays on computer A.

Suppose we want to get the position of the mouse from computer A, and send the draw requests from computer B

The following codes are all implemented on computer B.

STUB on computer B get_mouse_pos (){

Char message[];
Messageß GETMOUSEPOS;
SEND;
Wait reply;
Unmarshall position;
Return position;
}

Point mouse pos;

While (1){

Point p = get_mouse_pos(); ß------
For (all points q between p and mouse_pos)
Draw_circle(q, &draw_circle_error); //ASYNC RPC doesn’t not //wait for response after sending draw_crical to computer A
Mouse_pos = p ;

}

draw_circle (point, error_callback){

sent message with id N;
stores a record N, error_callback

}

Draw_cirle_error(){

Printf(“Error”);

}

The following figure compares Synchronous RPC with Asynchronous RPC

The following figure is an illustration of an asynchronous RPC with call back list error handling.

There are other ways of Error handling w/asynchronous RPC;

Function supplied by RPC’s caller to handle errors

Asynchronous RPC Benefits

Reduce interactive latency by sending overlapped message

Another example of asynchronous RPC

Web application : Gmail

Writing a Server

How does networking fit together with applications?

File descriptor

open (“/net/18.26.4.3/tcp/80”)

Plan 9(Unix successor)

THIS IS NOT PRACTICAL TODAY

Actual way unix open connections is to use socket abstraction

Int fd = socket()

Sockets have the following functionality

listen() ->socket into listening mode ( web server)
accept() -> returns new socket for incoming connection
connect()-> socket actively connects

Connection state on servers

A client, by opening a connection, reserves state on the server possible including

Servers are opened to denial-of-service attack!

Server Architectures (Lab 4)

The following are different ways of implementing a server.

I. Single Process Server

(“+” means advantage, “-” means disadvantage)

Pseudo-code for Single Process Server

While(1){

(block) fd = accept (new connection);
(block)Read request from fd;
(block)Write response to fd;
Close (f);

}

II. Multi – Process Server

(“+” means advantage, “-” means disadvantage)

Pseudo code for a multi-process server

(block)fd = accept();

if(fork() == 0)

{
(block)read request;
(block)write response;
exit(0);

}

close(fd);

III. Multi – Threaded server

Uses Pthread_create and Pthread_exit

(“+” means advantage, “-” means disadvantage)

(state & resource usage)

Hybrid Apache model

Goal of lab4

Single process Event-Driven server

Question: How can we have multiple connections from single process?
Answer: Never block on any connection when other connections exist
Solution: Turn on non blocking I/O
How: fcntl (fd, F_SETFL, O_NONBLOCK);

For(every fd)
If( fd in read state)
{
Read request (fd);
Into buffer;
Check request complete
If (request complete)
Fd -> write state
Returns all data requested
  • Less data
  • EOF
  • -1 EAGAIN
  • }

    if (fd in write state){

    Write response (fd);
    If (response complete)
    Close fd
    }
    Close (fd):
    Fd = accept()
    If( fork () == 0){
    Read request
    Write response
    Exit(0);
    }
    close fd(in parent)

    To avoid busy waiting

    Block on a set of connections
    Kernel returns when any of the file descriptors is ready
    Select()

    Advantage/Disadvantages of a Single Process Event Driven Server

    Networked file system

    The goal of a networked file system is to make a remote computer’s disk looks like part of the local file system. When a local computer requests a file located on a remote computer to be read, the local computer’s virtual file system sends the request to the network file system. The network file system then takes the read request message and sends it to the remote computer through the network. Upon receiving the request message, the remote computer’s network file system sends that message to its own virtual file system which reads the file, and sends the contents back along the same path until it is received by the local computer.