29
Remote Procedure Call Arvind Krishnamurthy

Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

RemoteProcedureCall

ArvindKrishnamurthy

Page 2: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

CourseLogistics

• Everyoneshouldhaveagitlabaccount

• Letusknowifyoudon’thaveone

• MakesureyouhavesignedupforPiazza

• Lab1duenextThursday

• SubmissionthroughCanvas

• BlogpostforFriday’sreading

• SubmissionthroughCanvas

Page 3: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

MuddyForeheads

• 𝑛children,𝑘getmudontheirforeheads

• Childrensitincircle.

• Teacherannounces,"Someonehasmudontheirforehead."

• Someone==1ormore

• Nooncanseetheirownforehead

• 𝑘isnot“commonknowledge”

Page 4: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

MuddyForeheads

• 𝑛children,𝑘getmudontheirforeheads

• Childrensitincircle.

• Teacherannounces,"Someonehasmudontheirforehead."

• Teacherrepeatedlyasks,"Raiseyourhandifyouknowyouhavemudonyourforehead."

• Whathappens?

Page 5: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

MuddyForeheads

• 𝑛children,𝑘getmudontheirforeheads

• Childrensitincircle.

• Teacherannounces,"Someonehasmudontheirforehead."

• Teacherrepeatedlyasks,"Raiseyourhandifyouknowyouhavemudonyourforehead."

• Whathappens?

Page 6: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

MuddyForeheads

• 𝑛children,𝑘getmudontheirforeheads

• Childrensitincircle.

• Teacherannounces,"Someonehasmudontheirforehead."

• Teacherrepeatedlyasks,"Raiseyourhandifyouknowyouhavemudonyourforehead."

• Whathappens?

X

Y

Page 7: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

MuddyForeheads

• 𝑛children,𝑘getmudontheirforeheads

• Childrensitincircle.

• Teacherannounces,"Someonehasmudontheirforehead."

• Teacherrepeatedlyasks,"Raiseyourhandifyouknowyouhavemudonyourforehead."

• Whathappens?

X

Y

Z

Page 8: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

MuddyForeheads(contd.)

• Claim:

– Thefirstk-1timestheteacherasks,allchildrenwillreply“No”

– Thek-thtimealldirtychildrenwillreply“Yes”

• Reasoningbyconsideringcasesandusinginduction:

– k=1:thechildwithamuddyforeheadwillsayyes– k=2:letXandYhavemuddyforeheads

• Eachseesexactlyoneotherpersonwithmuddyforehead

• Inround1,XnoticedYdidn’tsay“Yes”

–PossibleonlybecauseYmusthaveseenachildwithamuddyforehead==>Xmusthavemud

Page 9: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

TheMuddyForehead"Paradox"

If 𝑘>1, the teacher didn't say anything anyone didn't already know!

Page 10: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

WhyAreDistributedSystemsHard?

• Asynchrony– Differentnodesrunatdifferentspeeds

– Messagescanbeunpredictably,arbitrarilydelayed

• Failures(partialandambiguous)– Partsofthesystemcancrash

– Can’ttellcrashfromslowness

• Concurrencyandconsistency– Replicatedstate,cachedonmultiplenodes

– Howtokeepmanycopiesofdataconsistent?

Page 11: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

WhyAreDistributedSystemsHard?

• Performance– Havetoefficientlycoordinatemanymachines– Performanceisvariableandunpredictable– Taillatency:onlyasfastasslowestmachine

• Testingandverification– Almostimpossibletotestallfailurecases– Proofs(emergingfield)arereallyhard

• Security– Needtoassumeadversarialnodes

Page 12: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

MapReduceComputationalModel

Foreachkeykwithvaluev,computeanewsetofkey-valuepairs: map(k,v)→list(k’,v’)Foreachkeyk’andlistofvaluesv’,computeanew(hopefullysmaller)listofvalues: reduce(k’,list(v’))→list(v’’)

Userwritesmapandreducefunctions.Frameworktakescareofparallelism,distribution,andfaulttolerance.

Page 13: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

MapReduce(orMLor…)Architecture

• ScheduleracceptsMapReducejobs– findsaMapReducemasterandsetofavailworkers

• Foreachjob,MapReducemaster<array>– farmstaskstoworkers;restartsfailedjobs;syncstaskcompletion

• Worker<array>– executesMapandReducetasks

• Storage<array>– storesinitialdataset,intermediatefiles,endresults

Page 14: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

RemoteProcedureCall(RPC)

Arequestfromtheclienttoexecuteafunctionontheserver.– Totheclient,lookslikeaprocedurecall

– Totheserver,lookslikeanimplementationofaprocedurecall

Page 15: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

RemoteProcedureCall(RPC)

