Java framework for distributed collection of interview questions

Java framework for distributed collection of interview questions

1. What is ZooKeeper?

A: ZooKeeper is an open source distributed application coordination service, is a typical distributed data consistency solutions. Those designed to complex and error-prone distributed consistency service package together to form an efficient and reliable system, and is easy to use a series of atomic operations available to users.

2.ZooKeeper provides what features?

A: ZooKeeper provides the following functions:

  • Distributed service registration and subscription: In a distributed environment, in order to ensure high availability, usually with the same application or a service provider will deploy more than to reach for other services. And consumers will need to select a relevant business logic to perform these peer server, the typical registration and subscription services, such as Dubbo.
  • Distributed Configuration Center: publish and subscribe model, the so-called distribution center, by definition is the publisher will publish data on ZooKeeper node for subscribers to obtain data, centralized management and dynamic update configuration information.
  • Naming Service: In a distributed system, it is possible to obtain resources in accordance with the specified name by naming service client applications, service providers address and other information.
  • Distributed Lock: This is mainly due to the strong ZooKeeper for us to ensure data consistency.

There are several built 3.ZooKeeper mode?

A: ZooKeeper usually has three modes to build:

  • Stand-alone mode: zoo.cfg only configure one server.id is a stand-alone mode, this mode is generally used in the test environment, if the current host goes down, all depends on the current work of other ZooKeeper service servers can not work properly;
  • Pseudo-distributed mode: starting a machine ZooKeeper different ports, arranged to zoo.cfg, the same and stand-alone mode, this mode is generally used in a test environment;
  • Distributed mode: multiple machines each configuration zoo.cfg file, each server will be added to their list, built on top of this cluster is fully distributed.

What features 4.ZooKeeper there?

A: ZooKeeper characteristics are as follows:

  • Sequential Consistency (Sequential Consistency): transactions from the same client submitted, ZooKeeper will be strictly followed by the implementation in accordance with its order of submission;
  • Atomicity (Atomicity): committing the transaction to the ZooKeeper cluster, the transaction will be "completed" or "all unfinished", "partially completed" does not exist;
  • A single system image (Single System Image): The client is connected to any node in the cluster ZooKeeper, which view is obtained are the same;
  • Reliability (Reliability): Upon completion of the transaction, which generates a state change will be permanently retained until covering other transactions;
  • Real-time (Timeliness): Once the transaction is completed, the client will be limited period of time, obtain the latest data.

5. The following is a description of the error on ZooKeeper?

A: All nodes have a stable memory capacity B: It is possible to perform communication between any node ZooKeeper (message transmission & reception) C: To improve performance, some of the nodes are permitted ZooKeeper successful write same data, writing another portion of node failure D: during the cluster is running ZooKeeper, as long as more than half of nodes alive, ZooKeeper normal service will be able to answer: C title parsing: ZooKeeper does not allow the same data exists a subset of nodes to write successful, another part of the write node fails, it does not meet ZooKeeper "consistent of "principle.

How 6.ZooKeeper achieve Distributed Lock?

A: The implementation of distributed lock step ZooKeeper as follows:

  • Client connection ZooKeeper, and creates a temporary and orderly child node in / lock, the first child node of a corresponding client / lock / lock-10000000001, the second is / lock / lock-10000000002, in order to analogy.
  • Client obtains a list of child nodes under / lock, determine whether the child nodes that you create for the current list of child nodes youngest child node number, if it is considered to obtain a lock, or monitor the child node just before one of their own deleted messages after obtaining sub-node change notification repeat this step until a lock is obtained;
  • Business code execution;
  • After the completion of business processes, delete the corresponding child node releases the lock.

How 7.ZooKeeper implement distributed transactions?

A: ZooKeeper implement distributed transactions, similar to the two-phase commit, in total divided into the following four steps:

  • ZooKeeper give the client node sends a write request;
  • ZooKeeper node will forward the request to write Leader node, cluster requires Leader broadcast to vote, waiting for confirmation;
  • Leader acknowledgment is received, voting statistics, more than half the votes transaction is committed;
  • After the transaction commits successfully, ZooKeeper nodes tell the client.

8. Why should the master node in the cluster?

A: In a distributed environment, some business logic needs only one of the machines in the cluster for execution, other machines can share the results, which can greatly reduce double counting, improve performance, and this is the meaning of existence of the master node.

What 9.Dubbo that?

A: Dubbo is a high performance, lightweight open-source Java RPC framework, which provides three core capabilities: an interface for remote method invocation, intelligent fault tolerance and load balancing, and automatic registration and service discovery.

