当前位置:网站首页>Common interview questions of microservice
Common interview questions of microservice
2022-07-03 05:11:00 【Li Dabao】
1、 Tell me about your right springcloud The understanding of the ?
Spring cloud yes ⼀ Based on Spring Boot Implemented service governance framework ,⽤ Manage and coordinate various services in the microservice architecture . It provides a series of components to facilitate users to quickly build microservices , Such as service discovery registration nacos、 Configuration in progress ⼼nacos、 The service gateway gateway, Client load configuration Ribbon、 Call between services openfeign、 Short circuiting device Hystrix、 Distributed transaction service Seata etc.

2、nacos Registration Center workflow
- 1、 Service registration :Nacos Client By sending REST The way of request to Nacos Server Register your services , Provide its own metadata . such as IP Address 、 Port and other information ,Nacos Server After receiving the registration request , This metadata information will be stored in a double layer of memory Map in .
- 2、 Service heartbeat : After service registration ,Nacos Client Will maintain a timed heartbeat to continuously notify Nacos Server, Indicates that the service is always available , Prevent being kicked out . Default 5 Send a heartbeat every second .
- 3、 Service synchronization :Nacos Server The cluster will synchronize service instances with each other , To ensure the consistency of service information .
- 4、 Service discovery : Serving consumers (Nacos Client) When invoking a service provider's service , Will send a REST Request to Nacos Server, Get the list of services registered above , And exist slowly Nacos Client Local , At the same time Nacos Client Start a scheduled task locally (35 second / Time ) Regularly pull the latest registry information of the server and update it to the local cache .nacos Support the message push mode of service list change , The service list is updated timely
- 5、 Service health check :Nacos Server A scheduled task will be started to check the health of the registered service instance , For more than 15 No instance of client heartbeat was received in seconds , It will be healthy Attribute is set to false( When the customer service is found, it will not get ), If a service instance exceeds 30 Seconds, no heartbeat , Kick the instance directly ( If the kicked instance resumes sending heartbeat, it will be re registered )
3、nacos How to have a health check ?
nacos There are two ways of health monitoring , One is for temporary services , One is persistent Services , The service is registered through ephemeral Parameters ,ephemeral=true Representatives are temporary services ,ephemeral=false Represents persistent Services , All services are temporary by default
- Temporary instance every 5 Second will take the initiative to report their health status once , The packets sent are called heartbeat packets , The mechanism of sending heartbeat packets is called heartbeat mechanism . If the interval between heartbeat packets exceeds 15 second , that Nacos The server will mark this service instance as an unhealthy instance , If the heartbeat packet exceeds 30s second , that Nacos The server will delete this service instance from the service list
- Persistent service checking mechanism : Active detection by the registry , Its detection period is 2000 millisecond + random number (5000 Within milliseconds ), Detection failure , Service is unhealthy , But the service will not be removed , Persistent instance support 3 A detection protocol ,TCP、HTTP and MySQL, The default detection protocol is TCP, That is, through constant ping To determine whether the instance is healthy .
4、nacos Configuration center dynamic monitoring
nacos It's using pull Pattern ( The client actively pulls data from the server ), But it's not simple pull Pattern , But a long rotation training mechanism , It is a combination of push and pull The advantages of both , The client uses long rotation training to launch regularly pull request , Check whether the service configuration information has changed , If the configuration of the server changes , Go straight back , If there is no change , Then the server will hold Live in this request , That is, the server will not return results within the specified time after receiving the connection , Until the configuration changes during this period , The server will change the original hold Live request to return . The default time for long connections is 30 second
5、Feign Summary of the principle of service invocation
Feign yes ⼀ individual HTTP Requested lightweight client frame . adopt Interface + In the form of annotations HTTP Request calling ,Feign By default, we use JDK Native URLConnection send out HTTP request , No connection pool , But there will be a long connection for each address , It is using HTTP Of persistence connection. We can use Apache Of HTTP Client Replace Feign The original http client, To get the connection pool 、 Timeout and other performance related control capabilities
- adopt @EnableFeignCleints Trigger Spring The app is right for @FeignClient Scanning of decorated classes
- Resolved to @FeignClient After decorating the class , Feign The framework extends Spring Bean Deifinition The registration logic of , Finally register a FeignClientFacotoryBean Get into Spring Containers
- Spring Container is used in initializing other @FeignClient Class time of interface , What you get is FeignClientFacotryBean Generate a proxy object Proxy.
- be based on java Native dynamic agent mechanism , in the light of Proxy Call to , Will be uniformly forwarded to Feign A framework defined by Handler , From the Handler Follow up HTTP transformation , send out , Receiving and other work
6、 say something Ribbon How to achieve load balancing ?
Send a request , By LoadBalancerInterceptor Interceptor interception , The request was handed over to ribbon To deal with it
LoadBalancerClient At initialization time (execute Method ), Will pass ILoadBalance(BaseLoadBalancer It's the implementation class ) Get the service registration list from the registry , And pass the service health examination , To determine the availability of services , If the availability of services changes or the number of services is inconsistent with the previous , Update or re pull from the registry .LoadBalancerClient With these service registration lists , According to the specific IRule To load balance .
Use a load balancing algorithm ( Default polling algorithm ) Select a machine from all the service instance information
Send the request to the service instance selected by load balancing
7、spring cloud The difference and description between degradation and fusing
Service failure
The function of service fuse is similar to the fuse in our home , When a service becomes unavailable or the response times out , To prevent the whole system from avalanche , Temporarily stop the call to the service .
service degradation
- Service degradation is based on the load of the whole system , For some cases where the load will be higher , To prevent certain functions ( Business scenario ) In case of overload or slow response , In its internal temporarily abandon some non core interface and data request , And go straight back to a prepared fallback( retreat ) Error handling information . such , Although it's a damaging service , But it ensures the stability and availability of the whole system .
- The biggest difference between service fusing and service degradation is , Self recovery , When a node is fused, it is detected that the node is normal, and the normal service will be restored , Demotion will not , stay SpringCould In frame , The fusing mechanism passes through Hystrix Realization ,Hystrix It will monitor the call status between microservices , When a failed call reaches a certain threshold , The default is 5 Seconds 20 Call failed , It will activate the fuse mechanism , The note of the fusing mechanism is @HystrixCommand
The opening of the circuit breaker only needs to directly the parameters of the circuit breaker on the basis of degradation , Here are several main parameters: time window 、 Number of requests 、 Failure rate , That is, the failure rate reaches the threshold of the number of requests within a time window , Open fuse
After the fuse is turned on, normal requests will be degraded , After a while ( Default 5 second ) The fuse will enter a half open state , Can put 1 A request came to try to execute the business code , If it can be executed normally and returns normal results , Then the fuse will close , If it still fails, the circuit breaker will continue to open , Wait for the next half open state to check whether the service is normal
Snapshot time window : It is necessary to count some request and error data when determining whether to open the circuit breaker , The statistical time range is the snapshot time window , Default to the latest 10 second .
Minimum number of requests : In the snapshot window , The lower limit of the total number of requests must be met in order to be eligible for fusing . The default is 20, It means in 10 Seconds , If it's time to hystrix Command call is not enough at this time 20 Time , Even if all requests time out or fail for other reasons , None of the breakers will open .
Lower error percentage limit : When the total number of requests in the snapshot window exceeds the lower limit , For example, something happened 30 Secondary call , If in this 30 In calls , Yes 16 Timeout exception occurred , That's more than 50% Percentage of errors , In default settings 50% At the lower limit , This will turn on the circuit breaker .
.
边栏推荐
- Automatic voltage rise and fall 5-40v multi string super capacitor charging chip and solution
- sql语句模糊查询遇到的问题
- Common methods of JS array
- 小学校园IP网络广播-基于校园局域网的小学IP数字广播系统设计
- [research materials] annual report of China's pension market in 2021 - Download attached
- JDBC database operation
- Yolov5 input (II) | CSDN creative punch in
- Analysis of proxy usage of ES6 new feature
- Actual combat 8051 drives 8-bit nixie tube
- [backtrader source code analysis 5] rewrite several time number conversion functions in utils with Python
猜你喜欢

RT thread flow notes I startup, schedule, thread

leetcode406. Rebuild the queue based on height

Without 50W bride price, my girlfriend was forcibly dragged away. What should I do

Introduction to deep learning (II) -- univariate linear regression

BTC-密码学原理

Basic use of Metasploit penetration testing framework

(完美解决)matplotlib图例(legend)如何自由设置其位置

小学校园IP网络广播-基于校园局域网的小学IP数字广播系统设计

Gbase8s unique index and non unique index

Yolov5 model construction source code details | CSDN creation punch in
随机推荐
Automatic voltage rise and fall 5-40v multi string super capacitor charging chip and solution
JS string and array methods
[research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached
Dynamic programming - related concepts, (tower problem)
On typescript and grammar
Online VR model display - 3D visual display solution
Chapter II program design of circular structure
Burp suite plug-in based on actual combat uses tips
How to connect the network: Chapter 2 (Part 1): a life cycle of TCP connection | CSDN creation punch in
Botu uses peek and poke for IO mapping
SSM framework integration
Redis Introduction et explication des types de données
appium1.22.x 版本後的 appium inspector 需單獨安裝
Without 50W bride price, my girlfriend was forcibly dragged away. What should I do
The principle is simple, but I don't know how to use it? Understand "contemporaneous group model" in one article
Source insight garbled code solution
Use posture of sudo right raising vulnerability in actual combat (cve-2021-3156)
M1 Pro install redis
2022-02-12 daily clock in: problem fine brush
Handler understands the record