Saturday, February 17, 2018

Learning Distributed System



http://the-paper-trail.org/blog/distributed-systems-theory-for-the-distributed-systems-engineer/
Distributed Systems for Fun and Profit is a short book which tries to cover some of the basic issues in distributed systems including the role of time and different strategies for replication.
Notes on distributed systems for young bloods – not theory, but a good practical counterbalance to keep the rest of your reading grounded.
A Note on Distributed Systems – a classic paper on why you can’t just pretend all remote interactions are like local objects.
The fallacies of distributed computing – 8 fallacies of distributed computing that set the stage for the kinds of things system designers forget.
* The (partial) hierarchy of failure modes: crash stop -> omission -> Byzantine. You should understand that what is possible at the top of the hierarchy must be possible at lower levels, and what is impossible at lower levels must be impossible at higher levels.
* How you decide whether an event happened before another event in the absence of any shared clock. This means Lamport clocks and their generalisation to Vector clocks, but also see the Dynamo paper.
* How big an impact the possibility of even a single failure can actually have on our ability to implement correct distributed systems (see my notes on the FLP result below).


* The quorum technique for ensuring single-copy serialisability. See Skeen’s original paper, but perhaps better is Wikipedia’s entry.
* About 2-phase-commit3-phase-commit and Paxos, and why they have different fault-tolerance properties.
* How eventual consistency, and other techniques, seek to avoid this tension at the cost of weaker guarantees about system behaviour. The Dynamo paper is a great place to start, but also Pat Helland’s classic Life Beyond Transactions is a must-read.
Basic primitives
* Leader election (e.g. the Bully algorithm)
* Consistent snapshotting (e.g. this classic paper from Chandy and Lamport)
* Consensus (see the blog posts on 2PC and Paxos above)
* Distributed state machine replication (Wikipedia is ok, Lampson’s paper is canonical but dry).

https://www.slideshare.net/HenryRobinson/pwl-nonotes

https://cloud.tencent.com/developer/article/1004409
而这些对于“服务速度”的要求,实际上包含的部分却是以下几个:高吞吐、高并发、低延迟和负载均衡。
因为除了大量用户访问可能造成请求在排队外,还有可能因为排队的长度太长,导致内存耗尽、带宽占满等空间性的问题。如果因为排队失败而采取重试的策略,则整个延迟会变的更高。所以分布式系统会采用很多请求分拣和分发的做法,尽快的让更多的服务器来出来用户的请求。但是,由于一个数量庞大的分布式系统,必然需要把用户的请求经过多次的分发,整个延迟可能会因为这些分发和转交的操作,变得更高,所以分布式系统除了分发请求外,还要尽量想办法减少分发的层次数,以便让请求能尽快的得到处理



至此,我们就会发现,一个典型的三层结构出现了:接入、逻辑、存储。然而,这种三层结果,并不就能包医百病。例如,当我们需要让用户在线互动(网游就是典型) ,那么分割在不同逻辑服务器上的在线状态数据,是无法知道对方的,这样我们就需要专门做一个类似互动服务器的专门系统,让用户登录的时候,也同时记录一份数据到它那里,表明某个用户登录在某个服务器上,而所有的互动操作,要先经过这个互动服务器,才能正确的把消息转发到目标用户的服务器上。
又例如,当我们在使用网上论坛(BBS)系统的时候,我们发的文章,不可能只写入一个数据库里,因为太多人的阅读请求会拖死这个数据库。我们常常会按论坛板块来写入不同的数据库,又或者是同时写入多个数据库。这样把文章数据分别存放到不同的服务器上,才能应对大量的操作请求。然而,用户在读取文章的时候,就需要有一个专门的程序,去查找具体文章在哪一个服务器上,这时候我们就要架设一个专门的代理层,把所有的文章请求先转交给它,由它按照我们预设的存储计划,去找对应的数据库获取数据。