What features 10.Dubbo there?

A: Dubbo characteristics are as follows:

  • High performance RPC interface proxy for calling: remote call providing high performance based on the ability of the agent, the service interface to the particle size, the underlying details of the remote call shielding developers;
  • Intelligent load balancing: Built-in a variety of load balancing strategy, IntelliSense health of downstream node, significantly reduce call latency, improve system throughput;
  • Auto service registration and discovery: support a variety of registry services, real-time off the assembly line on perceived service instance;
  • Highly scalable: + follow microkernel design principles plug-in, all core competencies such as Protocol, Transport, Serialization is designed as an extension point, equal treatment and built to achieve third-party implementation;
  • Run-time traffic scheduling: built-in condition, scripts, and other routing policies by configuring different routing rules, easily publish gray, with priority to the engine room and other functions;
  • Visualization of service management and operation and maintenance: provide rich service management, operation and maintenance tools: always check the service metadata, services, health status and call statistics, real-time routing policy issued, adjust the configuration parameters.

What are the core components 11.Dubbo there?

A: Dubbo core components as follows:

  • Provider: Service Provider
  • Consumer: Consumer Services
  • Registry: service registration and discovery registries
  • Monitor: The main statistical services for the number of calls and call times
  • Container: run container services

12.Dubbo which load balancing strategies?

A: Dubbo responsible for balancing strategy is as follows:

  • Randomized load balancing (Random LoadBalance): Press the weight setting random probability, high probability in a cross section of the collision, but the call amount greater distribution more uniform, and after use by probability weight is also uniform, facilitate dynamic adjustment provided by the weight;
  • Polling load balancing (RoundRobin LoadBalance): by convention right after reset polling rate, there is a problem of slow accumulation provider's request, such as: the second machine is very slow, but did not hang, when transferred to a second request on the card in that, over time, all requests are transferred to the card in the second stage;
  • Minimum number of calls active load balancing (LeastActive LoadBalance): using the minimum number of active calls, the number of active call count means before and after a difference;
  • Load balancing hash (ConsistentHash LoadBalance): forward hash value, the request is always sent to the same parameters of the same provider.

Load Balancing configuration is as follows :

Server service levels

\<dubbo:service interface="xxx" loadbalance="roundrobin" /\>

Client service levels

\<dubbo:reference interface="xxx" loadbalance="roundrobin" /\>

Server-side method level

\<dubbo:service interface="xxx"\>
   \<dubbo:method name="xxx" loadbalance="roundrobin"/\>
\</dubbo:service\>

Client method level

\<dubbo:reference interface="xxx"\>
   \<dubbo:method name="xxx" loadbalance="roundrobin"/\>
\</dubbo:reference\>

13.Dubbo Which of the following does not support the agreement?

A:dubbo://
B:rmi://
C:redis://
D:restful://

Answer: D

Topic resolve: restful is a programming standard, not a transport protocol, and is not supported Dubbo.

What 14.Dubbo default registry, there are other options to use it?

A: ZooKeeper is recommended as a registration center, as well as Nacos, Redis, Simple registration center (ordinary Dubbo service).

15.Dubbo support multi-registry do?

A: Dubbo registered the same service at the same time to support multi-registry, or different services are registered to different registries up, even cited the same name registration service in different registries at the same time.

Multi-registry registration:

\<?xml version="1.0" encoding="UTF-8"?\>
\<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://dubbo.apache.org/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd"\>
    \<dubbo:application name="world" /\>
    \<!-- 多注册中心配置 --\>
    \<dubbo:registry id="hangzhouRegistry" address="10.20.141.150:9090" /\>
    \<dubbo:registry id="qingdaoRegistry" address="10.20.141.151:9010" default="false" /\>
    \<!-- 向多个注册中心注册 --\>
    \<dubbo:service interface="com.alibaba.hello.api.HelloService" version="1.0.0" ref="helloService" registry="hangzhouRegistry,qingdaoRegistry" /\>
\</beans\>

Connection 16.Dubbo support of what?

A: The main connection Dubbo supported are: multicast, and even till ZooKeeper registry.

① multicast mode , do not need to start any central node, as long as the broadcast address, you can find each other.

  • When the provider to start broadcasting its own address
  • When the consumer starts broadcasting subscription request
  • When providers receive a subscription request unicast own address to subscribers, if you set the unicast = false, then broadcast to subscribers
  • When the consumer has received the provider address, the connection address RPC call

