西维蜀黍

【Linux】命令 - lsof

lsof命令是什么

lsof lists on its standard output file information about files opened by processes

被打开的文件可以是

  • regular file
  • directory
  • 网络文件系统的文件
  • 字符设备文件
  • (函数)共享库
  • 管道,命名管道
  • 符号链接
  • a stream or a network file (Internet socket, NFS file or UNIX domain socket.
  ...


【Distributed System】云计算(Cloud Computing)

云计算(Cloud Computing)

我们对于云计算的概念,维基百科有以下定义:Cloud computing is a new form of Internet-based computing that provides shared computer processing resources and data to computers and other devices on demand.

云计算就是一种按照需求通过Internet获取计算资源的形态。这些计算资源被包装成为服务,提供给用户。而提供这些服务的主体,我们称之为云服务供应商(Cloud Service Provider)。

按照NIST (National Institute of Standards and Technology,美国国家标准和技术研究院)的定义,云服务最主要的有三类:IaaS、PaaS、SaaS。

  ...


【Data Structure】树 - 平衡二叉查找树(Balanced Binary Search Tree) - 有了二叉查找树、AVL 树为啥还需要红黑树?

二叉查找树的缺点

二叉查找树,相信大家都接触过,二叉查找树的特点就是左子树的节点值比父亲节点小,而右子树的节点值比父亲节点大,如图:

基于二叉查找树的这种特点,我们在查找某个节点的时候,可以采取类似于二分查找的思想,快速找到某个节点。n 个节点的二叉查找树,正常的情况下,查找的时间复杂度为 $O(log_2n)$。

之所以说是正常情况下,是因为二叉查找树有可能出现一种极端的情况,例如

这种情况也是满足二叉查找树的条件,然而,此时的二叉查找树已经近似退化为一条链表,这样的二叉查找树的查找时间复杂度顿时变成了 O(n),可想而知,我们必须不能让这种情况发生,为了解决这个问题,于是我们引申出了平衡二叉树

  ...


【Microservices】微服务架构(Microservice Architecture)

Monolithic Architecture

To start explaining the microservice style it’s useful to compare it to the monolithic style: a monolithic application built as a single unit. Enterprise Applications are often built in three main parts: a client-side user interface (consisting of HTML pages and javascript running in a browser on the user’s machine) a database (consisting of many tables inserted into a common, and usually relational, database management system), and a server-side application. The server-side application will handle HTTP requests, execute domain logic, retrieve and update data from the database, and select and populate HTML views to be sent to the browser. This server-side application is a monolith - a single logical executable. Any changes to the system involve building and deploying a new version of the server-side application.

Such a monolithic server is a natural way to approach building such a system. All your logic for handling a request runs in a single process, allowing you to use the basic features of your language to divide up the application into classes, functions, and namespaces. With some care, you can run and test the application on a developer’s laptop, and use a deployment pipeline to ensure that changes are properly tested and deployed into production. You can horizontally scale the monolith by running many instances behind a load-balancer.

以Java为例,所有的功能打包在一个 WAR包里,基本没有外部依赖(除了容器),部署在一个JEE容器(Tomcat,JBoss,WebLogic)里,包含了 DO/DAO,Service,UI等所有逻辑。

  ...


【Database】读写分离(Read/Write Splitting)

读写分离(Read/Write Splitting)+ 主从复制(Master-slave Replication)

**读写分离(Read/Write Splitting)**的基本思想:让集群中的主数据库负责增(insert)、删(delete)和改(update)事务操作,而集群中的从数据库负责查询操作(select);并且,数据库后台会自动将因在主数据库中进行的事务操作导致的数据变更,同步到集群中的各个从数据库中。

MySQL的主从复制和MySQL的读写分离两者有着紧密联系,首先部署主从复制,只有主从复制完了,才能在此基础上进行数据的读写分离。简单来说,读写分离就是只在主服务器上写,只在从服务器上读,基本的原理是让主数据库处理事务性查询,而从数据库处理select查询。当业务量非常大时,一台服务器的性能无法满足需求,就可以通过配置主从复制实现写分离来分摊负载,避免因负载太高而造成无法及时响应请求。

读写分离的方式,扩展了数据库对读数据的处理能力,但写能力并没有任何提升。

而且,数据库中单表的数据量是有限制的,当数据库中单表的数据量到达一定程度后,数据库的性能会显著下降。

使用原因

大部分互联网业务读多写少,数据库的读往往最先成为性能瓶颈,如果希望:

  • 线性提升数据库读性能
  • 通过消除读写锁冲突提升数据库写性能

此时可以使用分组架构。

一句话,分组主要解决“数据库读性能瓶颈”问题,在数据库扛不住读的时候,通常读写分离,通过增加从库线性提升系统读性能。

适用场景

读写分离适用与读远大于写的场景,如果只有一台服务器,当select很多时,update和delete会被这些select阻塞,因此并发性能不高。 对于写和读比例相近的应用,应该部署双主相互复制。

  ...