Open jasperzhong opened 3 years ago
讲义写得很好了...我就写点体会吧.
分布式系统三大基础设施: 分布式存储,分布式通信,分布式计算.
几个主题:
MapReduce是一个非常好的例子. 看得比较多了,不多说了.
虽然这节比较简单,看了一遍视频还是觉得很有收获.
一开始讲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试了下.
这个loop太典了!
https://pdos.csail.mit.edu/6.824/schedule.html
https://github.com/vycezhong/MIT6.824
https://www.youtube.com/channel/UC_7WrbZTCODu1o_kfUMq88g/videos
鸽两年了