why use Threads
I/O Concurrency = using mutiple thread to call remote procedure, each thread will call remote i/o and wait for answer
Parallelism
Convience = do something in background or periodically
with out Threads
event driven programming = has single thread and single loop (like nodejs) , cant have parallelism , hard to write sequential programming ,
Thread chanllenges
threads share same memory = synchronous issue
Thread Coordination
channel = just sending data to other thread
sync.cond = give other thread a "kick" to perform its operation
wait group = waiting for every other thread to finish
crawler with shared memory (= fetch map structure)
done.Done() = decrement by 1 which is what "done.Add" added , we are calling this before ConcurrentMutex because it might fail during gorotuine operation
done.wait() = wait until done get to zero
u string = it uses copy of for_, u:= range urls , because outside u keeps changing and gorotuine might refer to other url which is not our intention
crawler with channel
notice worker thread(function) doesn't have any shared memory , doesn't need to worry about lock
ch is channel , worker is sending to that channel while master is receiving from that channel
'Database > Distributed Systems' 카테고리의 다른 글
Lecture 10: Cloud Replicated DB, Aurora (0) | 2022.03.06 |
---|---|
Lecture 8: Zookeeper , More Replication, CRAQ (0) | 2022.03.05 |
Lecture 6: Fault Tolerance: Raft (1) ,(2) (0) | 2022.02.26 |
Lecture 4: Primary-Backup Replication (0) | 2022.02.11 |
Lecture 3: GFS(Google File System) (0) | 2022.01.31 |