Arequestfromtheclienttoexecuteafunctionontheserver.• Onclient– Ex:result=DoMap(worker,i)– Parametersmarshalledintoamessage(canbearbitrarytypes)– Messagesenttoserver(canbemultiplepkts)– Waitforreply

• Onserver– messageisparsed– operationDoMap(i)invoked– Resultmarshalledintoamessage(canbemultiplepkts)– Messagesenttoclient

Page 16: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

RPClibrary

ReaddataDeserializeargs

Transport

CSE461

RPCimplementation

DoMap(worker, i) Map(worker, i)

RPClibrary

SerializeargsOpenconnectionWritedata

ReaddataDeserializereply

SerializereplyWritedata

Transport

OS

TCP/IPwrite

OS

TCP/IPreadTCP/IPwriteTCP/IPread

x xx

Page 17: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

RPCvs.ProcedureCall

• Whatisequivalentof:– Thenameoftheprocedure?

– Thecallingconvention?– Thereturnvalue?– Thereturnaddress?

Page 18: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

RPCvs.ProcedureCall

Binding– Clientneedsaconnectiontoserver– Servermustimplementtherequiredfunction– Whatiftheserverisrunningadifferentversionof

thecode?

Performance– procedurecall:maybe10cycles=~3ns– RPCindatacenter:10microseconds=>~1Kslower

– RPCinthewidearea:millionsoftimesslower

Page 19: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

RPCvs.ProcedureCall

Failures–Whathappensifmessagesgetdropped?

–Whatifclientcrashes?

–Whatifservercrashes?

–Whatifservercrashesafterperformingopbutbeforereplying?

–Whatifserverappearstocrashbutisslow?

–Whatifnetworkpartitions?

Page 20: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

Semantics

• Semantics=meaning

• reply==ok=>???

• reply!=ok=>???

Page 21: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

Semantics

• Atleastonce(NFS,DNS)– true:executedatleastonce– false:maybeexecuted,maybemultipletimes

• Atmostonce– true:executedonce– false:maybeexecuted,butnevermorethanonce

• Exactlyonce– true:executedonce– false:neverreturnsfalse

Page 22: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

AtLeastOnce

RPClibrarywaitsforresponseforawhile

Ifnonearrives,re-sendtherequest

Dothisafewtimes

Stillnoresponse--returnanerrortotheapplication

Page 23: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

Non-replicatedkey/valueserver

ClientsendsPutkv

Servergetsrequest,butnetworkdropsreply

ClientsendsPutkvagain– shouldserverrespond"yes"?– or"no"?

Whatifopis“append”?

Page 24: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

DoesTCPFixThis?

• TCP:reliablebi-directionalbytestreambetweentwoendpoints– Retransmissionoflostpackets

– Duplicatedetection

• ButwhatifTCPtimesoutandclientreconnects?– BrowserconnectstoAmazon

– RPCtopurchasebook

– WifitimesoutduringRPC

– Browserreconnects

Page 25: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

Whendoesat-least-oncework?

• Ifnosideeffects– read-onlyoperations(oridempotentops)

• Example:MapReduce

• Example:NFS– readFileBlock– writeFileBlock

Page 26: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

AtMostOnce

ClientincludesuniqueID(UID)witheachrequest– usesameUIDforre-send

ServerRPCcodedetectsduplicaterequests– returnpreviousreplyinsteadofre-runninghandlerifseen[uid]{r=old[uid]}else{r=handler()old[uid]=rseen[uid]=true}

Page 27: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

SomeAt-Most-OnceIssues

HowdoweensureUIDisunique?– Bigrandomnumber?

– CombineuniqueclientID(IPaddress?)withseq#?

– Whatifclientcrashesandrestarts?CanitreusethesameUID?

– Inlabs,nodesneverrestart

– Equivalentto:everynodegetsnewIDonstart

Page 28: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

WhenCanServerDiscardOldRPCs?

Option1: Never?Option2:uniqueclientIDsper-clientRPCsequencenumbersclientincludes"seenallreplies<=X"witheveryRPCOption3:onlyallowclientoneoutstandingRPCatatimearrivalofseq+1allowsservertodiscardall<=seqLabsuseOption3

Page 29: Remote Procedure Call - courses.cs.washington.edu · Remote Procedure Call (RPC) A request from the client to execute a function on the server. • On client – Ex: result = DoMap(worker,

WhatifServerCrashes?

Ifat-most-oncelistofrecentRPCresultsisstoredinmemory,serverwillforgetandacceptduplicaterequestswhenitreboots– DoesserverneedtowritetherecentRPCresultsto

disk?– Ifreplicated,doesreplicaalsoneedtostorerecent

RPCresults?

InLabs,servergetsnewaddressonrestart– Clientmessagesaren’tdeliveredtorestartedserver