1. Description of site architecture evolution

First, the site architecture evolution

Site architecture can be divided into the following phases:
traditional architectures (single use) -> distributed architecture (project-split) -> SOA (Service Oriented Architecture) -> Micro Services Architecture

1.Monolith (single use) Architecture

1.1 What is a single application
first of all recall that we have developed service is what it looks like. Typically, the service code corresponding to a plurality of items composed, each item will have a definite boundary depending on the functionality provided by itself. At compile time, these items will be packaged into one JAR package, and eventually merge together to form a WAR package. Next, we need to upload the WAR package to the Web container, extract the WAR package, and restart the server. After completion of the implementation of this series of operations, we compile and deploy the service has been completed. This project organization and functions of all of the code are contained in one package is referred WAR Monolith. For example, we use SSH, SSM architecture are single architecture.
Here Insert Picture Description

1.2 drawback of
this architecture will be developed throughout the business modules in a project, stratified according to MVC idea.
In the case of this project is small monomer applications is relatively simple, but as the project becoming larger and larger, more and more code that will exist the following disadvantages:

  • Compile difficult, difficult to deploy, difficult to test
    the code amount more time to change a line of code, also need to spend a lot of time to compile, before deployment to compile the package, unpack it and so difficult to deploy, the deployment is over but also test so the test difficult.
  • Coupled with high
    Once a module resulting in service is unavailable, it could affect the entire project.
  • Extended difficult to
    follow the code Monolith organization will only generate a WAR package contains all the features, so when the capacity of the service to be extended, we can only choose to deploy these WAR package repeatedly to extend service capabilities, rather than merely extensions appear components of the system bottlenecks.

2. Distributed Architecture

Based on traditional architecture evolved, the entire project will be split into multiple sub-projects, divided into the following phases:
2.1 database services, applications, file separation stage
Here Insert Picture Description
2.2 application server cluster deployment phase
when a lot of business traffic when users the request will be queued, which leads to a poor user experience, this time the same application can be deployed on multiple servers, a large number of user requests distributed to each server, in order to ease the pressure on one server.
Here Insert Picture Description
And how to distribute the request, which involves the 负载均衡(Load Balancing)算法design, a good load balancing algorithm can maximize server performance will be, commonly used load balancing algorithms:

  • Polling method
    Polling method, the user's request is assigned to a server in turn, it is like counting one by one, in turn allocation. This algorithm is relatively simple, he has the advantage of absolute balance, but also because it is absolutely balanced it must pay a high price, for example, it can not guarantee the rational allocation of tasks, assign tasks based on the server unable to afford.
  • Randomly
    randomly, randomly select a server to assign tasks. It ensures the dispersion of requests reaches the balancing purposes. At the same time it is no need to maintain the previous state and the selected state equalization factors [5]. However, with the increasing amount of the task, its effects tend to poll the polling algorithm also has the disadvantage portion.
  • Minimum ligation
    minimum connection method, the task is assigned to a node having a minimum number of connections at this time, so it is a dynamic load balancing algorithm. After a node receives a number of connections is increased by one task, the node will be a node failure when weight is set to 0, the task is no longer assigned to the node. Minimum connection method suitable for each node is similar to the processing performance. The task distributing unit to the server will assign tasks smoothly. But when server performance gap is large, it can not achieve the desired results. Because the number of connections does not accurately indicate the processing power, connection small and poor performance of the server itself may be less than the number of connections big and excellent performance of the server itself. So at this time will cause the task can not be accurately allocated to a strong surplus processing capacity machine.

2.3数据库读写分离阶段
Here Insert Picture Description
2.4为了缓解数据库压力,又在系统加入NoSql(Redis、MongoDB)等内存型数据库作为缓存
此时遇到用户请求,先去查找缓存,若查到则只需要1次内存I/O;缓存中没有时,经过1次磁盘I/O从数据库读取数据,再经过1次内存I/O写入缓存。
Here Insert Picture Description
2.5将服务器集群按照应用拆分并拆分数据库
随着业务量的增加,表的数据不断增长,数据查询性能便成了问题,所以必须要对数据库进行水平拆分。水平拆分是将单个表的数据拆分到多个数据库中,如100W数据的表拆分到10个数据库后,每个表就只有10w。
Here Insert Picture Description

