Learn what microService
Reference: https://www.cnblogs.com/skabyy/p/11396571.html
A), the drawbacks of the original monomers services
Scene presentation:
Requirements: Xiao Ming and small leather together to do business story online supermarket
Features:
website
- User registration, log function
- Product showcase
- Order
Management background
- User Management
- Commodity Management
- Order Management
Two), Business Development:
- Website promotion system to increase functionality
- Increasing mobile device: a small micro-channel program, moving the App (same function and the function of the site of the mobile device),
- Add a promotional management and data analysis system in the background
- Four systems share a database
After business expansion architecture drawbacks arise;
1. The mobile terminal sites and applications many of the same business logic code duplication
2. Data is sometimes shared by the database, and sometimes through the interface call transfer. Call interfaces messy relationship
3. The database table structure is dependent on a plurality of applications, and can not be reconstructed optimization
4. All applications in a database operation, a sharp decline in the performance of database
The development, testing, deployment, maintenance more difficult, even if only a small change function, but also need to publish the entire application together,
C) micro-service features:
Abstract: Abstract of the operational capacity of the public, made several public service
Solve common problems among application database: a database corresponds to a service
Split the database to generate problems and challenges: cascade across libraries needs
D), logs for
Logs for the original monomer system: view the log, the error message and call stack study
In the micro-service architecture, a service failure may cause an avalanche effect, cause the entire system failure
E), the drawbacks of micro-services
1. Micro Services Architecture dispersed throughout the application into multiple services, very difficult to locate the point of failure
2. Stability decline, a service failure, may cause the entire system to hang
3. The number of services is very large, heavy workload deployment and management
4. How to ensure that all services remain synergies in the case of the continued development of
5. Test the original single program into a test between service calls. Testing becomes more complex
F) How to troubleshoot:
Reduce errors: ex ante control, post hoc analysis
Reduction: fault tolerance, service degradation
Establish a sound monitoring system
Micro-service architecture, many components, each different component indicators need to be monitored, to make a large and comprehensive monitoring system to monitor the various components is not realistic
For example: There are indicators Redis cache memory for monitoring the value of network traffic, monitor database connections, disk space, number of concurrent business service monitoring, response delay, error rate, etc.
How to monitor:
1. The various components of the current state of their own reporting interface (metrics Interface)
2. Interface consistent output data format
3. Deploying a metrics acquisition assembly, timing acquisition and retention assembly from the state of these interfaces, provide access to services
4. The need UI, which query the index from the index collection, drawing or monitoring interface according to an alarm threshold value.
For example: Redis cache and index interfaces MySQL database: RedisExporter and MySQLExporter (online open source components)
Used as an index using the collector Prometheus
Six), the tracking link
What is tracked link?
A user's request often involves multiple internal service calls
LT: record each user request, internal records produced a number of micro-service service calls, and call relations
Implements link tracking:
1), at least four service calls to be recorded in the data in the HTTP HEADERS
1.traceId: identifying a calling user requests a link with the same call it belongs to the same link traceId
2.spanId: id identifies a service call
spanId parent node: 3.parentId
4.requestTime & responseTime: request and response times
2) call log collection and storage components, as well as UI components show a link called
Link tracking implementation process:
HTTP requests using interceptors, which generates data to HEADERS injected at each HTTP request, and call logs sent asynchronously to Zipkin log collection vessel
Link tracking services can only target problems which arise, find specific error message capability is required to be provided by the log analysis component
Log Analysis
ELK (Elasticsearch, Logstash and Kibana) log analysis components:
Elasticsearch: search engines, but also store logs
Logstash: log collection, a log which receives an input, some pre-processing the log, and then output to Elasticsearch
Kibana: UI components, data Elasticsearch find an API and displayed to the user
Log analysis process:
------ log output to a file "service in each deploy one Agent, scans the log files -------" to the logstash