jasperzhong / cs-notes

CS认知体系
6 stars 0 forks source link

MIT 6.824 #24

Open jasperzhong opened 3 years ago

jasperzhong commented 3 years ago

https://pdos.csail.mit.edu/6.824/schedule.html

https://github.com/vycezhong/MIT6.824

https://www.youtube.com/channel/UC_7WrbZTCODu1o_kfUMq88g/videos

鸽两年了

jasperzhong commented 3 years ago

Lec 1

讲义写得很好了...我就写点体会吧.

分布式系统三大基础设施: 分布式存储,分布式通信,分布式计算.

几个主题:

  1. Implementation: RPC (分布式系统中非常重要的一个piece), threads, concurrency control
  2. Performance: 目标是scalable throughput
  3. Fault Tolerance: 希望提供: Availability (总有一个在线) 或者 Recoverability (故障后能恢复). Big idea是replication.
  4. Consistency: 为了保证强一致性,需要非常多的通信. 和performance是trade-off.

MapReduce是一个非常好的例子. 看得比较多了,不多说了.

虽然这节比较简单,看了一遍视频还是觉得很有收获.

jasperzhong commented 3 years ago

Lec 2

一开始讲threads. 有自己PC, registers, stack, 和同一进程中其他threads共享内存. shared data有race condition, 需要mutual exclusion. threads还需要coordination,需要condition variable. 这些OS都学过,但看视频还是听得津津有味儿...

举了一个crawler.go的例子. 最后讲的channel的写法我非常appreciate. 这个code写得非常好.

func worker(url string, ch chan []string, fetcher Fetcher) {
    urls, err := fetcher.Fetch(url)
    if err != nil {
        ch <- []string{}
    } else {
        ch <- urls
    }
}

func master(ch chan []string, fetcher Fetcher) {
    n := 1
    fetched := make(map[string]bool)
    for urls := range ch {
        for _, u := range urls {
            if fetched[u] == false {
                fetched[u] = true
                n += 1
                go worker(u, ch, fetcher)
            }
        }
        n -= 1
        if n == 0 {
            break
        }
    }
}

func ConcurrentChannel(url string, fetcher Fetcher) {
    ch := make(chan []string)
    go func() {
        ch <- []string{url}
    }()
    master(ch, fetcher)
}

RPC部分课上似乎没讲. 讲义里提到: RPC is a key piece of distributed system machinery. 隐藏了网络协议细节.

RPC message diagram:
  Client             Server
    request--->
       <---response

Software structure
  client app        handler fns
   stub fns         dispatcher
   RPC lib           RPC lib
     net  ------------ net

直接看kv.go那个例子.

Go的RPC的semantics是"at-most-once".

把kv.go部署在了vps试了下. image image

jasperzhong commented 3 years ago

Lec 3

这个loop太典了! image