When creating a large system, multi-pipeline is an important aspect that requires attention, especially in terms of efficiency (how fast does the system run ?) And performance (does the system work normally ?) When you create a balance. The use of multiple programming procedures can greatly improve the system performance.
What is a Failover process?
Each running on the systemProgramIs a progress. Each progress contains one or more engineering processes. The progress may also be the dynamic execution of the whole program or some programs. A program is a set of commands, or a special segment of the program. It can be set up in the program. It can also be understood as the context of the runtime. Therefore, the processing is basically a process of batch computing, which allows you to perform multiple tasks in a single program. Generally, the operating system checks the response and response of multiple programming procedures.
What is multi-processing?
Multi-programming is to make multiple concurrent jobs to complete multiple tasks, so as to improve the efficiency of the system. The execution process is implemented when multiple tasks need to be completed at the same time.
There are the following points to use the Failover process:
· Using the processing procedure, you can place the tasks in the program for a long period of time to the backend for handling.
· The UI can be even more attractive. For example, you can use a notebook to handle a certain event on a pay-as-you-go basis, you can define an increment to indicate the progress of processing.
· Program operation speed may be accelerated
· In some of the waiting tasks, such as using Website access, file transfer, and online delivery data, the process is better than swimming. In this case, we can release some valuable resources such as internal storage and usage.
There are many other advantages of using multi-programming, which are not clearly stated here.
Background of some failover Models
We can repeat some common models in Win32 environments.
· Single-process model
In this route model, only one route can be created, and the rest of the route must be completed before the current schedule. The deficiency of this model is that it takes a long time for the system to complete a small task.
· Two-way programming model (single-process multi-dimensional model Sta)
In this model, a program may contain multiple response rows. Here, each route is divided into a single route in the process. Each progress can contain multiple regions and share the data of multiple regions. The program schedules the maximum time of each route. All requests are serialized by means of the Windows message queue. This ensures that only one listener can be asked at a time, therefore, there is only one simple process that can be used to obtain the rows at a certain moment. This model is better than a single-process model. It can handle multiple tasks requested by the buyer at the same time rather than simply using the buyer. However, its performance is not very good, because it uses a serialized continuous programming model, and tasks are processed one by one.
· Multi-process scheduler model (free-process scheduler Model)
The multi-process workflow model (MTA) has only one worker in each progress, rather than multiple workers. This single thread Controls Multiple Threads rather than a single thread. In this case, the Message Queue column is not required because all the threads are part of the same queue and can be shared. Such a program is faster than a single-process model and a Stas, because it reduces the complexity of the system, therefore, we can reduce the system idle time. These applications are generally more suitable than other applications, because programmers must provide program synchronization to ensure that the program will not be issued and request the same resource, this leads to the emergence of emotional conditions. It is necessary to provide a messaging system. However, this may lead to the death of the system.
How does multi-programming work in. Net?
In terms of quality and architecture,. Net is a multi-programming environment. There are two main multi-programming methods. net advocate: Use threadstart to start your own progress directly (using threadpool. queueuserworkitem) or interlace (such as stream. beginread, or ininvoke) uses threadpool class. Generally, you can "manually" Create a new route for long-time tasks, in addition, for short-term operations, especially those that often need to start, the Progress pool is a very good choice. The progress pool can run multiple tasks at the same time, or use frameworks. For the lack of information sources that need to be synchronized, it can limit a certain period of time to allow only one remote access resource. This kind of situation can be deemed as a failure mechanism for the program. The base type of the program is system. threading. All threads are managed through CLI.
· Creation of the Failover process:
Create a new thread object example. The component number of the thread accepts one parameter:
Thread dummythread = new thread (New threadstart (dummyfunction ));
· Failover process:
Run the program by using the start method in the threading namespace:
Dummythread. Start ();
· Integration process:
It is often the case that multiple programming threads need to be combined, that is, when a certain programming thread needs the end of another programming thread to complete its own tasks. False settings dummythread must wait for dummyprioritythread to complete their tasks. We only need to do this:
Dummyprioritythread. Join ();
· Stopovers:
The number of seconds for which the specified timeout period is stopped.
Dummyprioritythread. Sleep ();
· Abort the process:
If you need to abort the statement, you can use the following code:
Dummyprioritythread. Abort ();
· Synchronization
We often encounter situations where synchronization needs to be performed during the pipeline. The following Code provides some methods:
Using system; using system. Threading; namespace synchronizationthreadsexample {
Class synchronizationthreadsexample {
Private int counter = 0;
Static void main (){
Synchronizationthreadsexample ste = new synchronizationthreadsexample ();
Ste. threadfunction ();
}
Public void threadfunction (){
Thread dummythread = new thread (New threadstart (somefunction );
Dummythread. isbackground = true;
Dummythread. Name = "first thread ";
Dummythread. Start ();
Console. writeline ("started thread {0}", dummythread. Name );
Thread dummyprioritythread = new thread (New threadstart (somefunction ));
Dummyprioritythread. isbackground = true;
Dummyprioritythread. Name = "second thread ";
Dummyprioritythread. Start ();
Console. writeline ("started thread {0}", dummyprioritythread. Name );
Dummythread. Join ();
Dummyprioritythread. Join ();
}
Public void somefunction (){
Try {
While (counter <10 ){
Int tempcounter = counter;
Tempcounter ++;
Thread. Sleep (1 );
Counter = tempcounter;
Console. writeline ("thread {0}. somefunction: {1}", thread. currentthread. Name, counter );
}
}
Catch (threadinterruptedexception ex ){
Console. writeline ("exception in thread {0}", thread. currentthread. Name );
}
Finally {
Console. writeline ("thread {0} exiting.", thread. currentthread. Name );
}
}
}
}
· Interlock
C # provides a special kind called interlocked, that is, provides the implementation of the camera system. We can add the following generation to implement the camera system:
Interlocked. somefunction (ref counter );
· Use logging
In order to synchronize the domain names of the designated region, the following figure shows the fixed generation region:
Lock (this) {some statements ;}
· Use monitor
When you need to perform route management, we can use:
Monitor. Enter (this );
Other methods are also available for management, which will not be mentioned here.
Defects of failover
There are also some defects in the Failover process, which are listed below:
· If there are a large number of processing processes, it will affect the performance, because the operating system needs to switch between them;
· More memory tasks require more Memory Spaces
· Failover will bring more bugs to the program, so be careful when using it.
· If a program is terminated, the impact of the Program on its operation should be checked.
· Generally, the data share of the modeling model is shared across multiple programming cycles. a unified data system is required to replace the data share.