What is Microkernel Architecture Design
What is Microkernel Architecture Design.As a Java programmer, I believe that all students have heard of microkernel architecture design and have their own understanding. So how did the microkernel come about? What role does the microkernel play in the design of the operating system kernel? This article interprets the microkernel architecture design from the perspective of plug-in architecture, and shares its reference significance for microservice design through the comparison of microkernel architecture and microservice architecture .
What is Microkernel Architecture Design.What is Microkernel Architecture Design.The design of microkernel architecture is hot now. It sounds like it is related to the operating system kernel. As a Java programmer, the operating system kernel is so far away that it seems to have nothing to do with us. But if I say that the microkernel is actually a plug -in architecture, you will be puzzled, "You actually explain to a Java programmer what a plug-in architecture is? I use it every day, Eclipse, IntelliJ IDEA, OSGi, Spring Plugin, SPI, etc., which is not a plug-in architecture. Some of my projects are also designed with plug-ins, such as using plug-ins to implement process control customization, etc." But don't worry, even the technology we use every day, and most people know, if we can explain it more clearly, and can find some problems in it, make some optimizations to help the future architecture design , wouldn't it be better for most people to benefit in their day-to-day design and development. Now let's talk about microkernel architecture design.
What is Microkernel Architecture Design.An operating system kernel designed by a microkernel
Microkernel design is actually a plug-in system. We all know that the operating system kernel was born relatively early, so plug-in was first used in kernel design, so there is the name of microkernel design.
What is Microkernel Architecture Design.A microkernel is a kind of kernel: it only completes the functions that the kernel has to complete, including clock interruption, process creation and destruction, process scheduling, inter-process communication, while others such as file systems, memory management, device drivers, etc. are used as System processes are placed in user space. To put it bluntly, the microkernel is relative to the macrokernel. Linux is a typical macrokernel. In addition to clock interruption, process creation and destruction, process scheduling, and inter-process communication, other file systems, memory management, input and output. , Device driver management requires the kernel to complete.
What is Microkernel Architecture Design.That is to say, the microkernel is relative to the macrokernel. The macrokernel is a low-level program with very many functions, which is the Monolith we are talking about now. It does a lot of things, and it is not pluggable. Modifying some small functions will involve recompilation of the entire program. For example, a small bug in a function may cause problems in the entire kernel. This is why many people refer to Linux as a monolithic OS. The microkernel is only responsible for the most core functions, and other functions are added in the form of plug-ins through user - mode independent processes, and then the microkernel is responsible for process management, scheduling and communication between processes, so as to complete the functions required by the entire kernel. Basically, there is a problem with a function, but the function exists as an independent process, and it will not affect other processes and cause the kernel to be unavailable . At most, a certain function of the kernel is unavailable now.
A microkernel is a program segment running at the highest level, which can perform some functions that a user -mode program cannot. The micro-kernel coordinates the cooperation between various system processes through inter-process communication, which requires system calls, and the system calls need to switch the stack and protect the process site, which is time-consuming; while the macro-kernel completes each module through simple function calls. Therefore, in theory, the macro kernel is more efficient than the micro kernel. This is the same as the architecture design of microservices . After we divide the Monolith application into multiple small applications , the design of the system becomes more complicated. It used to be called internal functions of the application, but now it involves network communication, timeout and other issues, and at the same time Response time will be stretched.
has a general understanding of the microkernel and the macrokernel , and it seems that each has its own merits. But one of the biggest problems with the macro kernel is to customize and maintain Chen Ben. Nowadays, there are more and more mobile devices and IoT devices. It is a very complicated thing to adapt a huge and complex kernel to a certain device. If it is very simple, then adapt the Linux kernel to the Android kernel. , and even in-vehicle systems such as Tesla, basically everyone can do it.
Therefore, we need a microkernel architecture design, which is easy to customize, and is very small, which can realize hot replacement or online update of functions, etc. This is the core requirement proposed by the microkernel. However, the microkernel has a problem of operating efficiency, so between the microkernel and the macrokernel , there is the Hybrid kernel, mainly to have the flexibility of the microkernel, and at the same time have the performance of the macrokernel at key points. Microkernel design does have an efficiency problem in theory, but with chip design, hardware performance improvement, etc., this aspect may have been greatly improved, and it is no longer the most critical issue.
In general, the kernel design has three forms, as follows:
What is Microkernel Architecture Design.Two plug-in (Plug-in) architecture design
The role of the microkernel in the design of the operating system kernel has been discussed above. Next, we will discuss the more general plug-in architecture design. After all, everyone understands the word.
The plug-in architecture is very simple, with two core components: Core System and Plug -in component. Core System is responsible for managing various plug-ins. Of course, Core System also includes some important functions, such as plug-in registration management, plug-in life cycle management, communication between plug-ins, and dynamic replacement of plug-ins. The overall structure is as follow
The plug-in architecture is very helpful for the design of the microservice architecture. Considering the isolation, the plug-in may run as an independent process. If these processes are extended to the network and distributed on many servers, this is the prototype of the microservice architecture . , so students who know the microkernel are disdainful to discuss the microservice architecture with you. I believe you also understand that, in addition to the traditional contempt chain factor of IT, this is indeed the case in principle.
Back to the microservice architecture design scenario, we rename the Plug-in component to Service, which is similar to the service in the microkernel design. At this time, the microservice and the microkernel are almost the same, both involving service registration, Manage communications between services, etc. Then let's take a look at how the microkernel solves the communication problem between services?
The following is from Wikipedia:
Because all service trips run in different address spaces, in a microkernel architecture, function calls cannot be made directly like a macrokernel. Under the micro-core architecture, an inter-process communication mechanism should be created to allow service processes to exchange messages with each other, call each other's services, and complete synchronization through the message passing mechanism. The use of master-slave architecture makes it have special advantages in distributed systems, because the same set of inter-process communication mechanisms can be used between remote systems and local processes.
That is to say, it adopts a message-based inter-process communication mechanism. The message is the simplest. There are only two interfaces: send and receive. The message is sent out, and then it waits for the message to be received, and then the message can be sent after processing. Everyone here should also know that this is asynchronous. Going back to the plug-in architecture design, the Plug-in component design includes interaction specifications, that is, the interface for communicating with the outside world. If it is based on message communication, it is the send and receive interfaces, which can be said to be very simple.
What is Microkernel Architecture Design.But there is still a problem here, that is inter-process communication. You may ask, what's in doubt about this is that the two processes send messages to each other. But there is a biggest question here, that is, is there a third party involved in inter-process communication? As shown below:
Of course, in the kernel design of the operating system, it must be forwarded through the kernel, which is the bus architecture we understand, and the kernel is responsible for coordinating the communication between various processes. Everyone can understand this. If process A sends directly to another process B, it must know the corresponding memory address. The service in the microkernel can be replaced at any time. If the service is unavailable or replaced, it is necessary to notify and Is it too complicated for other processes of its communication? As mentioned just now, there are only send and receive interfaces, and there are no other interfaces for notifying offline and service unavailability . In the design of the microkernel, the process must send a message to the kernel through the bus structure, and then the kernel sends it to the corresponding process, such a bus design. In fact, many applications use the structure of EventBus when decoupling Plug-in components, which is actually the design mechanism of the bus.
Why do mother-in-law say this? Because it is very important. Distributed process communication is the core of microservices . The service-to-service communication we understand is that service A starts the listening port, service B will establish a connection with service A, and then the two can communicate. This method is different from the bus architecture design in which the kernel is responsible for message reception and forwarding in the microkernel design. For example, when using HTTP, HSF and other communication protocols, it is equivalent to the kernel telling the respective addresses of both parties of the communication, and then they can communicate with each other. Then there is no Kernel, and no bus structure design is used. This is the traditional service discovery mechanism.
But there is another mode, which is a completely transparent plug-in communication mechanism, as shown below:
What is Microkernel Architecture Design.Plug-in components, that is, services in the microservice architecture, cannot communicate directly, but need to be forwarded by the Core System. The advantage of this is the same as the microkernel architecture. Plugins are not directly connected to each other and are very transparent to each other. For example, after service A goes offline, there is no need to notify other services at all; when service A is replaced, there is no need to notify other services; Service A goes from data center 1 to data center 2 without notifying other services; even if the network between service N and service A is not interoperable, they can communicate with each other.
There's a problem here: a performance issue. We all know that between two points, the straight line segment is the shortest. Why go around to the Core System? This is the point of contention between microkernels and macrokernels , using function calls is very fast, and inter-process message communication is very slow, but the benefits of this communication mechanism through an intermediary are also very obvious. So how to improve the performance of this bus-based communication? Of course, for example, if you choose a high-performance binary protocol, you do not need a text protocol such as HTTP 1.1; using the Zero Copy mechanism, you can quickly forward network packets; good network hardware, such as RDMA; good protocols, such as UDP-based QUIC, etc. To sum up, like the microkernel, the performance of this microservice communication can be improved. Of course, if you really can't stand this kind of performance, in key scenarios, you can use the Hybrid mode and mix in some designs for direct communication between services, but it can only be used in scenarios with extreme performance.
In addition, the plug- in components in the plug-in architecture are various, and the communication mechanisms are also different. Some are RPC, some are Pub/Sub, some do not require ACK (such as Beacon interface), and some It is two-way communication, etc. Of course, you can choose a different communication protocol, but there is a problem here, that is, the Core System needs to understand this protocol before it can perform message routing. At this time, the Core System needs to write a large number of Adapters to parse these protocols. For example, Envoy includes various filters to support different protocols, such as HTTP, MySQL, ZooKeeper , etc., but the Core System will become very complicated and unstable.
In addition, you can choose a general protocol. The Core System only supports this protocol, and each plug-in communicates based on this protocol. As for how the service communicates with other external systems, such as database, github integration, etc., these Core Systems do not care. , that's just something inside the Service. At present, the more common protocol is gRPC , which is used internally by K8s. In addition, Dapr also uses gRPC protocol for service integration, because the communication model provided by gRPC can basically meet most
communication scenarios. Of course, the other is RSocket , which provides a richer communication model and is also suitable for inter-service communication scenarios such as Core System. Compared with gRPC , RSocket can run on various transport layers, such as TCP, UDP, WebSocket, RDMA, etc. On the contrary, gRPC can only run on HTTP 2 at present.
What is Microkernel Architecture Design.The extension of the three-service communication.
As mentioned earlier, it is best to use the Core System designed by the plug-in architecture as the route for message communication between services. If this is the case, a Broker mode will be generated, and of course it may also be an Agent. Everyone here will definitely think of Service Mesh, yes. Of course, you can choose the Agent Sidecar mode or the centralized Broker mode. The functions of both are the same, but the processing methods are different. Based on the service registration and discovery mechanism, the agent finds the agent of the other party's service, and then communicates between the two agents, which only saves the cost of calling between services. However, the Broker is centralized. Everyone sends and receives messages to the Broker. It does not involve the service registration discovery mechanism, nor does it involve the push of service meta information , which is the bus structure.
Many students will ask, when the load of the service instance is too high, how does the Broker achieve dynamic expansion? The Broker will provide you with data, such as a service instance QPS. As for whether to expand, you only need to write a service, collect data from the Broker, and after analysis, call the K8s API to expand the capacity. The Broker does not load these business functions, it Only very necessary functions will be added, which is the same as the Core System design.
Back to the flexibility of the plug-in architecture, if there is a KV storage plug-in in the system, you can save the KV data as long as you follow the message format or communication interface. But you don't care too much about Redis storage, Tair storage, or KV service in the cloud, which provides a good foundation for service standardization and replaceability, which is very helpful for applications on the cloud or cloud native . Large, the whole system has very great flexibility.
What I am doing now is the architecture design of the bus based on this Broker. In the RSocket Broker, the microkernel architecture is also designed, of course, it may not be the best. The core of RSocket Broker is to manage registered services, routing management, data collection, etc., without adding too many functions. Just like the design concept of Core System, only necessary functions are added. If you want to expand more functions of the entire system, such as sending text messages, sending emails, connecting to cloud storage services, etc., you need to write a Service, then connect with the broker, and then receive messages from the broker, and send them after processing. (send) to Broker and that's it. The overall structure is as follows:
What is Microkernel Architecture Design.Four Summary
In fact, there are a lot of books about the introduction of the microkernel, not to mention the books on the operating system. The other two books are also very good, and they are also very helpful for the design of general architecture, especially in the scenario of microservices . I also refer to this book. The two who wrote this art
What is Microkernel Architecture Design.The microkernel architecture design has a very good reference for the design of microservices, but a very big problem with microservices is the division of service boundaries. Compared with the operating system, it has been developed for decades, and it is very stable, and the function division is very easy. The microservice architecture serves the business. Although the business it faces may have existed for hundreds of years, the software, digitization and processization have not been around for many years. In addition to the complexity of the real business, there are also various compromises. I personally think that Microservices architectures are a bit more complicated.
Knowledge Base Team
Knowledge Base Team
Knowledge Base Team
Knowledge Base Team
Explore More Special Offers
50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00