Multicast network by structural constraints, only suitable for small-scale applications or development stage use. Multicast addresses: 224.0.0.0 ~ 239.255.255.255

Configuration

\<dubbo:registry address="multicast://224.5.6.7:1234" /\>

or

\<dubbo:registry protocol="multicast" address="224.5.6.7:1234" /\>

In order to reduce the amount of broadcast, Dubbo default unicast delivery provider address information to consumers, if a machine at the same time start the process of multiple consumers, consumers need to declare unicast = false, otherwise it will have a consumer can receive message; and consumers when the service running on the same machine, consumers also need to declare unicast = false, otherwise consumers can not receive the message, resulting in No provider available for the service exception:

\<dubbo:registry address="multicast://224.5.6.7:1234?unicast=false" /\>

or

\<dubbo:registry protocol="multicast" address="224.5.6.7:1234"\>
    \<dubbo:parameter key="unicast" value="false" /\>
\</dubbo:registry\>

② direct connection , the registry itself is a common Dubbo service, you can rely on third parties to reduce the overall consistency of communication.

\<dubbo:registry protocol="zookeeper" address="N/A" file="./.dubbo-platform"/\>

Simple registration center will be exposed to Dubbo service:

\<?xml version="1.0" encoding="UTF-8"?\>
\<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://dubbo.apache.org/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd"\>
    \<!-- 当前应用信息配置 --\>
    \<dubbo:application name="simple-registry" /\>
    \<!-- 暴露服务协议配置 --\>
    \<dubbo:protocol port="9090" /\>
    \<!-- 暴露服务配置 --\>
    \<dubbo:service interface="org.apache.dubbo.registry.RegistryService" ref="registryService" registry="N/A" ondisconnect="disconnect" callbacks="1000"\>
        \<dubbo:method name="subscribe"\>\<dubbo:argument index="1" callback="true" /\>\</dubbo:method\>
        \<dubbo:method name="unsubscribe"\>\<dubbo:argument index="1" callback="false" /\>\</dubbo:method\>
    \</dubbo:service\>
    \<!-- 简单注册中心实现,可自行扩展实现集群和状态同步 --\>
    \<bean id="registryService" class="org.apache.dubbo.registry.simple.SimpleRegistryService" /\>
\</beans\>

Reference Simple Registry Service:

\<dubbo:registry address="127.0.0.1:9090" /\>

or:

<dubbo:service interface="org.apache.dubbo.registry.RegistryService" group="simple" version="1.0.0" ... >

or:

<dubbo:registry address="127.0.0.1:9090" group="simple" version="1.0.0" />

Applicability: This SimpleRegistryService simply realize, do not support cluster can be used as reference custom registry, but not directly suitable for production environments.

③ ZooKeeper registry , Zookeeper is Apacahe Hadoop subprojects, is a tree of directory services to support change push for Dubbo services as registration centers, industrial high strength, can be used in a production environment, and recommended.

Service Provider startup: URL address to write their own directory under /dubbo/com.foo.BarService/providers

  • When consumers start service: subscription provider directory at /dubbo/com.foo.BarService/providers URL address, and write their own URL address directory under /dubbo/com.foo.BarService/consumers
  • Monitoring Center on startup: subscribe to all providers and consumers under /dubbo/com.foo.BarService directory URL address

It supports the following features:

  • When the provider of a power failure or other abnormal shutdown, the registry can automatically delete information provider
  • When the registry to restart, can automatically restore the registration data, as well as subscription request
  • When the session expires, it can automatically restore the registration data, as well as subscription request
  • When set <dubbo:registry check="false" />, the recording fails registration and a subscription request retry timer background
  • By <dubbo:registry username="admin" password="1234" />login settings zookeeper
  • By <dubbo:registry group="dubbo" />setting the root node zookeeper is not provided unrooted trees using
  • Support *wildcard <dubbo:reference group="*" version="*" />all packets can subscribe to the service providers and all versions

Zookeeper use

Increase provider and consumer customers zookeeper mid jar package dependency:

\<dependency\>
    \<groupId\>org.apache.zookeeper\</groupId\>
    \<artifactId\>zookeeper\</artifactId\>
    \<version\>3.3.3\</version\>
\</dependency\>

Dubbo support zkclient and curator two kinds Zookeeper client implementation:

Note: zkclient has been removed to achieve the 2.7.x version, if you want to use zkclient client, we need to expand on their own.

Use zkclient client

From version 2.2.0 by default zkclient beginning to realize, in order to enhance the healthy state of the zookeeper client. zkclient is a Zookeeper Datameer open source client implementations.

