I went to Alibaba for an interview with confidence, but I didn’t expect Ryo to be on DUboo, and summed up the interview carefully in the evening.

Pay attention, don't get lost; continue to update Java related technologies and information! ! !

 

Dubbo interview topics

1. The difference between Dubbo and DubboX

Dubbox and Dubbo are essentially the same. The meaning of the name is just an extension of Dubbo. The following expanded functions are also important considerations for choosing Dubbox.

  • Support REST style remote call (HTTP + JSON/XML);
  • Support the implementation of efficient Java serialization based on Kryo and FST;
  • Support JSON serialization based on Jackson;
  • Support HTTP remoting system based on embedded Tomcat;
  • Upgrade Spring to 3.x;
  • Upgrade ZooKeeper client;
  • Support Dubbo configuration based entirely on Java code;

2. Zookeeper in Dubbo serves as the registry. If the registry clusters are all down, can publishers and subscribers still communicate?

Yes, when Dubbo is started, consumers will pull the registered producer's address interface and other data from zk and cache it locally. Each time it is called, it is called according to the address stored locally

  • The registration center is a peer-to-peer cluster, after any one goes down, it will automatically switch to another
  • The registry is all down, service providers and consumers can still communicate through local cache
  • The service provider is stateless, after any one is down, it will not affect the use
  • All service providers are down, service consumers will be unavailable, and they will reconnect indefinitely and wait for the server to recover

3. What are the roles in Dubbo?

①. Registry

Registry. It is a platform for publishing and subscribing services. It is used to replace the ESB service bus in the SOA framework.

  • Publish: After the development of the server code is completed, the service information will be published. Realize the publicity of a service.
  • Subscription: The client program downloads service content from the registration center. This process is subscription.

When subscribing to the service, all information of the published service will be downloaded to the client at one time.

The client can also customize and modify part of the service configuration information. Such as: timeout duration, call retries, etc.

②. Consumer

The consumer of the service is the client of the service.

Consumers must use Dubbo technology to develop part of the code. Basically it is a configuration file definition.

③. Provider

The provider of the service is the server.

The server must use Dubbo technology to develop part of the code. Mainly with configuration files.

④. Container

Container. The Dubbo technology server (Provider), when it starts execution, must rely on the container to start normally.

The default dependency is the spring container. And Dubbo technology cannot be separated from the Spring framework.

In the 2.5.3 version of Dubbo, the default dependency is Spring 2.5 version technology. Spring 4.5 or lower versions can be used.

In Dubbo of version 2.5.7, the default dependency is Spring 4.3.10 version technology. You can choose any Spring version.

⑤. Monitor

Monitoring center. It is a jar project provided by Dubbo.

The main function is to monitor the usage data of the server (Provider) and the consumer (Consumer). For example: what is the server, how many interfaces, how many methods, the number of calls, pressure information, etc.. How many clients are there, which services have been called End, how many times have been called etc.

4. How does Dubbo solve the security mechanism?

Dubbo uses Token to prevent users from bypassing the registration center to directly connect, and then manage authorization on the registration center. Dubbo also provides service black and white lists to control the callers allowed by the service.

5. Dubbo execution process?

  1. Start: When the Spring container is started, Dubbo's Provider is automatically started
  2. Register: Dubbo's Provider will automatically go to the registration center to register content after startup. The registered content includes:
    2.1 Provider IP
    2.2 Provider port.
    2.3 List of external interfaces provided by Provider. Which methods. Which interface classes
    2.4 Dubbo version.
    2.5 Access to the Provider agreement.
  3. Subscribe: Subscription. When the Consumer starts, it automatically goes to the Registry to get the information of the registered service.
  4. Notify: Notification. When the Provider's information changes, the Registry will automatically push notifications to the Consumer.
  5. Invoke: Invoke. Consumer calls the method in Provider
    5.1 Synchronous request. It consumes certain performance. But it must be a synchronous request because it needs to receive the result of calling the method.
  6. Count: Times. Every 2 minutes, Provoider and Consumer automatically send the number of visits to the Monitor. The Monitor performs statistics.

6. What protocols does Dubbo support?

①. Dubbo Agreement (Official Recommendation Agreement)

  • Advantages: Use NIO to reuse a single long connection, and use the thread pool to process requests concurrently, reduce handshake and increase concurrency efficiency, and have better performance (recommended)
  • Disadvantages: problems may occur when uploading large files (do not use Dubbo file upload)

