A business request processing method, system, electronic device and storage medium
By migrating the task to be executed by threads that preempt the mutex lock to other threads in the business request processing system, the thread blockage problem caused by multi-core CPUs due to preempt the lock is solved, and the response efficiency is improved.
Patent Information
- Application Number
- CN202411027966.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-30
- Publication Date
- 2024-12-24
- Estimated Expiration
- 2044-07-30
AI Technical Summary
When the number of service requests is large, the performance of the multi-core CPU is blocked by threads caused by preemption of mutexes, which limits the response efficiency of service requests.
In the business request processing system, the thread that seizes the target critical resource is used as the target thread, and the task it executes is moved to the target task chain, and other threads are used as thread being locked, and the task it is used to migrate is also moved to the task it is used to execute. Go to the target task chain to be executed, so that the target thread executes all tasks to be executed based on the target critical resource.
It reduces the release and preemption process of mutex locks, avoids thread blockage, and improves the response efficiency of business requests.
Smart Images

Figure CN118550675B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, system, electronic device and storage medium for processing a business request. Background Art
[0002] At present, with the widespread application of servers in all walks of life, the business scope carried by servers is getting larger and larger, and the number of business requests is growing rapidly. Therefore, how to make servers respond to business requests efficiently has become a hot research topic.
[0003] In the related art, a single service request is usually split into a number of tasks to be executed, so that these tasks to be executed are processed in parallel based on a multi-core CPU.
[0004] However, when the number of business requests is huge, along with the generation of a large number of small tasks to be executed, the threads corresponding to each task to be executed will seize the mutex lock to access critical resources, which will cause a large number of threads to be forced into a blocked state, limiting the performance of the multi-core CPU and reducing the response efficiency of business requests. Summary of the invention
[0005] The present application provides a business request processing method, system, electronic device and storage medium to solve the defects of related technologies such as reducing the response efficiency of business requests.
[0006] The first aspect of the present application provides a service request processing method, comprising:
[0007] When any thread in the business request processing system seizes the mutex lock of the target critical resource, the thread is used as the target thread;
[0008] Migrating the target task to be executed by the target thread to the target task chain to be executed;
[0009] The threads other than the target thread in the business request processing system are used as threads to be locked, and the target tasks to be executed that are requested to be executed by the threads to be locked are migrated to the target task chain to be executed, so that the target thread executes all the target tasks to be executed in the target task chain to be executed based on the target critical resources;
[0010] Among them, the target pending task requested to be executed by the target thread and the target pending task requested to be executed by the lock-grabbing thread are both pending tasks that need to access the target critical resource, and the request to be responded to is composed of multiple pending tasks.
[0011] In an optional implementation, migrating the target to-be-executed task requested to be executed by the target thread to a target to-be-executed task chain includes:
[0012] Accessing several task queues corresponding to the target thread;
[0013] Locating the to-be-executed tasks that need to access the target critical resource in each of the task queues, and using the to-be-executed tasks as the target to-be-executed tasks;
[0014] The target to-be-executed task is migrated to the end of the target to-be-executed task chain list, and a task count value of the target to-be-executed task chain is determined according to the number of the migrated target to-be-executed tasks.
[0015] In an optional implementation, the step of migrating the target task to be executed that is requested to be executed by the thread to be locked to the target task chain to be executed includes:
[0016] During the process of the target thread executing the target task to be executed at the head of the target task to be executed chain list, the target task to be executed requested to be executed by the lock-grabbing thread is migrated to the tail of the target task to be executed chain list;
[0017] Each time a target task to be executed is migrated to the end of the target task to be executed chain list, the task count value of the target task to be executed chain is increased by 1.
[0018] In an optional embodiment, the method further includes:
[0019] Every time the target thread completes the execution of a target task at the head of the target task chain list, the task count value of the target task chain is reduced by 1;
[0020] Determine whether the task count value of the target to-be-executed task chain is 0;
[0021] When it is determined that the task count value of the target to-be-executed task chain is not 0, the head pointer of the target to-be-executed task chain is incremented by 1 to execute the next target to-be-executed task in the target to-be-executed task chain.
[0022] In an optional embodiment, the method further includes:
[0023] When it is determined that the task count value of the target to-be-executed task chain is 0, the mutex lock of the target critical resource is released.
[0024] In an optional embodiment, the method further includes:
[0025] Selecting a task queue to be balanced from a plurality of task queues corresponding to the target thread;
[0026] Migrate several tasks to be balanced in the task queue to be balanced to the target task queue of the corresponding thread to be locked;
[0027] The types of tasks to be executed cached in the to-be-balanced task queue and the target task queue are the same.
[0028] In an optional implementation, the screening of the task queues to be balanced from the plurality of task queues corresponding to the target thread includes:
[0029] When the task queue corresponding to the target task to be executed is not empty, the task queue corresponding to the target task to be executed is used as the task queue to be balanced.
[0030] In an optional implementation, the screening of the task queues to be balanced from the plurality of task queues corresponding to the target thread includes:
[0031] Obtaining the task cache amount of each of the task queues corresponding to the target thread;
[0032] The task queue with the largest task cache amount is used as the task queue to be balanced.
[0033] In an optional implementation, the screening of the task queues to be balanced from the plurality of task queues corresponding to the target thread includes:
[0034] Obtaining the processor occupancy rate of the tasks to be executed in the task queue cache corresponding to the target thread;
[0035] The cached task queue with the highest processor occupancy rate of the tasks to be executed is used as the task queue to be balanced.
[0036] In an optional implementation, the step of migrating the plurality of tasks to be balanced in the task queue to be balanced to the target task queue of the thread to be locked includes:
[0037] Determine a balanced allocation strategy for the plurality of tasks to be balanced according to the number of target tasks to be executed that are migrated from each of the threads to be locked to the target task chain to be executed;
[0038] According to the balanced allocation strategy, the plurality of tasks to be balanced are migrated to the target task queue of the corresponding thread to be locked.
[0039] In an optional implementation, migrating the plurality of tasks to be balanced to the target task queue of the corresponding thread to be locked according to the balanced allocation strategy includes:
[0040] For any of the threads to be locked, a corresponding number of tasks to be balanced are migrated to the target task queue of the corresponding thread to be locked according to the migration ratio represented by the balanced allocation strategy.
[0041] A second aspect of the present application provides a service request processing device, including:
[0042] A preemption module, used to take any thread in the business request processing system as a target thread when the thread preempts the mutex lock of the target critical resource;
[0043] A migration module, used for migrating the target to-be-executed task requested to be executed by the target thread to a target to-be-executed task chain;
[0044] A processing module, used for treating threads other than the target thread in the business request processing system as threads to be locked, and migrating target tasks to be executed that are requested to be executed by the threads to be locked to the target task chain to be executed, so that the target thread executes all target tasks to be executed in the target task chain to be executed based on the target critical resources;
[0045] Among them, the target pending task requested to be executed by the target thread and the target pending task requested to be executed by the lock-grabbing thread are both pending tasks that need to access the target critical resource, and the request to be responded to is composed of multiple pending tasks.
[0046] The third aspect of the present application provides a service request processing system, comprising: a controller, a plurality of threads and a task queue, wherein the threads correspond one-to-one to the processing cores of the multi-core processor;
[0047] Each of the threads corresponds to a plurality of task queues, a request to be responded to is composed of a plurality of tasks to be executed, and a plurality of tasks to be executed of a single service to be responded to are cached in different task queues;
[0048] The controller processes the service request based on the method described in the first aspect and various possible designs of the first aspect.
[0049] A fourth aspect of the present application provides an electronic device, comprising: at least one processor and a memory;
[0050] The memory stores computer-executable instructions;
[0051] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the method described in the first aspect and various possible designs of the first aspect.
[0052] A fifth aspect of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions. When a processor executes the computer-executable instructions, the method described in the first aspect and various possible designs of the first aspect are implemented.
[0053] The sixth aspect of the present application provides a computer program product, including computer instructions, which are used to enable a computer to execute the method described in the first aspect and various possible designs of the first aspect.
[0054] The technical solution of this application has the following advantages:
[0055] The present application provides a business request processing method, system, electronic device and storage medium, the method comprising: when any thread in the business request processing system seizes the mutex lock of the target critical resource, the thread is used as the target thread; the target task to be executed requested to be executed by the target thread is migrated to the target task chain to be executed; the threads other than the target thread in the business request processing system are used as threads to be locked, and the target task to be executed requested to be executed by the thread to be locked is migrated to the target task chain to be executed, so that the target thread executes all the target tasks to be executed in the target task chain based on the target critical resource; wherein the target task to be executed requested to be executed by the target thread and the target task to be executed requested to be executed by the thread to be locked are both tasks to be executed that need to access the target critical resource, and the request to be responded to is composed of multiple tasks to be executed. The method provided by the above scheme reduces the release of the mutex lock and the generation of the preemption process by migrating the target task to be executed of the thread that has not seized the mutex lock to the target thread that has seized the mutex lock, so as to avoid thread blocking caused by seizing the lock, thereby improving the response efficiency of the business request. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the following is a brief introduction to the drawings required for use in the embodiments or the related technical descriptions. Obviously, the drawings described below are some embodiments of the present application, and a person skilled in the art can also obtain other drawings based on these drawings.
[0057] Figure 1 A flowchart of a method for processing a business request provided in an embodiment of the present application;
[0058] Figure 2 A schematic diagram of the structure of an exemplary service request processing system provided in an embodiment of the present application;
[0059] Figure 3 A schematic diagram of the structure of a service request processing device provided in an embodiment of the present application;
[0060] Figure 4 A schematic diagram of the structure of a service request processing system provided in an embodiment of the present application;
[0061] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
[0062] The above drawings have shown clear embodiments of the present application, which will be described in more detail below. These drawings and text descriptions are not intended to limit the scope of the present disclosure in any way, but to illustrate the concepts of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0063] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0064] In addition, the terms "first", "second", etc. are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. In the description of the following embodiments, the meaning of "multiple" is more than two, unless otherwise clearly and specifically defined.
[0065] In the related art, the storage controller is mainly used for managing the hard disk and the data stored on the storage end, and provides data access services to the server end. In the process of providing data access to the server end, due to the huge number of I / Os processed in a short period of time, the CPU in the storage controller undertakes a large number of unpacking, disk reading, and disk writing operations. In the storage field, a data I / O will go through multiple operation stages such as storage volume, storage pool, raid, storage disk, etc. in the back-end processing. How to speed up the processing speed of each stage and improve the effective utilization of the CPU has become an important way to improve the performance of the storage controller.
[0066] In order to effectively improve the current multi-core characteristics of CPUs, the general practice in the storage field is to further divide the storage process at each stage, dividing each existing stage into more and smaller processes to obtain a processing effect similar to pipeline concurrency, thereby greatly improving software execution efficiency. However, with the generation of a large number of small processes, the lock grabbing problem caused by the execution of critical sections controlled by locks has greatly limited the concurrency effect under this architecture.
[0067] In view of the above problems, the embodiment of the present application provides a business request processing method, system, electronic device and storage medium, the method comprising: when any thread in the business request processing system seizes the mutex lock of the target critical resource, the thread is used as the target thread; the target task to be executed requested by the target thread is migrated to the target task chain to be executed; the threads other than the target thread in the business request processing system are used as threads to be locked, and the target task to be executed requested by the thread to be locked is migrated to the target task chain to be executed, so that the target thread executes all the target tasks to be executed in the target task chain based on the target critical resource; wherein the target task to be executed requested by the target thread and the target task to be executed requested by the thread to be locked are both tasks to be executed that need to access the target critical resource, and the request to be responded to is composed of multiple tasks to be executed. The method provided by the above scheme reduces the release of the mutex lock and the generation of the preemption process by migrating the target task to be executed of the thread that has not seized the mutex lock to the target thread that has seized the mutex lock, so as to avoid thread blocking caused by seizing the lock, thereby improving the response efficiency of the business request.
[0068] The following specific embodiments may be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments. The embodiments of the present invention will be described below in conjunction with the accompanying drawings.
[0069] The embodiment of the present application provides a method for processing a business request, which is used to process a plurality of tasks to be executed split from a business request. The execution subject of the embodiment of the present application is an electronic device, such as a server, a desktop computer, a laptop computer, a tablet computer, and other electronic devices that can be used for processing business requests.
[0070] like Figure 1 FIG. 1 is a flow chart of a method for processing a service request provided in an embodiment of the present application, the method comprising:
[0071] Step 101: When any thread in the business request processing system seizes the mutex lock of the target critical resource, the thread is used as the target thread.
[0072] Among them, Figure 2 As shown, it is a schematic diagram of the structure of an exemplary business request processing system provided by an embodiment of the present application, based on binding one thread to each CPU core to eliminate the huge overhead caused by thread switching on a single CPU core. On the basis of binding one thread to each CPU core, a task queue is allocated for each processing stage of each I / O read and write, and each task category implements a task execution queue in each thread to wait for thread processing. Figure 2Taking the example of splitting the I / O service request into the fiber card stage, raid (redundant disk array) stage, volume stage and other stages, an I / O service request is split into fiber card tasks, raid (disk array) tasks, volume tasks and other tasks, and each task is cached in the corresponding task queue. Taking the raid service module as an example, the completion of its function is no longer supported by a single task, but the business process under this function is divided and cut into several pipeline tasks. Figure 2 In the shown mode, the life cycle of an I / O in the raid module consists of n tasks that support the raid module function. The n tasks can be inserted into any of the four RAID_queue queues to wait for the corresponding threads to process. The task queue can be a one-way or two-way linked list, a ring queue or other implementable methods.
[0073] in, Figure 2 A task scheduling execution framework for the current concurrent execution of storage task processes at various stages. Taking the raid business module as an example, once the tasks in the four raid queues grab a lock at the same time, under the current mechanism, only one thread will get the lock and obtain execution permission, and the other threads will be forced to enter a blocked state. Not only can the current task not be processed in time, but other tasks in the same queue or even the same thread are also forced to wait for the lock grabbing result, which seriously restricts the performance of the CPU and thus affects the overall performance of the storage system.
[0074] Specifically, critical resources are shared resources of the business request processing system. Threads use critical resources by accessing critical sections. The concept of critical sections is to protect mutual exclusive access to shared resources. Each critical section can only be accessed by one thread at a time. If a thread wants to access the critical section, it needs to seize the mutual exclusive lock of the target critical resource corresponding to the critical section. Figure 2 If any of the four threads shown grabs the mutex lock of the target critical resource, the thread will be used as the target thread.
[0075] Step 102 : Migrate the target to-be-executed task that is requested to be executed by the target thread to the target to-be-executed task chain.
[0076] Specifically, after the target thread seizes the mutex lock, it can migrate the target to-be-executed tasks in the task queue corresponding to any stage or the task queues corresponding to multiple stages to the target to-be-executed task chain for execution by the target thread.
[0077] Step 103, use threads other than the target thread in the business request processing system as threads to be locked, and migrate the target tasks to be executed by the requesting threads to be locked to the target task chain to be executed, so that the target thread executes all target tasks to be executed in the target task chain based on the target critical resources.
[0078] Among them, the target pending task requested to be executed by the target thread and the target pending task requested to be executed by the lock-grabbing thread are both pending tasks that need to access the target critical resources, and the request to be responded to is composed of multiple pending tasks.
[0079] It should be noted that in the related technology, since the threads other than the target thread in the business request processing system have not currently seized the mutex lock as the threads to be locked, they need to wait for the target thread to release the mutex lock before seizing it again. During the waiting process, the threads to be locked will be blocked, and the target tasks to be executed that are requested to be executed will not be processed in time.
[0080] Specifically, in order to solve the above-mentioned technical problems, the embodiment of the present application migrates the target tasks to be executed by the thread to be locked to the target task chain to be executed, so that the target thread that currently seizes the mutex lock can process the target tasks to be executed by these threads to be locked, so that the target tasks to be executed by the threads to be locked can be processed in a timely manner, thereby improving the response efficiency of business requests.
[0081] On the basis of the above embodiment, since the execution of tasks at different stages of a business request may require the same critical resource, in order to further improve the response efficiency of the business request, as an implementable manner, on the basis of the above embodiment, in one embodiment, the target task to be executed by the request target thread is migrated to the target task chain to be executed, including:
[0082] Step 1021, accessing several task queues corresponding to the target thread;
[0083] Step 1022, locating the to-be-executed tasks that need to access the target critical resource in each task queue, and taking the to-be-executed tasks as the target to-be-executed tasks;
[0084] Step 1023: Migrate the target to-be-executed task to the end of the target to-be-executed task chain list, and determine the task count value of the target to-be-executed task chain according to the number of the migrated target to-be-executed tasks.
[0085] The target critical resources may be shared memory, hardware devices, etc.
[0086] Specifically, by accessing each task queue corresponding to the target thread, it is possible to determine which critical resource the to-be-executed tasks cached in each task queue need to access respectively, and then migrate the to-be-executed tasks that need to access the target critical resource to the end of the target to-be-executed task chain list, and count the number of target to-be-executed tasks in the target to-be-executed task chain based on the task count value of the target to-be-executed task chain.
[0087] Specifically, in one embodiment, during the process of the target thread executing the target task to be executed at the head of the target task to be executed chain list, the target task to be executed by the requesting thread to grab the lock can be migrated to the end of the target task to be executed chain list; each time a target task to be executed is migrated to the end of the target task to be executed chain list, the task count value of the target task to be executed chain is increased by 1.
[0088] In this embodiment of the present application, the addition or subtraction of the task count value by 1 is atomic addition or atomic subtraction.
[0089] It should be noted that the embodiment of the present application makes the following structural adjustments to the common mutex lock. The number of tasks to be executed count (task count value) is initialized to 0, and the head and tail of the task list to be executed both point to NULL, that is, there are no tasks to be executed. Taking the raid business module as an example, the following scenarios are explained respectively.
[0090] {
[0091] Mutex lock; / / Non-blocking mutex lock
[0092] uint32count; / / Number of tasks to be executed
[0093] listhead; / / head of the list of tasks to be executed
[0094] listtail; / / The tail of the list of tasks to be executed
[0095] }
[0096] Furthermore, in one embodiment, each time the target thread completes the execution of a target task at the head of the target task chain to be executed, the task count value of the target task chain to be executed is reduced by 1; it is determined whether the task count value of the target task chain to be executed is 0; when it is determined that the task count value of the target task chain to be executed is not 0, the header pointer of the target task chain to be executed is increased by 1 to execute the next target task to be executed in the target task chain to be executed.
[0097] Specifically, Figure 2As shown, in the RAID queues -1, 2, 3, and 4 corresponding to threads 1, 2, 3, and 4, there is a raid task raid_task_m1, 2, 3, and 4, respectively, which needs to grab the same lock to access the critical area to execute the task. At this time, thread 1 grabs the lock and continues to execute according to the above-mentioned lock grabbing scenario. Since threads 2, 3, and 4 do not grab the lock, they will enter a blocked state under the existing mechanism, waiting for thread 1 to complete the task raid_task_m1 and release the lock, and then the next thread that grabs the lock will continue to execute. The other two threads continue to block and wait, and other tasks in their queues are also blocked and cannot be executed. Under the improved lock mechanism of the embodiment of the present application, taking thread 2 as an example, it grabs the lock once and returns immediately after failing to grab the lock, and completes the following actions in one atomic operation: determines whether its own target number of tasks to be executed, variable count, is zero; if it is zero, returns; if it is not zero, atomically adds 1 to the target number of tasks to be executed, variable count, of the target task chain to be executed, and removes the task to be executed raid_task_m2 from RAID queue-2, adds it to the tail of the task list to be executed, and waits for thread 1 to process it, while thread 2 continues to process other tasks in RAID_queue-2. In this way, thread 2 will not be blocked due to lock waiting, and at the same time, tasks in other task queues that thread 2 is responsible for are not affected by lock waiting and are processed more promptly.
[0098] Furthermore, in one embodiment, when it is determined that the task count value of the target to-be-executed task chain is 0, the mutex lock of the target critical resource is released.
[0099] Specifically, when the task count value of the target to-be-executed task chain is 0, it indicates that the target thread has processed all tasks in the target to-be-executed task chain, and thus the mutex lock of the target critical resource will be released for other threads to enter the mutex lock preemption process.
[0100] On the basis of the above embodiment, since migrating the target to-be-executed task to the target thread may increase the load of the CPU corresponding to the target thread, causing unbalanced utilization of the multi-core CPU, in order to achieve balanced utilization of the multi-core CPU, the embodiment of the present application, as an implementable manner, on the basis of the above embodiment, in one embodiment, the method further includes:
[0101] Step 201, screening the task queue to be balanced from the several task queues corresponding to the target thread;
[0102] Step 202: Migrate a number of tasks to be balanced in the task queue to be balanced to the target task queue of the corresponding thread to be locked.
[0103] The types of tasks to be executed cached in the task queue to be balanced and the target task queue are the same.
[0104] Specifically, according to the preset CPU balance scheduling standard, the task queues to be balanced can be screened from the several task queues corresponding to the target thread, and then the several tasks to be balanced in the task queues to be balanced can be migrated to the target task queue of the corresponding thread to be locked, so as to migrate the tasks to be executed in the target thread that do not require target critical resources to be executed to the thread to be locked for execution, so as to improve the efficiency of business request response while taking into account the balance of CPU utilization.
[0105] Specifically, in one embodiment, when the task queue corresponding to the target to-be-executed task is not empty, the task queue corresponding to the target to-be-executed task may be used as the task queue to be balanced.
[0106] Specifically, after the target to-be-executed task in the task queue is migrated to the target to-be-executed task chain, if the task queue still has other to-be-executed tasks, the task queue is used as the task queue to be balanced.
[0107] For example, since the task raid_task_m2 to be processed by thread 2 is handed over to thread 1 for processing, thread 2 can pick a task from RAID_queue-1 and insert it into RAID_task-2 to be processed by itself. If there is no task to be executed in RAID_queue-1, a task can be picked from other business modules, such as FC (fiber card)_queue-1, and inserted into FC_queue-2 to be processed by thread 2.
[0108] Specifically, in one embodiment, the task cache amount of each task queue corresponding to the target thread may be obtained; and the task queue with the largest task cache amount is used as the task queue to be balanced.
[0109] Specifically, when there is no task to be executed in RAID_queue-1, that is, when the task queue corresponding to the target task to be executed is empty, the task queue with the largest task cache amount is used as the task queue to be balanced.
[0110] The task cache capacity represents the number of tasks to be executed that are currently cached in the task queue.
[0111] Specifically, in one embodiment, the processor occupancy rate of the tasks to be executed cached in each task queue corresponding to the target thread is obtained; and the task queue with the highest processor occupancy rate of the cached tasks to be executed is used as the task queue to be balanced.
[0112] Specifically, since the types of tasks to be executed cached in each task queue are basically the same and belong to the same stage of the business request to be responded to, the processor occupancy rate (CPU occupancy rate) of the tasks to be executed cached in each task queue can be analyzed based on preset performance analysis tools, such as Perf, VTune and other tools, and then the task queue with the highest processor occupancy rate of the cached tasks to be executed is used as the task queue to be balanced, so as to improve the CPU utilization rate of the migration thread (such as thread 2).
[0113] Specifically, in one embodiment, for any thread to be locked, the amount of tasks to be executed that the thread to be locked requires for various critical resources is obtained, that is, the amount of tasks to be executed corresponding to each critical resource is determined, and the critical resource with the largest amount of tasks to be executed is used as the core critical resource; the tasks to be executed that require the core critical resource are screened in the target thread, and the task queue with the largest number of tasks to be executed that require the core critical resource is cached as the task queue to be balanced, so that the tasks to be executed that require the core critical resource in the task queue to be balanced can be migrated to the target task queue of the thread to be locked as the tasks to be balanced.
[0114] The target task queue is a task queue for tasks to be executed that require the core critical resources and are re-cached by the thread to be locked.
[0115] Furthermore, in one embodiment, a balanced allocation strategy for several tasks to be balanced can be determined based on the number of target tasks to be executed that are migrated from each thread to be locked to the target task chain to be executed; according to the balanced allocation strategy, several tasks to be balanced are migrated to the target task queue of the corresponding thread to be locked.
[0116] It should be noted that, since there are multiple threads to be locked that migrate target tasks to be executed to the target thread, when migrating the tasks to be balanced of the target thread to the thread to be locked, the tasks to be balanced can also be dispersedly migrated to multiple threads to be locked.
[0117] Specifically, in one embodiment, for any thread to be locked, a corresponding number of tasks to be balanced can be migrated to the target task queue of the corresponding thread to be locked according to the migration ratio represented by the balanced allocation strategy.
[0118] Specifically, the corresponding migration ratio can be determined according to the number of target tasks to be executed that are migrated from each thread to be locked to the target task chain to be executed. That is, the more target tasks to be executed that are migrated, the higher the corresponding migration ratio is, and more tasks to be balanced are undertaken to achieve balanced scheduling of CPU utilization.
[0119] The business request processing method provided by the embodiment of the present application is to use any thread in the business request processing system as the target thread when it seizes the mutex lock of the target critical resource; migrate the target task to be executed that the target thread is requested to execute to the target task chain to be executed; use the threads other than the target thread in the business request processing system as threads to be locked, and migrate the target task to be executed that the thread to be locked is requested to execute to the target task chain to be executed, so that the target thread executes all the target tasks to be executed in the target task chain based on the target critical resource; wherein the target task to be executed that the target thread is requested to execute and the target task to be executed that the thread to be locked is requested to execute are both tasks to be executed that need to access the target critical resource, and the request to be responded to is composed of multiple tasks to be executed. The method provided by the above scheme reduces the release of the mutex and the generation of the preemption process by migrating the target task to be executed of the thread that has not seized the mutex lock to the target thread that has seized the mutex lock, so as to avoid thread blocking due to lock seizure, effectively weaken the impact of a task on the overall business due to lock seizure blocking, thereby improving the response efficiency of the business request. In addition, by flexibly dealing with the inherent defects of multi-thread lock grabbing that causes thread blocking and restricts CPU performance, the purpose of optimizing storage read and write I / O is achieved.
[0120] An embodiment of the present application provides a service request processing device, which is used to execute the service request processing method provided by the above embodiment.
[0121] like Figure 3 , which is a schematic diagram of the structure of a service request processing device provided in an embodiment of the present application. The service request processing device 30 comprises: a preemption module 301 , a migration module 302 and a processing module 303 .
[0122] Among them, the preemption module is used to use any thread in the business request processing system as the target thread when the thread preempts the mutex lock of the target critical resource; the migration module is used to migrate the target to-be-executed task requested to be executed by the target thread to the target to-be-executed task chain; the processing module is used to use the threads other than the target thread in the business request processing system as the threads to be locked, and migrate the target to-be-executed tasks requested to be executed by the threads to be locked to the target to-be-executed task chain, so that the target thread executes all target to-be-executed tasks in the target to-be-executed task chain based on the target critical resource.
[0123] Among them, the target pending task requested to be executed by the target thread and the target pending task requested to be executed by the lock-grabbing thread are both pending tasks that need to access the target critical resources, and the request to be responded to is composed of multiple pending tasks.
[0124] Regarding the service request processing device in this embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0125] The service request processing device provided in the embodiment of the present application is used to execute the service request processing method provided in the above embodiment. Its implementation method and principle are the same and will not be repeated here.
[0126] An embodiment of the present application provides a service request processing system, which is used to execute the service request processing method provided in the above embodiment.
[0127] like Figure 4 FIG. 1 is a schematic diagram of the structure of a business request processing system provided in an embodiment of the present application. The business request processing system includes: a controller, multiple threads and a task queue.
[0128] Among them, threads correspond one-to-one to processing cores of a multi-core processor; each thread corresponds to multiple task queues, the request to be responded to is composed of multiple tasks to be executed, and multiple pending services of a single pending response service are cached in different task queues; the controller performs service request processing based on the method provided in the above embodiment.
[0129] The controller may specifically be a storage controller.
[0130] Regarding the service request processing system in this embodiment, its specific implementation has been described in detail in the embodiment of the method, and will not be elaborated here.
[0131] The service request processing system provided in the embodiment of the present application is used to execute the service request processing method provided in the above embodiment. Its implementation method and principle are the same and will not be repeated here.
[0132] An embodiment of the present application provides an electronic device for executing the service request processing method provided in the above embodiment.
[0133] like Figure 5 FIG. 5 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. The electronic device 50 includes: at least one processor 51 and a memory 52.
[0134] The memory stores computer-executable instructions; at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the service request processing method provided in the above embodiment.
[0135] The electronic device provided in the embodiment of the present application is used to execute the service request processing method provided in the above embodiment. Its implementation method and principle are the same and will not be repeated here.
[0136] An embodiment of the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, a service request processing method provided in any of the above embodiments is implemented.
[0137] The storage medium containing computer executable instructions provided in the embodiments of the present application can be used to store computer executable instructions of the service request processing method provided in the aforementioned embodiments. The implementation method and principle are the same and will not be repeated here.
[0138] An embodiment of the present application provides a computer program product, including computer instructions, which are used to enable a computer to execute the service request processing method provided in the aforementioned embodiment.
[0139] The embodiments of the present application provide a computer program product that can be used to execute computer instructions of the service request processing method provided in the aforementioned embodiments. The implementation method and principle are the same and will not be repeated here.
[0140] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0141] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0142] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0143] The above-mentioned integrated unit implemented in the form of a software functional unit can be stored in a computer-readable storage medium. The above-mentioned software functional unit is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform some steps of the methods of each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program codes.
[0144] A part of the present application may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of computer program instructions in computer-readable media includes, but is not limited to, source files, executable files, installation package files, etc., and accordingly, the way in which computer program instructions are executed by a computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to the computer.
[0145] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example for illustration. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. The specific working process of the device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0146] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for processing a business request, characterized in that: include: When any thread in the business request processing system seizes the mutex lock of the target critical resource, the thread is used as the target thread; Migrating the target task to be executed by the target thread to the target task chain to be executed; The threads other than the target thread in the business request processing system are used as threads to be locked, and the target tasks to be executed that are requested to be executed by the threads to be locked are migrated to the target task chain to be executed, so that the target thread executes all the target tasks to be executed in the target task chain to be executed based on the target critical resources; The target pending task requested to be executed by the target thread and the target pending task requested to be executed by the lock-grabbing thread are both pending tasks that need to access the target critical resources, the request to be responded to is composed of multiple pending tasks, and the target critical resources include shared memory and hardware devices; The method further comprises: Selecting a task queue to be balanced from a plurality of task queues corresponding to the target thread; Migrate several tasks to be balanced in the task queue to be balanced to the target task queue of the corresponding thread to be locked; The types of tasks to be executed cached in the task queue to be balanced and the target task queue are the same; The step of screening the task queues to be balanced from the plurality of task queues corresponding to the target thread includes: When the task queue corresponding to the target task to be executed is not empty, the task queue corresponding to the target task to be executed is used as the task queue to be balanced; or Obtaining the task cache amount of each of the task queues corresponding to the target thread; The task queue with the largest task cache amount is used as the task queue to be balanced.
2. The method according to claim 1, characterized in that The step of migrating the target task to be executed by the target thread to a target task chain to be executed includes: Accessing several task queues corresponding to the target thread; Locating the to-be-executed tasks that need to access the target critical resource in each of the task queues, and using the to-be-executed tasks as the target to-be-executed tasks; The target to-be-executed task is migrated to the end of the target to-be-executed task chain list, and a task count value of the target to-be-executed task chain is determined according to the number of the migrated target to-be-executed tasks.
3. The method according to claim 1, characterized in that The step of migrating the target task to be executed by the lock-grabbing thread to the target task chain to be executed includes: During the process of the target thread executing the target task to be executed at the head of the target task to be executed chain list, the target task to be executed requested to be executed by the lock-grabbing thread is migrated to the tail of the target task to be executed chain list; Each time a target task to be executed is migrated to the end of the target task to be executed chain list, the task count value of the target task to be executed chain is increased by 1.
4. The method according to claim 3, characterized in that The method further comprises: Every time the target thread completes the execution of a target task at the head of the target task chain list, the task count value of the target task chain is reduced by 1; Determine whether the task count value of the target to-be-executed task chain is 0; When it is determined that the task count value of the target to-be-executed task chain is not 0, the head pointer of the target to-be-executed task chain is incremented by 1 to execute the next target to-be-executed task in the target to-be-executed task chain.
5. The method according to claim 4, characterized in that The method further comprises: When it is determined that the task count value of the target to-be-executed task chain is 0, the mutex lock of the target critical resource is released.
6. The method according to claim 1, characterized in that The step of screening the task queues to be balanced from the plurality of task queues corresponding to the target thread includes: Obtaining the processor occupancy rate of the tasks to be executed in the task queue cache corresponding to the target thread; The cached task queue with the highest processor occupancy rate of the tasks to be executed is used as the task queue to be balanced.
7. The method according to claim 1, characterized in that The step of migrating a plurality of tasks to be balanced in the task queue to be balanced to the target task queue of the thread to be locked includes: Determine a balanced allocation strategy for the plurality of tasks to be balanced according to the number of target tasks to be executed that are migrated from each of the threads to be locked to the target task chain to be executed; According to the balanced allocation strategy, the plurality of tasks to be balanced are migrated to the target task queue of the corresponding thread to be locked.
8. The method according to claim 7, characterized in that The step of migrating the plurality of tasks to be balanced to the target task queue of the corresponding thread to be locked according to the balanced allocation strategy includes: For any of the threads to be locked, a corresponding number of tasks to be balanced are migrated to the target task queue of the corresponding thread to be locked according to the migration ratio represented by the balanced allocation strategy.
9. A business request processing system, characterized in that: include: A controller, a plurality of threads and a task queue, wherein the threads correspond one-to-one to the processing cores of the multi-core processor; Each of the threads corresponds to a plurality of task queues, a request to be responded to is composed of a plurality of tasks to be executed, and a plurality of tasks to be executed of a single service to be responded to are cached in different task queues; The controller performs service request processing based on the method according to any one of claims 1 to 8.
10. An electronic device, characterized in that: include: at least one processor and memory; The memory stores computer-executable instructions; The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the method according to any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when a processor executes the computer-executable instructions, the method according to any one of claims 1 to 8 is implemented.
12. A computer program product, characterized in that The method comprises computer instructions for causing a computer to execute the method according to any one of claims 1 to 8.
