RPC Semantics Doug Woos Logistics notes Toms OH canceled this week - - PowerPoint PPT Presentation

rpc semantics
SMART_READER_LITE
LIVE PREVIEW

RPC Semantics Doug Woos Logistics notes Toms OH canceled this week - - PowerPoint PPT Presentation

RPC Semantics Doug Woos Logistics notes Toms OH canceled this week Last time - Go tips and tricks - RPC intro, using RPCs in Go - MapReduce discussion Outline RPC semantics in detail Gos RPC semantics RPC Warmup Whats the


slide-1
SLIDE 1

RPC Semantics

Doug Woos

slide-2
SLIDE 2

Logistics notes

Tom’s OH canceled this week

slide-3
SLIDE 3

Last time

  • Go tips and tricks
  • RPC intro, using RPCs in Go
  • MapReduce discussion
slide-4
SLIDE 4

Outline

RPC semantics in detail Go’s RPC semantics

slide-5
SLIDE 5

RPC Warmup

What’s the equivalent of:

  • Procedure name?
  • Calling convention?
  • Return value?
  • Return address?
slide-6
SLIDE 6

Semantics

semantics: meaning

slide-7
SLIDE 7

RPC library

Read data Deserialize args

Transport CSE 461

RPC implementation

  • k := call(address, "Worker.DoJob",

args, &reply) func (wk *Worker) DoJob(args *DJArgs, reply *DJReply)

RPC library

Serialize args Open connection Write data Read data Deserialize reply Serialize reply Write data

Transport OS

TCP/IP write

OS

TCP/IP read TCP/IP write TCP/IP read

x xx

slide-8
SLIDE 8

Semantics

semantics: meaning

  • ok == true: ???
  • ok == false: ???
  • Possibilities?
slide-9
SLIDE 9

Semantics

At least once (NFS, DNS, …):

  • true = executed at least once
  • false = maybe executed, multiple times

At most once (Go, …):

  • true = executed exactly once
  • false = maybe executed once
  • Exactly once (Lab 2 writes)
  • true = executed exactly once
  • never returns false
slide-10
SLIDE 10

At least once

RPC library sends, waits for response If none arrives, re-send request After a few retries, give up and return an error How should applications deal with this?

slide-11
SLIDE 11

Example: one-node KV store (Redis)

Client sends PUT k v Server gets request, reply dropped Client sends PUT k v again

  • What should the server do?

What if instead, op is “deduct $10 from bank acct”

slide-12
SLIDE 12

What about TCP?

“Just use TCP” TCP: reliable byte stream between two endpoints

  • Retransmission of dropped packets
  • Duplicate detection & removal

What if TCP times out and reconnects?

  • User browses to Amazon
  • RPC to purchase book
  • Wifi spotty during RPC
  • Browser reconnects
slide-13
SLIDE 13

When does at-least-once work?

No side effects (e.g. MapReduce jobs)

  • read-only, idempotent

NFS: readFileBlock, writeFileBlock Application-level duplicate detection

slide-14
SLIDE 14

At most once

Client includes unique id (UID) with each request

  • same UID on re-send

RPC lib on server detects duplicates

if seen[uid] {
 return old[uid]
 } else {
 r = Handler()


  • ld[uid] = r


seen[uid] = true
 return r
 }

slide-15
SLIDE 15

Some at-most-once issues

How to ensure unique UID?

  • large random numbers
  • combine UID (e.g. MAC address) w/ sequence #

Can clients use same UID if they crash? Get UID from server?

slide-16
SLIDE 16

When can server discard old?

Option 1

  • Never!

Option 2

  • Unique client IDs
  • per-client sequence number
  • client includes “discard <= i” w/ all RPCs

Option 3

  • only allow one outstanding RPC per client
  • When seq+1 arrives, discard <= seq

Option 4

  • Client gives up after n minutes
  • Server discards after n minutes
slide-17
SLIDE 17

Handling server crashes

Server will lose old on crash

  • Does it need to be persisted?
  • Does it need to be replicated?
slide-18
SLIDE 18

Handling server crashes

Server will lose old on crash

  • Does it need to be persisted?
  • Does it need to be replicated?

Needs to have same persistence/replication as data

slide-19
SLIDE 19

Go RPC revisited

What are the semantics?

slide-20
SLIDE 20

Go RPC revisited

At most once Rely on TCP retry

  • Open connection
  • Write data
  • TCP may retransmit

Return error if no reply after timeout

slide-21
SLIDE 21

Go’s at-most once is not enough

Imagine side-effectful MapReduce Master sends RPC to worker, gets a timeout What does application do?

  • Attempt to figure out if work was done
  • Implement better at-most-once
  • Lab 2!
slide-22
SLIDE 22

Exactly once

Keep retrying forever Need to survive client and server crashes

  • Client must store pending RPCs on disk
  • Server must store completed RPCs on disk
slide-23
SLIDE 23

Takeaways

Failure makes RPCs complicated Think carefully about semantics Mechanisms in app vs. RPC vs. transport