②. RMI (Remote Method Invocation) protocol

  • Advantages: JDK's own capabilities. Interoperable with native RMI, based on TCP protocol
  • Disadvantages: occasionally the connection fails.

③. Hessian agreement

  • Advantages: Interoperable with native Hessian, based on HTTP protocol
  • Disadvantages: need Hessian.jar support, Http short connection is expensive

7. What are the registration centers supported by Dubbo?

①. Zookeeper (Official recommendation)

  • Advantages: Support distributed. Many peripheral products.
  • Disadvantages: Limited by the stability of Zookeeper software. Zookeeper special distributed auxiliary software, stability is better

②. Multicast

  • Advantages: Decentralization, no need to install software separately.
  • Disadvantages: Provider, Consumer and Registry cannot cross computer rooms (routing)

③. Redis

  • Advantages: support clusters, high performance
  • Disadvantages: server time synchronization is required. Otherwise, cluster failure may occur.

④. Simple

  • Advantages: Standard RPC service. No compatibility issues
  • Disadvantages: Does not support clusters.

8. Dubbo service load balancing strategy?

①. l Random LoadBalance

Random, set random probability by weight. The probability of collision on a cross-section is high, but the larger the amount of calls, the more even the distribution, and the more even the weight is used according to the probability, which is beneficial to dynamically adjusting the provider weight. (Weight can be configured in Dubbo control console)

②. l RoundRobin LoadBalance

Round robin, the round robin ratio is set according to the weight after the convention. There is a problem of accumulating requests from slow providers. For example, the second machine is slow but not hung up. When the request is transferred to the second machine, it is stuck there. Over time, all requests are stuck in the second machine.

③. l LeastActive LoadBalance

The minimum number of active calls, the same active number is random, and the active number refers to the count difference before and after the call. The slower provider receives fewer requests, because the slower the provider will have a greater difference in counts before and after the call.

④. l ConsistentHash LoadBalance

Consistent Hash, requests with the same parameters are always sent to the same provider. When a certain provider hangs up, the request originally sent to that provider will be spread to other providers based on the virtual node without causing drastic changes. By default, only the first parameter Hash, if you want to modify, please configure

9. What are the core configurations of Dubbo? What protocol does Dubbo recommend?

核心配置有 dubbo:service/ dubbo:reference/ dubbo:protocol/ dubbo:registry/ dubbo:application/ dubbo:provider/ dubbo:consumer/ dubbo:method/

The Dubbo protocol is used by default.

10. The difference between dubbo registration center and direct connection

In the development and testing environment, it is often necessary to bypass the registry and only test the designated service provider. At this time, point-to-point direct connection or point-to-point direct connection may be required. The service interface will be used as the unit and the provider list of the registry is ignored. The registry, dynamically registering and discovering services, makes the location of the service transparent, and achieves soft load balancing and Failover by obtaining the service provider address list on the consumer side, and the registry returns the service provider address list to the consumer, if there are changes , The registry will push the change data to consumers based on the long connection. The service consumer, based on the soft load balancing algorithm, selects one provider to call from the provider address list, and if the call fails, selects another to call. The registry is responsible for the registration and search of the service address, which is equivalent to a directory service. Service providers and consumers only interact with the registry at startup. The registry does not forward the request. The service consumer obtains the service provider address list from the registry, and Directly call the provider according to the load algorithm, the registry, the service provider, and the service consumer are all persistent connections, except for the monitoring center. The registry perceives the existence of the service provider through the persistent connection, and the service provider is down and registered The center will immediately push the event to notify the consumer that the registry and monitoring center are down, and will not affect the providers and consumers that are already running. The consumer caches the provider list locally. The registry and the monitoring center are optional. Service consumption The person can directly connect to the service provider.

11. Dubbo communication protocol Why can't Dubbo protocol transmit large packets

Because the Dubbo protocol uses a single long connection, if the packet size of each request is 500KByte, assuming that the network is a gigabit network card (1024Mbit=128MByte), each connection may have a maximum of 7MByte (different environments may be different, for reference),

  • The maximum TPS (transactions per second) of a single service provider is: 128MByte / 500KByte = 262.
  • The maximum TPS (transactions processed per second) for a single consumer to call a single service provider is: 7MByte / 500KByte = 14.