3.SOA架构(Service-Oriented Architecture)

在上面的架构中,用户服务会调用到商品服务,商品服务又会调用交易服务,用户服务又调用订单服务,调用关系错综复杂,维护成本不断变高。此时,SOA架构出现了:
SOA是一种粗粒度、松耦合服务架构,服务之间通过简单、精确定义接口进行通讯,不涉及底层编程接口和通讯模型。SOA可以看作是B/S模型、XML(标准通用标记语言的子集)/Web Service技术之后的自然延伸。
SOA将能够帮助软件工程师们站在一个新的高度理解企业级架构中的各种组件的开发、部署形式,它将帮助企业系统架构者以更迅速、更可靠、更具重用性架构整个业务系统。较之以往,以SOA架构的系统能够更加从容地面对业务的急剧变化。

SOA架构通俗的理解为将共同的业务逻辑抽取出来形成一个通用服务,如Mq、Hdfs、检索工具等,该服务作为一个独立项目部署,给其他服务提供接口进行调用,服务间调用依然使用RPC远程技术。
Here Insert Picture Description

4.微服务架构

微服务架构是一种架构模式,它提倡将单一应用程序划分成一组小的服务,服务之间互相协调、互相配合,为用户提供最终价值。每个服务运行在其独立的进程中,服务与服务间采用轻量级的通信机制互相沟通(通常是基于Http的Restful API)。每个服务都围绕着具体业务进行构建,并且能够被独立地部署到生产环境、类生产环境等。另外,应尽量避免统一的、集中式的服务管理机制,对具体的一个服务而言,应根据业务上下文,选择合适的语言、工具对其进行构建。
微服务是一种架构风格,一个大型复杂软件应用由一个或多个微服务组成。系统中的各个微服务可被独立开发,独立部署,独立运维,各个微服务之间是松耦合的。每个微服务仅关注于完成一件任务并很好地完成该任务。在所有情况下,每个任务代表着一个小的业务能力。
4.1.那么服务间的远程调用方式有哪些呢?
常见的远程调用方式有以下几种:

  • RPC:Remote Produce Call远程过程调用,类似的还有RMI。自定义数据格式,基于原生TCP通信,速度快,效率高。早期的webservice,现在热门的dubbo,都是RPC的典型
  • Http:http其实是一种网络传输协议,基于TCP,规定了数据传输的格式。现在客户端浏览器与服务端通信基本都是采用Http协议。也可以用来进行远程服务调用。缺点是消息封装臃肿。

Due to the presence of multiple micro-service micro-services architecture, how to manage and coordinate these services? We need to service governance framework, while springcloud is a service-based management tools Spring Boot implement package.
4.2. Cloud What is the Spring
the Spring Cloud is an ordered collection of a series of frames. It uses facilitate the development of Spring Boot cleverly simplify the development of distributed systems infrastructure, such as service discovery registration, distribution center, message bus, load balancing, circuit breakers, monitoring and other data, can be done with a style of development of Spring Boot and a key to start the deployment. Springcloud not reinventing the wheel, it just will present each company developed more mature, and can withstand the test of actual service framework combined, re-packaged masked a complex configuration and implementation of the principles by Spring Boot style, eventually to develop to set aside a set of easy to understand, easy to deploy and easy maintenance of distributed systems development kit.
The following are the main components (excerpt from Baidu):
Here Insert Picture Description
the Spring Cloud has many excellent components, a later article will enumerate.

Published 13 original articles · won praise 26 · views 6395

Guess you like

Origin blog.csdn.net/weixin_44269312/article/details/104343419