The default configuration:

\<dubbo:registry ... client="zkclient" /\>

or:

dubbo.registry.client=zkclient

or:

zookeeper://10.20.153.10:2181?client=zkclient

Or need to rely on direct download :

\<dependency\>
    \<groupId\>com.github.sgroschupf\</groupId\>
    \<artifactId\>zkclient\</artifactId\>
    \<version\>0.1\</version\>
\</dependency\>

Use curator client

From version 2.3.0 started to support an optional curator achieve. Curator open source Netflix is ​​a Zookeeper client implementation.

If you need to change curator implement, configure:

\<dubbo:registry ... client="curator" /\>

or:

dubbo.registry.client=curator

or:

zookeeper://10.20.153.10:2181?client=curator

Or need to rely on direct download:

\<dependency\>
    \<groupId\>com.netflix.curator\</groupId\>
    \<artifactId\>curator-framework\</artifactId\>
    \<version\>1.1.10\</version\>
\</dependency\>

Zookeeper stand-alone configuration:

\<dubbo:registry address="zookeeper://10.20.153.10:2181" /\>

or:

\<dubbo:registry protocol="zookeeper" address="10.20.153.10:2181" /\>

Zookeeper cluster configuration:

\<dubbo:registry address="zookeeper://10.20.153.10:2181?backup=10.20.153.11:2181,10.20.153.12:2181" /\>

or:

\<dubbo:registry protocol="zookeeper" address="10.20.153.10:2181,10.20.153.11:2181,10.20.153.12:2181" /\>

The same Zookeeper, divided into groups registry:

<dubbo:registry id="chinaRegistry" protocol="zookeeper" address="10.20.153.10:2181" group="china" />
<dubbo:registry id="intlRegistry" protocol="zookeeper" address="10.20.153.10:2181" group="intl" />

17. What is the service fuse?

A: In the application system, when the dependent services due to excessive pressure and visited slow response or failure, upstream service in order to protect the overall availability of the system, temporarily cut off the call to the downstream services. Local sacrifice, to preserve the overall measure is called blown.

18.Dubbo can cache the results? What are the types of support caching?

A: Yes, Dubbo provides declarative cache to accelerate popular data access speed, add cache to reduce user workload.

Dubbo Support cache types are:

  • lru based on the principle of least recently used to remove the extra cache, maintaining the hottest data is cached;
  • threadlocal current thread cache, such as rendering a page, use a lot of portal, each portal have to check user information through the thread cache can reduce this unnecessary access;
  • jcache integration, can bridge all kinds of cache implementation.

Configuration is as follows:

\<dubbo:reference interface="com.foo.BarService" cache="lru" /\>

or

\<dubbo:reference interface="com.foo.BarService"\>
    \<dubbo:method name="findBar" cache="lru" /\>
\</dubbo:reference\>

19.Dubbo There are several fault-tolerant cluster mode?

A: Dubbo cluster fault-tolerant mode as follows.

① Failover Cluster

Automatic switching failure when a failure occurs, retry other servers. Usually used for read operations, but retry will bring a longer delay. You can retries="2"set the number of retries (excluding the first).

Number again re-arranged as follows:

\<dubbo:service retries="2" /\>

or

\<dubbo:reference retries="2" /\>

or

\<dubbo:reference\>
    \<dubbo:method name="findFoo" retries="2" /\>
\</dubbo:reference\>
② Failfast Cluster

Quick failure, only to initiate a call immediately fails error. Write operations commonly used in non-idempotent nature, such as the new record.

③ Failsafe Cluster

Security failure, abnormal, direct ignored. Typically operable to write audit logs.

④ Failback Cluster

Automatic recovery fails, background records failed request, the retransmission timer. Typically a message notifying operation.

⑤ Forking Cluster

Call multiple servers in parallel, that is as long as a successful return. Typically used for higher real-time requirements of a read operation, but more services need to waste resources. May = "2" to set the maximum number of parallel through the forks.

⑥ Broadcast Cluster

Calling all broadcast providers, one by one call, Renyiyitai error is an error. Typically used to notify all providers such as cache or log updates the local resource information.


I welcome the attention of the public number, keyword reply " the Java ", there will be a gift both hands! ! ! I wish you a successful interview ! ! !

% 97% E5% 8F% B7 % E4% BA% 8C% E7% BB% B4% E7% A0% 81.png)

Guess you like

Origin www.cnblogs.com/dailyprogrammer/p/12272760.html