Writing in the front
Arrange some interview questions with Internet companies, these interview questions are often asked, also as a Java engineer need to master the knowledge, after all, the combination of theory and practice, is king, fragmentation, eat some knowledge every day, happy every day, if you have any help to you, remember the point attention and point oh.
Related articles
MyBatis (MyBatis) (ZooKeeper) (Dubbo) (Elasticsearch) (Redis) (MySQL) (Dubbo) Java concurrent programming interview questions (1)
Why Dubbo?
With the further development of servitization, there are more and more services, and the invocation and dependency between services are more and more complex. Service-oriented Architecture (SOA) has been born, and a series of corresponding technologies have been derived. A service framework that encapsulates behavior such as service provision, service invocation, connection processing, communication protocol, serialization, service discovery, service routing, and log output. Thus a service governance framework for distributed systems emerged, and Dubbo was born.
What are the layers of Dubbo’s overall architectural design?
Interface Service Layer
: This layer is related to business logic, and the corresponding interfaces and implementations are designed according to the services of provider and consumerConfiguration Layer (Config)
: External configuration interface, centered on ServiceConfig and ReferenceConfigService Proxy Layer
: service interface transparent proxy, which generates the service client Stub and server Skeleton. The ServiceProxy is centered on the ServiceProxy, and the extension interface is ProxyFactoryService Registry Layer
: Encapsulates the registration and discovery of service addresses, centering on service urls and extending interfaces to RegistryFactory, Registry, and RegistryServiceRouting Layer (Cluster)
: encapsulates routing and load balancing for multiple providers, and Bridges registries, invoker-centric, with extended interfaces asCluster, Directory, Router and LoadBlancce
Monitor Layer
: Monitors the number of RPC calls and call time. With Statistics as the center, the interfaces are MonitorFactory, Monitor, and MonitorServiceRemote Call Layer (Protocal)
: Encapsulates RPC calls with Invocation and Result centered and extends interfaces to Protocal, Invoker, and ExporterInformation Exchange Layer
: Encapsulates the request response mode, synchronous to asynchronous. Centered on Request and Response, the extended interface isExchanger, ExchangeChannel, ExchangeClient and ExchangeServer
Network Transport Layer
Abstract Mina and NetTY are unified interfaces centered on Message, and extended interfaces include Channel, Transporter, Client, Server, and CodecData Serialization Layer (Serialize)
: reusable tools with Serialization, ObjectInput, ObjectOutput, and ThreadPool extensions
What communication framework is used by default, and what other options are there?
The netty framework is also recommended by default, as is Mina.
Is the service invocation blocking?
It blocks by default and can be called asynchronously, if there is no return value. Dubbo is a non-blocking parallel invocation based on NIO. The client can complete the parallel invocation of multiple remote services without starting multithreading. Compared with multithreading, the overhead is relatively small.
What registry is commonly used? Is there any other option?
Zookeeper, Redis, Multicast, and Simple registration centers are recommended, but not recommended.
What serialization framework is used by default, and what else do you know?
Hessian serialization is recommended, as well as Duddo, FastJson, and Java serialization.
What is the mechanism by which service providers can implement fail-kick?
Service failure Kicks out temporary zooKeeper-based nodes.
How does the launch of the service not affect the old version?
Adopt multi-version development, do not affect the old version.
How to solve the problem of long service invocation chains?
You can combine zipkin for distributed service tracking.
What are the core configurations?
configuration | Configuration instructions |
---|---|
dubbo:service | Service configuration |
dubbo:reference | The reference configuration |
dubbo:protocol | Protocol configuration |
dubbo:application | Application configuration |
dubbo:module | The module configuration |
dubbo:registry | Registry Configuration |
dubbo:monitor | Monitoring Center Configuration |
dubbo:provider | Provider Configuration |
dubbo:consumer | Consumer allocation |
dubbo:method | A method configuration |
dubbo:argument | Parameter configuration |
What protocol does Dubbo recommend?
- Dubbo ://
- rmi://
- hessian://
- http://
- webservice://
- thrift://
- memcached://
- redis://
- rest://
Can a service be directly connected to multiple registrations of the same service?
You can directly connect to a service point-to-point by modifying the configuration, or directly connect to a service through Telnet.
Flowchart service registration and discovery?
How many options are there for Dubbo cluster fault tolerance?
Cluster fault tolerance scheme | instructions |
---|---|
Failover Cluster | Failure to automatically switch, automatically retry other servers (default) |
Failfast Cluster | A quick failure, an immediate error, and only one call |
Failsafe Cluster | Fail-safe, ignore exceptions when they occur |
Failback Cluster | Failed automatic recovery, record failed requests, scheduled resend |
Forking Cluster | Call multiple servers in parallel and return if one succeeds |
Broadcast Cluster | The broadcast calls all the providers one by one, and an error is reported on any one of them |
Dubbo service degraded, failed to retry what to do?
Mock =”return NULL “can be set in dubbo: Reference. You can also change the mock value to true, and then implement a mock class in the same path as the interface with the “interface name + mock” suffix. Then implement your own degradation logic in the Mock class
What are some of the problems with Dubbo?
The corresponding service cannot be found in the registry. Check if the service implementation class has added the @service annotation and cannot connect to the registry. Check if the corresponding test IP in the configuration file is correct
How does Dubbo Monitor work?
The Consumer goes through the Filter chain before making the call. When receiving a request, the provider goes through the Filter chain first and then performs actual business logic processing. By default, both consumer and provider filter chains have MonitorFilters.
- MonitorFilter sends data to the DubboMonitor
- DubboMonitor stores aggregated data (statistics within 1 minute by default) temporarily
ConcurrentMap<Statistics, AtomicReference> statisticsMap
, and then use a single thread with three threads (thread name: The thread pool of DubboMonitorSendTimer calls SimpleMonitorService every 1min to iterate over statisticsMap data. Reset the AtomicReference of the current Statistics - SimpleMonitorService loads the aggregated data into BlockingQueue Queue (column uppercase 100000)
- SimpleMonitorService using a background thread (thread called: DubboMonitorAsyncWriteLogThread) will be written to the file of data in the queue (this thread to write in the form of infinite loop)
- SimpleMonitorService also uses a thread pool of one thread (thread name: DubboMonitorTimer) to graph the statistics in the file every 5 minutes
What design patterns does Dubbo use?
Dubbo framework uses a variety of design patterns during initialization and communication, which can flexibly control functions such as class loading and weight limit control.
- Factory mode: Provider invokes the Export method of ServiceConfig when exporting the service. There is a field in ServiceConfig:
private static final Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtensi on(a);
Copy the code
There’s a lot of this code in Dubbo. This is also a factory pattern, except that the implementation class is retrieved using the JDK SPI mechanism. The advantage of this implementation is that it is extensible, and to extend the implementation, you can simply add a file to the classpath, with zero code intrusion. In addition, Adaptive implementation, like the one above, can dynamically decide which implementation to call when calling, but because this implementation uses dynamic proxy, it will cause trouble in code debugging, and the implementation class actually called needs to be analyzed.
- Decorator pattern: Dubbo makes heavy use of decorator pattern in both startup and invocation phases. In the case of a Provider, this is done in the ProtocolFilterWrapper buildInvokerChain, which implements a Filter that has group= Provider in its annotations. In order, the last call order is:
EchoFilter -> ClassLoaderFilter -> GenericFilter -> ContextFilter -> ExecuteLimitFilter -> TraceFilter -> TimeoutFilter -> MonitorFilter -> ExceptionFilter
Copy the code
More specifically, it’s a mix of decorator and chain of responsibility patterns. For example, EchoFilter is used to determine if it is an echo test request, and if it is, it returns the content directly, which is a chain of responsibility. Something like ClassLoaderFilter simply adds functionality to the main function, changing the ClassLoader of the current thread, which is a typical decorator pattern.
- Observer mode: When Dubbo’s Provider is started, it interacts with the registry to register its own service and then subscribe to its own service. When Dubbo’s Provider is subscribed, the Observer mode is used and a Listener is started. The registry checks for service updates every 5 seconds and sends a Notify message to the service provider. After receiving the notify message, the provider runs the notify method of NotifyListener and executes the listener method.
- Dynamic proxy mode: The Adaptive implementation of Dubbo’s ExtensionLoader class extending JDK SPI is typical of dynamic proxy implementations. Dubbo needs to control the implementation class flexibly, that is, in the call phase, dynamically decide which implementation class to call according to the parameters, so the method of using the proxy class can achieve flexible call. The code that generates the proxy class is ExtensionLoader
createAdaptiveExtensionClassCode
Methods. The main logic of the proxy class is to get the value of the specified parameter in the URL parameter as the key to get the implementation class.
How is the Dubbo configuration file loaded into Spring?
When the Spring container is started, it reads some of Spring’s default schemas as well as Dubbo’s custom schemas. Each schema has its own NamespaceHandler. NamespaceHandler uses BeanDefinitionParser to parse configuration information and convert it to loaded bean objects!
What is the difference between Dubbo SPI and Java SPI?
-
The STANDARD SPI in the JDK loads all extension implementations at once. If there are extensions that are time consuming but are not used, it is a waste of resources. So it’s not realistic to just want to load one implementation
-
DUBBO SPI
- Extensions to Dubbo do not require any changes to Dubbo’s source code
- Lazy loading allows you to load only as many extensions as you want at a time.
- Added support for extension points IOC and AOP, where an extension point can be directly setter injected into other extension points.
- Dubbo’s extension mechanism works well with third-party IoC containers and supports Spring beans by default.
Does Dubbo support distributed transactions?
- Currently not supported and can be implemented with the TCC-Transaction framework
- Tcc-transaction is an open source TCC compensatory distributed transaction framework
- Git address: github.com/changmingxi…
- Tcc-transaction avoids its own intrusion into business code through Dubbo’s implicit parameter passing capability.
Can Dubbo cache the results?
To improve the speed of data access. Dubbo provides declarative caching to reduce user caching efforts
<dubbo:reference cache="true" />
Copy the code
Cache =”true” cache=”true”
How can the service be compatible with the old version?
You can transition to version, where multiple services of different versions are registered in the registry, and services of different versions are not referenced to each other. This is somewhat similar to the concept of service grouping.
What packages must Dubbo rely on?
Dubbo must rely on JDK, otherwise optional.
What does the Dubbo Telnet command do?
After dubbo service is released, we can use Telnet command to debug and manage. Dubbo2.0.5 or later services provide ports that support Telnet commands
- Connection service:
Telnet localhost 20880 // Type Enter to enter Dubbo command mode
. - Viewing the Service List
dubbo>ls com.test.TestService
dubbo>ls com.test.TestService
create
delete
query
Copy the code
-
ls (list services and methods)
- Ls: displays the service list.
- Ls -l: displays the service details list.
- Ls XxxService: displays the service method list.
- Ls -l XxxService: displays the service method details list.
Is Dubbo support service degraded?
Set mock=”return NULL “via dubbo: Reference. You can also change the mock value to true, and then implement a mock class in the same path as the interface, using the “interface name + mock” suffix. Then implement your own degradation logic in the Mock class
How does Dubbo stop gracefully?
Dubbo is implemented with JDK ShutdownHook for graceful shutdown, so if you use kill -9 PID or other forced shutdown commands, graceful shutdown will not be performed, only if you pass kill PID.
The difference between a Dubbo and a Dubbox?
Dubbox is an extension project made by Dangdang based on Dubbo after Dubbo stopped maintenance, such as adding Restful service calls and updating open source components.
What’s the difference between Dubbo and Spring Cloud?
Take a look at what Spring Cloud and Dubbo offer in terms of the various aspects of microservices architecture.
Dubbo | Spring Cloud | |
---|---|---|
Service Registry | Zookeeper | Spring Cloud Netflix Eureka |
Service invocation mode | RPC | REST API |
The service gateway | There is no | Spring Cloud Netflix Zuul |
The circuit breaker | imperfect | Spring Cloud Netflix Hystrix |
Distributed configuration | There is no | Spring Cloud Config |
Service tracking | There is no | Spring Cloud Sleuth |
The message bus | There is no | Spring Cloud Bus |
The data flow | There is no | Spring Cloud Stream |
The batch task | There is no | Spring Cloud Task |
… | … | … |
Using Dubbo to build a microservice architecture is like building a computer. We have a lot of freedom in the process, but the end result is very likely to be broken because of a poor memory quality, which is always not a problem if you are an expert. Spring Cloud, on the other hand, is like a branded machine. Under the integration of Spring Source, a lot of compatibility tests are done to ensure a higher stability of the machine. However, if you want to use something other than the original components, you need to have a sufficient understanding of its foundation.
What other distributed frameworks do you know about?
There’s Spring Cloud for Spring, Thrift for Facebook, Finagle for Twitter