In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "A software architecture that can be flexibly choreographed under a shared multithreaded scenario". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. let's study and learn a flexible software architecture under shared multithreaded scenarios.
1 A basic software running structure diagram
In the picture above
Main function in the main thread, child threads 1 and 2 are used to process tasks, and tasks are stored in the task queue
Each task needs two stages to complete, first processed by stage 1, and then processed by stage 2.
Stage 1 requires two functions, which are function An and function B.
Stage 2 requires a function processing, that is, function C.
2 how are functions and queues deployed to different threads?
In the final analysis, there are some basic functions running on each thread, and we can divide the functions that implement a function into a set of functions. In this example, function set 1 runs on child thread 1, and function set 3 runs on child thread 2.
Binding diagrams for threads, function sets, and task queues
When a function on a thread fetches a task from the task queue for processing, we need to make the following clear:
The same task queue can be scheduled by multiple threads
Multiple threads can schedule the same task queue
Different sets of functions can be deployed on the same thread
The same set of functions can also be deployed on different threads
The specific binding relationships of threads, function sets, and task queues can be flexibly written in configuration files, such as json, yaml, and so on. After the process starts, the resource is deployed by loading the configuration file. Why can there be multiple task queues on a thread? Because there can be different types of task queues, such as system tasks, user services and so on.
3 how to schedule functions on threads?
In the actual process of running the business thread, we will only see one function after another, so how to control the order in which the functions are executed? One of the simplest solutions is the state machine. Each time a thread executes a loop, it starts in the initial state, passes through the intermediate state, and ends in the final state. When the task reaches each state, the corresponding action processing will be carried out (that is, corresponding to an ordered set of functions). According to the result of the task processing, the next state that needs to jump is selected until the final state is encountered and the current task processing is completed. Next, take a task from the task queue and schedule it round robin.
State machine round robin task scheduling
After the 4 thread is up, which set of functions will actually run?
As mentioned earlier, the deployment framework specifies which sets of functions need to be run on each thread. However, when the thread is in practice, we schedule according to the state machine, and the state machine specifies what actions need to be performed for each state (that is, the set of functions). So are we going to execute the set of functions defined in the deployment framework or the corresponding set of functions in the state machine? The answer, of course, is the corresponding set of functions in the state machine.
Thank you for your reading. the above is the content of "sharing a flexible choreographed software architecture in a multithreaded scenario". After the study of this article, I believe you have a deeper understanding of the problem of sharing a flexible choreographed software architecture in a multithreaded scenario, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.