00:01
各位同学大家好,这节课开始呢,我们就正式进入阿帕奇fair这门技术的学习。首先我们来看第一章高性能架构模式。我们先来了解一下高性能架构模式产生的背景。那在互联网项目当中呢,大家都知道,一般情况下除了需要实现业务本身的功能之外,海量的用户访问以及海量的数据存储呢,实际上都是我们互联网项目当中的一个最突出的特点。那海量的用户访问它体现在什么地方呢?比如说我们在做商城项目的时候,都会考虑到一个比较大的用户访问量,例如双11呀,618呀,都会有非常多的这样的一个并发用户来同时访问我们的系统,进行下单呀,支付呀啊等等这样的一个操作,所以这个呢就叫海量的用户访问,那么除了海量用户之外呢,很多项目的数据规模也非常大,比如还是前面我们提到的这个商城系统,像里面的商品数据,用户数据,订单数据,那这些数据呢,都是非常有规模的啊,那么我们的比如说淘宝网上或者是京东上,或者是现在比较常买东西的地方哈,我们现在经常就会看那个抖音直播,然后在抖音上买东西,那那里面的商家还有商品,还有用户,还有订单,他其实都是非常大规模的,而且。
01:33
跟每一天也都在不断的增长,如果是商家的话,就有商家表,如果是商品的话呢,就有商品表,用户有用户表,订单有订单表,那这些数据呢,也是都存储在我们的数据库当中,这些数据库表数据量非常大的情况下呢,那么很多互联网公司呢,实际上他们都是有明确的规定的,那么如果你是作为一个架构师的话,单表记录如果超过1000万条,其实呢,你就应该警觉起来了。
02:03
比如说阿里巴巴在它的这个开发规范当中呢,它就规定单表呢,如果超过500万条记录,或者是呢,单表的容量啊,超过2GB的话,那就建议你呢进行分库分表了,也就是我们一会儿将要讲到的数据分片架构啊,这是阿里巴巴的一个开发规范,当然很多的互联网公司呢,也都有一个类似的规范。如果我们不这么做的话呢,那就会影响我们数据的访问速度,拖垮呢系统的性能啊,所以怎么办呢。实际上就是这一章大家已经看到的,我们将会有读写分离架构,将会有数据分片架构,所以高性能数据集群的第一种方式就是读写分离,第二种方式就是数据分片。接下来呢,我们分别来介绍一下读写分离以及数据分片。我们先来看读写分离架构,那么读写分离的基本原理呢,实际上就是将数据库的读操作和写操作分别分散到不同的节点上,下面这个呢,就是一个读写分离的架构图,这里面其实一共画了四台服务器,上面这台呢是业务服务器,如果我们的应用程序是用Java写的,这个其实就是Java的业务服务器了,那实际上呢,你也可以使用业务服务器的集群,在这门课程当中呢,我们就不去展开讲解上面的业务服务器的集群了,比如说我们可以用spring boot spring cloud这样的一些解决方案,那我们的课程当中呢,主要是针对下的数据库集群来讲解哈,所以接下来呢,我们来详细的讲解一下下面的数据库集群。
03:45
那么在这个数据库集群当中呢,一共有三台服务器啊,这三台服务器呢,其中有一台是主机。有两台呢是从机,那么主机呢,它主要负责我们事务性的增删改操作,从机呢,它是只负责读操作的,那所以说呢,我们主机其实呢啊,它主要处理的呢,就是一些写操作,那从基呢,它主要处理的呢,就是查询操作了。
04:20
因此呢,写操作会被路由到主机。然后呢,从机从主机呢,复制数据,复制完数据之后,接下来读操作呢,就会被路由到从机。啊,是这样的一个架构模式,为什么要这样设计呢?其实原因呢也显而易见,我们都知道在买SQL数据库当中,默认情况下数据更新它是有行锁的,因此呢,在独立的数据库中专门执行查询操作呢,其实是能够有效的避免由数据更新而导致的行锁,这样的话,整个系统的查询性能就会得到极大的改善,那这张图呢,是易主。
05:01
多重的这样的一个配置方案,因为有多台从机,因此呢可以将查询请求均匀的分散到多个数据库的副本当中,这样的话呢,也能够进一步的提升系统的处理能力。当然了,其实我们也可以有多主多层的方式,那这样的话,任何一台数据库宕机,包括主机如果宕机,甚至是磁盘物理损坏的情况下,也不会影响我们系统的正常运行。好,这是我们所说的读写分离的一个架构模式,那下面这张图展示的就是根据业务的需要,我们将用户表的写操作和读操作路由到不同数据库的一个具体的解决方案。那么大家看这里面呢,是一台数据库服务器,那么这台数据库服务器当中呢,它有一张表,这一张表呢,就是tu user表,用户表,那正常情况下,如果我们不去做读写分离这样的一个架构的话,我们会发现更新用户和查询用户都会呢被发送到这一台服务器上,当然了,你也可以有啊insert插入啊,也可以有delete删除啊,我们管这个insert呀,Delete呀,还有更新用户呀,我们都叫写操作,那所有的写操作和读操作呢,都会发送到这一台服务器上,那如果我们使用了读写分离架构的话呢,你会发现这面呢,我们就有了一台主机。有了一台从。
06:30
机,也就是主机的副本,那么只有更新操作啊,在我们这个例子当中会被发送给主机,那么查询操作呢,就会被发送给服务器的副本,也就是从记当中,好,这就是我们所说的读写分离架构的一个具体的落地实现的一个方案了。
我来说两句