If it is acceptable, consider using it, otherwise the network will become a bottleneck.

12. Dubbo communication protocol Why does Dubbo protocol require more consumers than providers?

Because the Dubbo protocol uses a single long connection, assuming that the network is a gigabit network card (1024Mbit=128MByte), according to the test experience data, each connection can only fill up to 7MByte (different environments may be different, for reference), theoretically 1 service The provider needs 20 service consumers to fill the network card.

13. Dubbo communication protocol Why does Dubbo protocol adopt asynchronous single long connection

Because the current status of the service is mostly that there are few service providers, usually only a few machines, and many consumers of the service, the entire website may be accessing the service. For example, Morgan’s provider has only 6 providers, but there are hundreds of consumers. There are 150 million calls per day. If the conventional Hessian service is used, the service provider is easily overwhelmed. Through a single connection, it is ensured that a single consumer will not crush the provider, long connections, and reduce connection handshake verification. And use asynchronous IO, reuse thread pool to prevent C10K problems.

14. Dubbo communication protocol Dubbo protocol scope and application scenarios

①. Dubbo Agreement

  • Scope of application: The incoming and outgoing parameter data packets are small (recommended to be less than 100K), there are more consumers than providers, and a single consumer cannot fill the providers. Try not to use the dubbo protocol to transfer large files or large strings.
  • Applicable scenarios: call conventional remote service methods

Supplement to the dubbo agreement:

  • Number of connections: single connection
  • Connection mode: long connection
  • Transmission protocol: TCP
  • Transmission method: NIO asynchronous transmission
  • Serialization: Hessian binary serialization

②. RMI protocol

The RMI protocol is implemented using JDK standard Java.rmi.*, using blocking short connections and JDK standard serialization, and Java standard remote calling protocol.

  • Number of connections: multiple connections
  • Connection mode: short connection
  • Transmission protocol: TCP
  • Transmission method: synchronous transmission
  • Serialization: Java standard binary serialization
  • Scope of application: the incoming and outgoing parameter data packet sizes are mixed, the number of consumers and providers is similar, and files can be transferred.
  • Applicable scenarios: conventional remote service method calls, interoperability with native RMI services

③. Hessian agreement

The Hessian protocol is used to integrate Hessian's services. The bottom layer of Hessian uses Http communication and uses Servlet to expose services. Dubbo embeds Jetty as a server by default; it is based on Hessian's remote call protocol.

  • Number of connections: multiple connections
  • Connection mode: short connection
  • Transmission protocol: HTTP
  • Transmission method: synchronous transmission
  • Serialization: Hessian binary serialization
  • Scope of application: The incoming and outgoing parameter data packets are larger, the number of providers is larger than that of consumers, and the providers are under greater pressure, and files can be transferred.
  • Applicable scenarios: page transfer, file transfer, or interoperability with native hessian services

④. http

Implemented by Spring's HttpInvoker; remote invocation protocol based on Http form.

  • Number of connections: multiple connections
  • Connection mode: short connection
  • Transmission protocol: HTTP
  • Transmission method: synchronous transmission
  • Serialization: Form serialization (JSON)
  • Scope of application: Incoming and outgoing parameter data packets are mixed in size, there are more providers than consumers, which can be viewed by a browser, and parameters can be passed in via forms or URLs. File upload is not currently supported.
  • Applicable scenarios: Services that need to be used by applications and browser JS at the same time.

⑤. Webservice

Implementation of Frontend-simple and Transports-http based on CXF; remote call protocol based on WebService.

  • Number of connections: multiple connections
  • Connection mode: short connection
  • Transmission protocol: HTTP
  • Transmission method: synchronous transmission
  • Serialization: SOAP text serialization
  • Applicable scenarios: system integration, cross-language call.

⑥. Thrif

Thrift is an RPC framework donated by Facebook to Apache. The current thrift protocol supported by dubbo is an extension of the native thrift protocol. Some additional header information is added to the native protocol, such as service name, magic number, etc.

 

This is the end of this about article!

 

The answers to the above interview questions are organized into document notes. I also sorted out some interview materials & the latest interview questions collected by some big companies in 2020 (all organized into documents, a small part of the screenshots), if necessary, you can  click to enter to view the materials .

 

Pay attention, don't get lost! If this article is helpful to you, don't forget to like and support!

Guess you like

Origin blog.csdn.net/SQY0809/article/details/108710247