MapReduce
Unix哲学
自动化:优先使用工具减轻编码任务
快速原型设计:程序单一职责
增量式迭代:新工作对应新程序,而非旧程序新特征
测试友好与模块化:轻松观察程序进展(如
less结束流水线)统一接口:期待一个程序的输出成为另一个程序的输入
MapReduce与分布式文件系统
What is MapReduce?

MapReduce的并行化
分布式Unix工具。
数据流基于分区实现
RPC
Go語言的一大优势在于协程支持:比如可以在后台启动一个goroutine定时执行某件事、周期性的检测什么东西(比如心跳)。由此也衍生出了一些设计风格:https://go.dev/talks/2012/concurrency.slide
“并发”指的是程序的结构,“并行”指的是程序运行时的状态(Different concurrent designs enable different ways to parallelize.)
并行:就是多个工作单位同时执行的意思
并发:程序为多个操作在重叠的时间段内进行提供可能性支持
GFS
Guarantees
consistent: all clients will always see the same data, regardless of which replicas they read from.
defined: consistent and clients will see what the mutation writes in its entirety.

Record Append: offset by GFS's choosing
--> Specific:
appending rather than overwriting. (Record Append)
Single Master with snapshot WAL, copy-on-write, checkpoints...
meta model (Swap in heartbeat)
Big Storage
trade-off
performance -> sharding
faults -> tolerance -> replication(REPL) -> in consistency -> low performance
Go
同步原语
闭包:捕获了外部变量的方法体。如:Go中匿名函数。 经常使用WaitGroup在父 goroutine 中阻塞地等待一组子 goroutine 的完结。
线程间同步:一个 goroutine
mu.Unlock会唤醒另外的 goroutine 正在阻塞mu.Lock,保证主线程对done的修改一定能够被子线程看到。回忆下Java的Happen-before
锁
对于数据竞争,加锁来保护所有对共享变量的访问。
保护不变量
出借和借钱应该是一个原子性操作,因此需要使用锁整个包裹起来。当获取锁进入临界区后,可能会破坏不变性,但是只需要在释放锁前恢复即可。
条件变量
上面的代码中,对于count的判断,占用了100%的CPU。对于需要一定条件的并发设计,可以使用条件变量。这个方式类似于【信号】,即锁和条件关联了起来。
管道
管道不是队列,会阻塞,也是同步原语。
带缓冲的 channel 类似一个同步队列,建议在实验中通过共享变量 + 锁来进行多线程间消息的同步和互斥。
参考: https://laike9m.com/blog/huan-zai-yi-huo-bing-fa-he-bing-xing,61/
最后更新于
这有帮助吗?