根据上面的例子来看,分布式系统虽然具有三层典型的结构,但是实际上往往不止有三层,而是根据业务需求,会设计成多个层次的。为了把请求转交给正确的进程处理,我们而设计很多专门用于转发请求的进程和服务器。这些进程我们常常以Proxy或者Router来命名,一个多层结构常常会具备各种各样的Proxy进程。这些代理进程,很多时候都是通过TCP来连接前后两端。然而,TCP虽然简单,但是却会有故障后不容易恢复的问题。而且TCP的网络编程,也是有点复杂的。——所以,人们设计出更好进程间通讯机制:消息队列。

而Memcache的不具备集群功能,也是一个用户的痛点。于是很多人开始设计,如何让数据缓存分不到不同的机器上。最简单的思路是所谓读写分离,也就是缓存每次写,都写到多个缓冲进程上记录,而读则可以随机读任何一个进程。在业务数据有明显的读写不平衡差距上,效果是非常好的。
然而,并不是所有的业务都能简单的用读写分离来解决问题,比如一些在线互动的互联网业务,比如社区、游戏。这些业务的数据读写频率并没很大的差异,而且也要求很高的延迟。因此人们又再想办法,把本地内存和远端进程的内存缓存结合起来使用,让数据具备两级缓存。同时,一个数据不在同时的复制存在所有的缓存进程上,而是按一定规律分布在多个进程上。——这种分布规律使用的算法,最流行的就是所谓“一致性哈希”。这种算法的好处是,当某一个进程失效挂掉,不需要把整个集群中所有的缓存数据,都重新修改一次位置。你可以想象一下,如果我们的数据缓存分布,是用简单的以数据的ID对进程数取模,那么一旦进程数变化,每个数据存放的进程位置都可能变化,这对于服务器的故障容忍是不利的。


Orcale公司旗下有一款叫Coherence的产品,是在缓存系统上设计比较好的。这个产品是一个商业产品,支持利用本地内存缓存和远程进程缓存协作。集群进程是完全自管理的,还支持在数据缓存所在进程,进行用户定义的计算(处理器功能),这就不仅仅是缓存了,还是一个分布式的计算系统。
大家突然发现,其实很多互联网业务,其数据格式是如此的简单,很多时候根部不需要关系型数据库那种复杂的表格。对于索引的要求往往也只是根据主索引搜索。而更复杂的全文搜索,本身数据库也做不到。所以现在相当多的高并发的互联网业务,首选NoSQL来做存储设施

https://cloud.tencent.com/developer/article/1004566

Labels

Review (572) System Design (334) System Design - Review (198) Java (189) Coding (75) Interview-System Design (65) Interview (63) Book Notes (59) Coding - Review (59) to-do (45) Linux (43) Knowledge (39) Interview-Java (35) Knowledge - Review (32) Database (31) Design Patterns (31) Big Data (29) Product Architecture (28) MultiThread (27) Soft Skills (27) Concurrency (26) Cracking Code Interview (26) Miscs (25) Distributed (24) OOD Design (24) Google (23) Career (22) Interview - Review (21) Java - Code (21) Operating System (21) Interview Q&A (20) System Design - Practice (20) Tips (19) Algorithm (17) Company - Facebook (17) Security (17) How to Ace Interview (16) Brain Teaser (14) Linux - Shell (14) Redis (14) Testing (14) Tools (14) Code Quality (13) Search (13) Spark (13) Spring (13) Company - LinkedIn (12) How to (12) Interview-Database (12) Interview-Operating System (12) Solr (12) Architecture Principles (11) Resource (10) Amazon (9) Cache (9) Git (9) Interview - MultiThread (9) Scalability (9) Trouble Shooting (9) Web Dev (9) Architecture Model (8) Better Programmer (8) Cassandra (8) Company - Uber (8) Java67 (8) Math (8) OO Design principles (8) SOLID (8) Design (7) Interview Corner (7) JVM (7) Java Basics (7) Kafka (7) Mac (7) Machine Learning (7) NoSQL (7) C++ (6) Chrome (6) File System (6) Highscalability (6) How to Better (6) Network (6) Restful (6) CareerCup (5) Code Review (5) Hash (5) How to Interview (5) JDK Source Code (5) JavaScript (5) Leetcode (5) Must Known (5) Python (5)

Popular Posts