Micro service

Traditional stand-alone applications rely on JAR packages to call local methods, but such a strong dependency leads to an increasingly large system, which is not easy to deploy and maintain, and the system availability is poor. Therefore, we split the application into independent services. These services communicate with each other through RPC remote method call. In this way, decoupling between modules is achieved, and each module will not be affected by the update and release of other modules. Then the service number corresponding to smaller dimensions in each service, such as the circle of friends module and then unpacked into dynamic module, comment module, like module, is called micro service.

Service publication and reference is how each service of the service provider is described externally and how the service consumer refers to the service. For example, you need to define the interface name, parameters, and return value types of the service. Consol and Dubbo Restful apis: service description for HTTP XML: service description for RPC

Dubbo-rpc: Dubbo remote calls are integrated by default.

[How services are published and subscribed] Registry: Service providers register their services and addresses with the registry; Consumers subscribe to service addresses in the registry and get a list of service listings. When a service provider node changes, the registry synchronizes the change, and the consumer is aware of the change and refreshes the cache manifest in local memory. Therefore, a registry should provide service registration/unregistration interface, heartbeat reporting interface, service subscription interface, service change query interface and other core operations.

And the registry needs to accommodate cluster deployment.. Directories store.. Service health monitoring.. Service status Change notification.. Whitelist mechanism, etc.

Eureka: It belongs to the registration and discovery within the application, that is, it provides the SDK of the client and the server. Our application needs to introduce the SDK of Eureka to directly complete the registration and discovery of services within the application. Because it’s an in-app SDK, it only works when the provider and consumer are the same service.

Consul: It provides a third-party service manager, Registrator, that listens on Docker instances deployed by the service to determine viability and is responsible for registration and reconciliation of service providers; It also provides Consul Template to get the latest list of services from the registry on a regular basis.

Registries focus on data consistency: To ensure high availability, registries tend to be clustered, so we need to ensure consistency of node data across multiple data centers. The C(consistency), A(availability), and P(fault tolerance) theory. P: A network fault divides the network into disconnected areas. As a result, data cannot be shared between areas. Therefore, partition fault tolerance is generally to copy data to nodes in other partitions to ensure data consistency after partition. CA: But when you share data across multiple partitions, there are consistency and availability issues. That is, data on all nodes is consistent and all nodes are updated successfully. Therefore, the more data nodes have, the more AP can be guaranteed, but C consistency cannot be guaranteed. However, we need to increase machines to ensure data consistency on the basis of P, so the availability of A cannot be guaranteed.

CP: Sacrifice availability to ensure strong data consistency, such as ZK. The ZK cluster has only one Leader who synchronizes data to other Followers to ensure consistency. However, if a network partition problem occurs between multiple ZKS, multiple leaders will be mistakenly elected and the registry will become unavailable.

AP: Sacrificing consistency to ensure data availability, such as Eureka. Eureka servers keep separate lists of services, and each server can perform separate services when network partitions occur. But because of this, it may have inconsistent data information.

Nacos: Registry and configuration center, can support AP and CP, but registry is more focused on availability, once the registry is not available, the communication of the whole microservice can not communicate, resulting in the service crash.

We get the address of the service provider, and we call it. Therefore, we should pay attention to: what network protocol is adopted for service communication, what method of data transmission is adopted (synchronous asynchronous, single connection multiplexing), and what format of data compression is adopted.

Zuul: gateway that configures rules to provide routing services for request urls.

How does the service monitor indicator collection, data processing, data presentation, service tracking

[Sentinel: Flow Management and Fuse downgrading]

[How services are governed]

[How to Locate a Fault]

SpringCloud is a microservice ecosystem that provides many components that make it easier to build microservice projects on top of SpirngBoot.

The container

A container is actually a special process. When a container is started on Linux, Linux will set some parameters for the container process and isolate irrelevant resources for the container application process to achieve process space isolation. So when we perform ps after starting the container, we can see that the container process PID =1, but it is not actually 1 on our host, just that Linux’s Namespace mechanism creates an isolated process space for it. This allows our application to be placed in a container that has separate boundaries from other processes on the host, so the container is like a container that can move applications around. (The virtual machine is a newly created process and has one more virtual OS than the container). So, multiple containers on Linux share the operating system kernel. So although the container process is isolated on the surface, it can use resources such as CPU and memory, and can be occupied by other processes on the host at any time, which is obviously not in accordance with the characteristics of sandbox. So we have Linux Cgroups, which set resource limits for a group of processes (the process groups in the Tasks file), so that the resources it needs are isolated from other processes. We use docker run –.. Specify parameters for it.

Since containers are sandboxed, they need to be moved and used everywhere, while our application’s environment is based on the base of its original operating system, namely the file system and directory (the container uses the host’s operating system kernel). Hence the image, rootFS (root file system). When a container process starts, Mount Namespace remounts the root directory “/” for it. The original file directory of the container process is mounted to its Linux counterpart, and the Mount is not visible to the host. The container process view becomes the root view of the operating system, with all the file systems and directories that the mirror process needs to run. The file system that is mounted to the root directory and used to provide the container process with an isolated execution environment is the container image, also known as rootFS.

The image is layered, and we can change it incrementally to the version we want. This depends on the federated file system. One layer corresponds to a delta. When using the image, Docker will mount the delta to a unified directory, which is a complete file directory for the container process to use.

Make container image:

(1) Compile Dockerfile (FROM base image, RUN install dependency, ENV environment, etc.), then execute docker build-t name to create image.

②docker run [-p port :port] imgName imgTag: start the image.

③ Docker target: Give the image a full name.

④ Docker commit: a running container is directly committed to the image for saving, that is, the image read-only layer of the original container and the current top writable and readable layer are wrapped up into a new image.

⑤ Docker push uploads images to docker Hub

Docker image is: view all images on the host

Docker image pull: Pull the image to the docker host repository