Notes: https://pdos.csail.mit.edu/6.824/notes/l-rpc.txt

Video: https://youtu.be/oZR76REwSyA

Prep:


Why Go?

  • support for threads/rpc
  • gc
  • type safe

Thread Of Execution

Threads from same address space share memory

start (green) thread with go keyword, can exit, stop, resume

Why Threads?

  • Express concurrency with threads, IO concurrency
  • Multi core parallellism

Challenges

  • Race condition
    • overcome by avoid sharing
    • use locks, race detector from Go (sharing)
  • Coordination
    • Channels or conditional variables (no sharing)
  • Deadlock

Vote

use -race arg with go run to detect race conditions

Crawler

Goals

  • IO concurrency
  • Fetch url once (no looping)
  • Exploit parallellism

RPC

Remotely calling functions(procedures)

f(x, y) function call that happens client side but function is actually implemented at some server f(x, y) {}

image 22.png

https://excalidraw.com/#json=h_2qEFT7-EAPO-r36lXyh,mOxtxUkz5S5Lft2ZvgxG-Q

stubs are automatically generated by compiler

KV Store

rpc.NewServer() to init server

  • svr.Register() with arg as obj/struct, this will expose public methods of that obj for RPC
    • public methods starts with uppercase, private’s lowercase
  • svr.ServeConn(conn)

rpc.Dial() for client init

RPC Semantics Under Failures

  • at-least once
    • duplicates can occur, exec once or more
  • at-most once
    • duplicates shouldn’t occur, exec once or don’t (the above KV server)
  • exactly once
    • very hard, exec exactly once