{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture22 - C LIENT-S ERVER PARADIGM M AP R EDUCE G EORGE...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
C LIENT -S ERVER P ARADIGM , M AP R EDUCE 22 G EORGE W ANG [email protected] Department of Electrical Engineering and Computer Sciences University of California, Berkeley July 29, 2010 1 Threads, Callbacks (define (im-server-start) ;;;Start the server. ; ;Set! server-socket variable ;Set thunk for handling handshake with new client ; (format logging "~%Server starting...~%") (set! server-socket (make-server-socket)) (format #t "Server IP address: ~A, server port: ~A~%" (get-ip-address-as-string) (socket-port-number server-socket)) ( when-socket-ready server-socket (lambda () (begin (format logging "New client connecting.~%") (handshake (socket-dup server-socket))))) (format logging "(im-server-start) done.~%~%") ’okay) 2 The 3-Way Handshake (define (handshake sock) ;;;Handle the three-way handshake with a client. ; ;Handshaking should go as follows: 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
;client->server: ; request from CLIENT to server with request "hello" and data nil ;server->client: ; request from server to CLIENT with request "welcome" and data nil ;client->server: ; request from CLIENT to server with request "thanks" and data nil ; ;;Accept the socket connection (socket-accept-connection sock) (format logging "Connection accepted for ~A...~%" sock) (let * ((port-from-client (socket-input sock)) (port-to-client (socket-output sock)) (req (get-request port-from-client))) (if (not req) (socket-shutdown sock #f) (begin (format logging "Request received: ~S~%" req) ;; Check message is " hello ". (cond ((not (equal? ’hello (request-action req))) (format #t "Bad request from client: ~S" req) (socket-shutdown sock #f)) ((member (request-src req) (get-clients-list)) ;; name already exists, send "sorry" to client (format logging "Sending ’sorry’ to client~%") (send-request (make-request ’server (request-src req) ’sorry nil) port-to-client) (format #t "Name ~A already exists." (request-src req)) (socket-shutdown sock #f)) (else ;;Send " welcome " message back. (format logging "Sending welcome message.~%") (if (not (send-request (make-request ’server (request-src req) ’welcome nil) port-to-client)) (socket-shutdown sock #f) (begin ;; Check response is " thanks " (set! req (get-request port-from-client)) (if (not req) (socket-shutdown sock #f) (begin 2
Background image of page 2
(format logging "Response received: ~S~%" req) (if (not (equal? ’thanks (request-action req))) (begin (format #t "Bad response from client: ~S" req) (socket-shutdown sock #f)) (begin ;; Finally, we can register the client (format logging "~A has logged on.~%" (request-src req)) (register-client (request-src req) sock) (format logging "Finished handshake~%") )) ) ))))) ))) ’okay) 3 MapReduce Here’s the diagram of mapreduce again: ACCUMULATE MAP kv kv kv kv kv kv key REDUCE key REDUCE REDUCE key key key key (mapreduce f1 f2 base dataname) f1 f2 () MAP MAP MAP MAP SORT value value value value value value result result result f1 f2 (accumulate f2 base (map f1 data)) The seemingly unpoetic names f1 and f2 serve to remind you of two things: f1 (the mapper) is used before f2 (the reducer), and f1 takes one argument while f2 takes two arguments (just like the functions used with ordinary map and accumulate respectively).
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}