Thread scheduling method and device, computing equipment, storage medium and program product
By determining and binding the processing core information based on the server load type, the efficiency problems caused by thread scheduling in a multi-core processor environment are solved, and more efficient task processing and lower resource waste are achieved.
Patent Information
- Application Number
- CN202411086024.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-08
- Publication Date
- 2025-02-18
AI Technical Summary
In a multi-core processor environment, thread context switching losses and cache failure losses caused by thread scheduling affect the overall efficiency of the system, especially in heavy game server scenarios.
By obtaining the load type of the pending server, determining the processing core information based on the scheduling policy corresponding to the load type, and binding the pending server with the corresponding processing core to execute the task thread.
This method can improve task processing efficiency, reduce task waiting time, avoid thread context switching and cache failure loss, thereby improving CPU usage.
Smart Images

Figure CN119473526A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present specification relate to the field of computer technology, and in particular to a thread scheduling method, apparatus, computing device, storage medium, and program product. Background Art
[0002] In a multi-core processor, thread scheduling refers to assigning threads to different processor cores for execution according to a certain strategy, so as to fully utilize the computing power of the multi-core processor and improve the overall performance of the system. Operating systems and hardware platforms usually provide a series of mechanisms to support thread scheduling in multi-core processors. For example, the Linux system provides a variety of scheduling strategies and priority settings, which can be configured according to the needs of the application.
[0003] However, in some heavy game server scenarios, thread scheduling will cause thread context switching losses and cache invalidation losses. In addition, different threads simultaneously occupying a CPU will result in longer waiting times, thus affecting the overall efficiency of the system. Summary of the invention
[0004] In view of this, an embodiment of this specification provides a thread scheduling method. One or more embodiments of this specification also relate to a thread scheduling device, a computing device, a computer-readable storage medium and a computer program product to solve the technical defects existing in the prior art.
[0005] According to a first aspect of an embodiment of this specification, a thread scheduling method is provided, including:
[0006] Get the load type of the server to be processed;
[0007] Determine the processing core information corresponding to the server to be processed according to the scheduling strategy corresponding to the load type;
[0008] According to the processing core information, the processing core to be bound is determined, and the server to be processed is bound to the processing core to be bound, wherein the processing core to be bound executes the task thread corresponding to the server to be processed when bound to the server to be processed.
[0009] According to a second aspect of an embodiment of this specification, a thread scheduling device is provided, including:
[0010] An acquisition module is configured to acquire a load type of a server to be processed;
[0011] A determination module is configured to determine the processing core information corresponding to the server to be processed according to the scheduling strategy corresponding to the load type;
[0012] The binding module is configured to determine the processing core to be bound according to the processing core information, and bind the server to be processed with the processing core to be bound, wherein the processing core to be bound executes the task thread corresponding to the server to be processed when bound to the server to be processed.
[0013] According to a third aspect of an embodiment of this specification, a computing device is provided, including:
[0014] Memory and processor;
[0015] The memory is used to store computer executable instructions, and the processor is used to execute the computer executable instructions. When the computer executable instructions are executed by the processor, the steps of the above-mentioned thread scheduling method are implemented.
[0016] According to a fourth aspect of the embodiments of this specification, a computer-readable storage medium is provided, which stores computer-executable instructions, and when the instructions are executed by a processor, the steps of the above-mentioned thread scheduling method are implemented.
[0017] According to a fifth aspect of the embodiments of this specification, a computer program product is provided, including a computer program / instruction, which implements the steps of the above-mentioned thread scheduling method when executed by a processor.
[0018] One embodiment of the present specification realizes obtaining the load type of the server to be processed; determining the processing core information corresponding to the server to be processed according to the scheduling strategy corresponding to the load type; determining the processing core to be bound according to the processing core information, and binding the server to be processed with the processing core to be bound, wherein the processing core to be bound executes the task thread corresponding to the server to be processed when bound to the server to be processed. By determining the processing core information corresponding to the server to be processed according to the scheduling strategy corresponding to the load type, the task thread corresponding to the server to be processed can be scheduled according to the load type, thereby improving the task processing efficiency; by determining the processing core to be bound according to the processing core information, and binding the server to be processed with the processing core to be bound, the corresponding processing core can be bound to the task thread in each server to be processed, so that the task thread is executed in the bound processing core, avoiding multiple threads from occupying the same processing core, reducing the task waiting time, improving the task processing efficiency, and avoiding the context switching loss and cache invalidation loss caused by the thread switching back and forth between multiple processing cores, thereby improving the CPU utilization rate. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 is a flowchart of a thread scheduling method provided by an embodiment of this specification;
[0020] Figure 2 is a process flow chart of a thread scheduling method provided by an embodiment of this specification;
[0021] Figure 3 It is a structural diagram of a thread scheduling device provided by an embodiment of this specification;
[0022] Figure 4 It is a structural block diagram of a computing device provided by an embodiment of this specification. DETAILED DESCRIPTION
[0023] Many specific details are described in the following description to facilitate a full understanding of this specification. However, this specification can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of this specification, so this specification is not limited to the specific implementation disclosed below.
[0024] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.
[0025] It should be understood that although the terms first, second, etc. may be used to describe various information in one or more embodiments of this specification, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0026] In addition, it should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in one or more embodiments of this specification are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0027] First, the terms involved in one or more embodiments of this specification are explained.
[0028] CPU (Central Processing Unit): It is the core component of the computer system, responsible for executing program instructions, processing data, and controlling the basic operations of the computer.
[0029] Multi-core processor: refers to a processor that integrates two or more complete computing engines (cores). These cores can independently execute instructions and process data, allowing the multi-core processor to handle multiple tasks or threads at the same time, thereby improving computing efficiency and overall performance.
[0030] Hyperthreading core: It is an application of hyperthreading technology at the CPU core level. Hyperthreading technology allows a single physical core to be simulated into two logical cores, thereby improving the parallel processing capability of the processor.
[0031] Process: A process is an execution process of a program. It is a dynamic concept and the basic unit for allocating and managing resources during the execution of a program.
[0032] Thread: A thread is the basic unit of CPU scheduling and dispatching, and can share all the resources owned by the process with other threads belonging to the same process.
[0033] Heavy game servers: usually used to support games that require high computing performance, large storage capacity, high network bandwidth, and strong real-time processing capabilities. Such games often have complex game logic, exquisite graphics, a huge world view, and rich game content, such as massively multiplayer online role-playing games (MMORPG), real-time strategy games (RTS), massively multiplayer online shooters (FPS), etc. These games require servers to be able to process data from thousands of players at the same time and ensure the smoothness and stability of the game.
[0034] Context switch: refers to the process of CPU switching from one thread to another. In this process, the CPU needs to save the context of the current thread (including CPU registers, program counter, stack and other status information) and load the context of the new thread. This saving and loading process consumes a certain amount of CPU time and system resources, resulting in loss.
[0035] Cache invalidation: When the CPU switches threads, different threads may access different memory areas, causing the data in the CPU cache to be no longer valid and need to be reloaded from the main memory. This process reduces the CPU's memory access efficiency, resulting in additional performance loss.
[0036] After the server is deployed, multiple processes can be run, and each process can include multiple threads. Generally speaking, these processes and threads can be scheduled by the operating system. Different operating systems often provide different process or thread scheduling strategies to achieve the scheduling of processes or threads in multi-core processors. However, the scheduling strategy of the operating system is a relatively universal design. In the scenarios of some heavy game servers, the use of the default scheduling strategy of the operating system will result in large thread context switching losses and cache invalidation losses, thereby reducing CPU utilization.
[0037] In addition, some asynchronous tasks are usually processed by threads. Assuming that the execution time of a thread task is 2 seconds, if two threads are occupying the same CPU, both threads will complete the task in about 4 seconds; if 16 threads are occupying the same CPU, all 16 threads will complete the task in about 32 seconds. In this case, if there is a next task that needs to wait for the task to be completed before execution, the waiting time of the next task thread will be too long, reducing the task processing efficiency.
[0038] Based on this, an embodiment of the present specification provides a thread scheduling method to obtain the load type of the server to be processed; determine the processing core information corresponding to the server to be processed according to the scheduling strategy corresponding to the load type; determine the processing core to be bound according to the processing core information, and bind the server to be processed to the processing core to be bound, wherein the processing core to be bound executes the task thread corresponding to the server to be processed when bound to the server to be processed.
[0039] In this way, by determining the processing core information corresponding to the server to be processed according to the scheduling strategy corresponding to the load type, the task thread corresponding to the server to be processed can be scheduled according to the load type, thereby improving the task processing efficiency; by determining the processing core to be bound according to the processing core information, and binding the server to be processed with the processing core to be bound, the corresponding processing core can be bound to the task thread in each server to be processed, so that the task thread is executed in the bound processing core, avoiding multiple threads from occupying the same processing core, reducing task waiting time, improving task processing efficiency, and avoiding context switching loss and cache invalidation loss caused by threads switching back and forth between multiple processing cores, thereby improving CPU utilization.
[0040] In this specification, a thread scheduling method is provided. This specification also relates to a thread scheduling device, a computing device, a computer-readable storage medium, and a computer program product, which are described in detail one by one in the following embodiments.
[0041] See also Figure 1 , Figure 1A flowchart of a thread scheduling method provided according to an embodiment of the present specification is shown, which specifically includes the following steps.
[0042] Step 102: Obtain the load type of the server to be processed.
[0043] According to an optional embodiment of the present specification, the load type of the server to be processed may be obtained, so that the scheduling strategy corresponding to the server to be processed may be determined based on the load type.
[0044] Specifically, the load type may include a low load type and a high load type, and different load types correspond to different scheduling strategies.
[0045] Specifically, the server to be processed may include servers that provide various services, such as servers that provide communication services, and servers that process data sent by clients, etc. In one or more embodiments of this specification, the server to be processed may specifically refer to a game server or a heavy game server.
[0046] It should be noted that the server to be processed can be implemented as a distributed server cluster consisting of multiple servers, or as a single server. The server to be processed can also be a server of a distributed system, or a server combined with blockchain. The server can also be a cloud server (cloud-side device) of basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms, or an intelligent cloud computing server or intelligent cloud host with artificial intelligence technology.
[0047] In practical applications, the scheduling strategy corresponding to the server to be processed can be determined according to the load type of the server to be processed.
[0048] According to another optional embodiment of the present specification, the configuration information of the server to be processed may also be obtained, and the scheduling strategy corresponding to the server to be processed may be determined based on the configuration information.
[0049] Specifically, the configuration information may include the load type of the server to be processed, and may also include the scheduling strategy corresponding to the server to be processed.
[0050] Optionally, the configuration information may be pre-configured and obtained based on the load type of the server to be processed.
[0051] According to another optional embodiment of the present specification, the load type of the server to be processed may be obtained in response to a server startup instruction for the server to be processed.
[0052] According to an optional embodiment of the present specification, obtaining the load type of the server to be processed may include the following steps:
[0053] Get the target game mode corresponding to the server to be processed;
[0054] Based on the load of the target game mode, determine the load type of the server to be processed.
[0055] Specifically, the target game mode can be understood as the game mode that the server to be processed runs in. The game mode can include different modes such as 3V3, 6V6, or 6*10, and the number of players loaded in different game modes is often different.
[0056] Optionally, the load type of the server to be processed can be determined based on the number of players in the target game mode load; the load type of the server to be processed can also be pre-configured based on the number of players in the target game mode load, so that the load type of the server to be processed can be directly obtained based on the configuration information.
[0057] Furthermore, when the number of players reaches a preset threshold, the load type of the server to be processed can be determined to be a high load type; when the number of players does not reach the preset threshold, the load type of the server to be processed can be determined to be a low load type. It is also possible to set in advance for each game mode whether each game mode belongs to a high load type or a low load type.
[0058] For example, the number of players in the 3V3 mode is usually 6, and the number of players in the 6V6 mode is usually 12; in actual applications, the number of players actually loaded by the server can be adjusted to 24, 36, etc. according to the CPU load. The 6*10 mode often requires a single core to load at least 60 players by default, and the server with the game mode of 6*10 can be pre-configured as a high-load type server.
[0059] By applying this embodiment, by obtaining the target game mode corresponding to the server to be processed, the load type of the server to be processed can be determined based on the load situation of the target game mode, so that the corresponding processing core can be determined for the server to be processed based on the scheduling method corresponding to the load type, thereby ensuring the server's response speed and task processing efficiency.
[0060] According to another optional embodiment of the present specification, obtaining the load type of the server to be processed may also include the following steps:
[0061] Get the historical CPU usage of the server to be processed;
[0062] Determine the load type of the server to be processed based on historical CPU usage.
[0063] In the actual implementation process, the load type of the server to be processed can also be determined based on system resource usage (such as memory usage, disk I / O, network traffic, etc.), system load indicators (such as the average load value within a preset time period, the number of concurrent connections, etc.), and other indicators (such as server response time, log analysis results, etc.); in addition, the load of the server to be processed can be monitored in real time through monitoring tools to determine the load type of the server to be processed.
[0064] Step 104: Determine the processing core information corresponding to the server to be processed according to the scheduling strategy corresponding to the load type.
[0065] According to an optional embodiment of the present specification, the processing core information corresponding to the server to be processed may be determined according to the scheduling strategy corresponding to the load type.
[0066] Specifically, the scheduling strategy is used to determine the processing core information corresponding to the server to be processed. The processing core information may include the processing core type, processing core location, processing core quantity and other information related to the processing core to be allocated.
[0067] In one or more optional embodiments of the present specification, determining the processing core information corresponding to the server to be processed according to the scheduling strategy corresponding to the load type may include the following steps:
[0068] According to the scheduling strategy corresponding to the load type, the processing core type and processing core position relationship corresponding to the server to be processed are determined.
[0069] Specifically, the processing core type may include a dedicated processing core type and a public processing core type. Among them, the processing core of the dedicated processing core type is usually used to process the main thread of a server, that is, a server main thread can use a dedicated processing core; the processing core of the public processing core type is usually used to process the auxiliary threads corresponding to multiple servers, that is, the auxiliary threads of multiple servers can share a public processing core.
[0070] Specifically, the position relationship of the processing cores may include that the processing cores are located adjacently, or that the processing cores are located at random.
[0071] By applying this embodiment, the processing core type and processing core position relationship corresponding to the server to be processed are determined according to the scheduling strategy corresponding to the load type. The processing core to be bound corresponding to the server to be processed can be determined according to the processing core type and processing core position relationship, thereby improving the efficiency and accuracy of processing core binding.
[0072] According to another optional embodiment of the present specification, a corresponding scheduling strategy may be pre-configured for the server to be processed according to the load type of the server to be processed. Further, the processing core information corresponding to the server to be processed may be determined according to the scheduling strategy pre-configured for the server to be processed.
[0073] Step 106: Determine the processing core to be bound according to the processing core information, and bind the server to be processed to the processing core to be bound, wherein the processing core to be bound executes the task thread corresponding to the server to be processed when bound to the server to be processed.
[0074] In actual applications, the processing core to be bound can be determined according to the processing core information, and the server to be processed can be bound to the processing core to be bound, so that the processing core to be bound can execute the task thread corresponding to the server to be processed when bound to the server to be processed.
[0075] Specifically, the processing core to be bound can be understood as at least one processing core in a multi-core processor, specifically a hyperthreaded core. The processing core to be bound is used to bind to the server to be processed to execute the task thread corresponding to the server to be processed. The task thread corresponding to the server to be processed may include a main thread and at least one auxiliary thread. Among them, the main thread is used to execute a series of core tasks in the server, including processing activity requests, system updates, status synchronization, communication, etc. The main thread tasks often have high requirements for task processing efficiency; the auxiliary threads are used to process tasks with infrequent requests and relatively low criticality, such as asynchronous writing of logs, asynchronous access to data, etc. The auxiliary thread tasks often have lower requirements for task processing efficiency than the main thread tasks, allowing threads to queue and wait.
[0076] According to an optional embodiment of the present specification, the load type may include a low load type; accordingly, determining the processing core to be bound according to the processing core information may include the following steps:
[0077] According to the processing core types and the processing core position relationship, the first dedicated processing core and the target common processing core to be bound are determined.
[0078] Specifically, the first dedicated processing core may be any idle core among the multiple processing cores of the multi-core processor. The target public processing core may be a processing core bound to an auxiliary thread of another server. The positional relationship between the first dedicated processing core and the target public processing core is arbitrary.
[0079] In actual applications, due to the low-load type of servers, the number of task threads is small and the load of auxiliary threads is low. Therefore, the main thread can be bound to the first dedicated processing core; the auxiliary thread can be bound to the target common processing core and share the target common processing core with the auxiliary threads of other servers.
[0080] For example, assuming that the multi-core processor includes 16 processing cores, then when each server is a low-load type server, 14 servers can be started on the multi-core processor, and the main threads of the 14 servers can be bound to 14 of the processing cores respectively; one of the remaining 2 processing cores can be used as a public processing core, and the auxiliary threads of the 14 servers can be bound to the public processing core; and the remaining one processing core can be used by other processes of the operating system.
[0081] By applying this embodiment, by determining the first dedicated processing core and the target common processing core to be bound for the low-load type of server to be processed, the auxiliary threads of each server with lower load can be bound to a common processing core, saving the number of processing cores occupied by the auxiliary threads, so that the saved processing cores can be used to bind more server main threads, thereby improving CPU utilization.
[0082] According to another optional embodiment of the present specification, the load type may include a high load type; accordingly, determining the processing core to be bound according to the processing core information may include the following steps:
[0083] According to the processing core type and the processing core position relationship, the second dedicated processing core and the third dedicated processing core to be bound are determined, wherein the second dedicated processing core and the third dedicated processing core are adjacent to each other.
[0084] Specifically, the second dedicated processing core and the third dedicated processing core may be two processing cores in adjacent locations and in an idle state among multiple processing cores of a multi-core processor, and the two processing cores share one physical core.
[0085] In actual applications, since high-load servers often have more auxiliary threads and the auxiliary thread load is high, the main thread can be bound to the second dedicated processing core; the auxiliary thread can be bound to the third dedicated processing core adjacent to the second dedicated processing core.
[0086] For example, assuming that the multi-core processor includes 16 processing cores, when each server is a high-load type server, 8 servers can be started, and two adjacent processing cores are bound to each server. Of the bound two adjacent processing cores, one is used to bind to the server main thread, and the other is used to bind to the server auxiliary thread.
[0087] By applying this embodiment, by determining the second dedicated processing core and the third dedicated processing core to be bound for the high-load type of server to be processed, the thread waiting time can be reduced and the thread task processing efficiency can be improved; and, by binding the server thread to two adjacent processing cores, the cache hit rate can be improved, the data exchange and synchronization efficiency can be improved, and the communication delay and overhead between threads can be reduced, thereby improving CPU performance and avoiding context switching overhead and cache invalidation overhead.
[0088] In the actual implementation process, it is also possible to bind servers of two load types in a multi-core processor according to the actual application situation, and each server can determine the processing core to be bound according to the scheduling policy corresponding to its load type.
[0089] In one or more optional embodiments of the present specification, binding the server to be processed with the processing core to be bound may include the following steps:
[0090] Get the main thread and at least one auxiliary thread of the server to be processed;
[0091] The main thread and at least one auxiliary thread are respectively bound to the processing core to be bound.
[0092] During the actual implementation process, since the operating system creates the thread corresponding to the server when the server is started, after determining the processing core to be bound corresponding to the server, the main thread and at least one auxiliary thread of the server to be processed can be obtained, thereby realizing the binding of the server and the processing core based on the thread.
[0093] According to an optional embodiment of the present specification, before obtaining the main thread and at least one auxiliary thread of the server to be processed, the method may further include: creating the main thread and at least one auxiliary thread of the server to be processed in response to a start instruction for the server to be processed.
[0094] Furthermore, based on the startup of the server to be processed, the main thread and at least one auxiliary thread can be bound to the processing core to be bound respectively.
[0095] By applying this embodiment, the main thread and at least one auxiliary thread of the server to be processed are obtained; the main thread and at least one auxiliary thread can be respectively bound to the processing core to be bound, so as to realize the binding of the server and the processing core, so that the main thread of the server can run in the corresponding dedicated processing core, avoiding the thread switching back and forth between different processing cores, and further avoiding the context switching loss and cache invalidation loss caused by thread scheduling.
[0096] According to an optional embodiment of the present specification, the load type of the server to be processed is a low load type, and the processing cores to be bound include a first dedicated processing core and a target public processing core; accordingly, binding the main thread and at least one auxiliary thread to the processing cores to be bound respectively may include the following steps:
[0097] The main thread is bound to the first dedicated processing core, and at least one auxiliary thread is bound to the target common processing core.
[0098] Specifically, the first dedicated processing core may be any idle processing core among multiple processing cores of the multi-core processor. The target public processing core may be used to bind the auxiliary thread of the server to be processed, or may be used to bind the auxiliary thread of other servers except the server to be processed.
[0099] In practical applications, when the load type of the server to be processed is a low load type, it can be determined that the processing cores to be bound corresponding to the server to be processed include the first dedicated processing core and the target public processing core. Further, the main thread of the server to be processed can be bound to the first dedicated processing core, and each auxiliary thread of the server to be processed can be bound to the target public processing core.
[0100] Optionally, binding the main thread to the first dedicated processing core and binding at least one auxiliary thread to the target common processing core may be achieved through an API provided by the operating system.
[0101] By applying this embodiment, by binding the main thread to the first dedicated processing core, the loss caused by thread scheduling context switching can be avoided and the CPU utilization rate can be improved; by binding at least one auxiliary thread to the target common processing core, the overhead of other threads and the main thread grabbing resources caused by binding to the same core can be avoided, thereby improving the overall performance of the system.
[0102] According to another optional embodiment of the present specification, the load type of the server to be processed is a high load type, and the processing cores to be bound include a second dedicated processing core and a third dedicated processing core; accordingly, binding the main thread and at least one auxiliary thread to the processing cores to be bound respectively may include the following steps:
[0103] The main thread is bound to the second dedicated processing core, and at least one auxiliary thread is bound to the third dedicated processing core, wherein the second dedicated processing core and the third dedicated processing core are located adjacent to each other.
[0104] Specifically, the second dedicated processing core and the third dedicated processing core may be two processing cores in adjacent locations and in an idle state among multiple processing cores of a multi-core processor, and the second dedicated processing core and the third dedicated processing core share the same physical core.
[0105] In practical applications, when the load type of the server to be processed is a high load type, it can be determined that the processing cores to be bound corresponding to the server to be processed include the second dedicated processing core and the third dedicated processing core. Further, the main thread of the server to be processed can be bound to the second dedicated processing core, and each auxiliary thread of the server to be processed can be bound to the third dedicated processing core.
[0106] Optionally, binding the main thread to the second dedicated processing core and binding at least one auxiliary thread to the third dedicated processing core may be achieved through an API provided by the operating system.
[0107] By applying this embodiment, by binding high-computation threads to adjacent cores, modern CPU hyperthreading technology can be better utilized, cache can be better utilized, and the situation in which thread preemption causes the final completion time of the task to exceed expectations can be avoided.
[0108] One embodiment of the present specification realizes obtaining the load type of the server to be processed; determining the processing core information corresponding to the server to be processed according to the scheduling strategy corresponding to the load type; determining the processing core to be bound according to the processing core information, and binding the server to be processed with the processing core to be bound, wherein the processing core to be bound executes the task thread corresponding to the server to be processed when bound to the server to be processed. By determining the processing core information corresponding to the server to be processed according to the scheduling strategy corresponding to the load type, the task thread corresponding to the server to be processed can be scheduled according to the load type, thereby improving the task processing efficiency; by determining the processing core to be bound according to the processing core information, and binding the server to be processed with the processing core to be bound, the corresponding processing core can be bound to the task thread in each server to be processed, so that the task thread is executed in the bound processing core, avoiding multiple threads from occupying the same processing core, reducing the task waiting time, improving the task processing efficiency, and avoiding the context switching loss and cache invalidation loss caused by the thread switching back and forth between multiple processing cores, thereby improving the CPU utilization rate.
[0109] The following combination Figure 2 , taking the application of the thread scheduling method provided in this specification in the heavy game server scenario as an example, the thread scheduling method is further explained. Figure 2 A processing flow chart of a thread scheduling method provided by an embodiment of the present specification is shown, which specifically includes the following steps.
[0110] Step 202: Start the game server.
[0111] In actual applications, the corresponding game server can be started according to the start instruction input by the user. There may be multiple game servers.
[0112] Step 204: Determine a corresponding scheduling strategy according to the load type of the game server.
[0113] Specifically, the load types of the game server include low load type and high load type. Among them, the scheduling strategy corresponding to the low load type may include: binding the server main thread to a dedicated idle core, and binding other auxiliary threads to a common core. The scheduling strategy corresponding to the high load type may include: binding the server main thread to a dedicated idle core, binding other auxiliary threads to another dedicated idle core, and the two bound cores are adjacent and share the same physical core.
[0114] When the load type is a low load type, step 206 is executed; when the load type is a high load type, step 206' is executed.
[0115] Step 206: Bind the main thread of the game server to a dedicated idle core, and bind other auxiliary threads to a public core.
[0116] It should be noted that the common core can be used to bind auxiliary threads of multiple servers with a low load type.
[0117] For example, on a 16-core machine, 14 game servers can be started and 14 cores can be bound to the main threads of the game servers, one common core can be bound to other auxiliary threads of the 14 servers, and the remaining core can be used by other processes of the operating system.
[0118] Step 206 ′: bind the main thread of the game server to a dedicated idle core, and bind other auxiliary threads to another dedicated idle core, and the positions of the two dedicated idle cores are adjacent.
[0119] For example, on a 16-core machine, eight game servers can be started, and two adjacent cores are bound to each game server as dedicated cores corresponding to each server.
[0120] Step 208: Release the bound core after the game server exits.
[0121] It should be noted that the above steps 202 to 208 may be executed by a scheduler.
[0122] By applying this embodiment, by determining the processing core information corresponding to the server to be processed according to the scheduling strategy corresponding to the load type, the task thread corresponding to the server to be processed can be scheduled according to the load type, thereby improving the task processing efficiency; by determining the processing core to be bound according to the processing core information, and binding the server to be processed with the processing core to be bound, the corresponding processing core can be bound to the task thread in each server to be processed, so that the task thread is executed in the bound processing core, avoiding multiple threads from occupying the same processing core, reducing task waiting time, improving task processing efficiency, and avoiding context switching loss and cache invalidation loss caused by threads switching back and forth between multiple processing cores, thereby improving CPU utilization.
[0123] Corresponding to the above method embodiment, this specification also provides a thread scheduling device embodiment, Figure 3 FIG. 1 shows a schematic diagram of the structure of a thread scheduling device provided by an embodiment of the present specification. Figure 3 As shown, the device comprises:
[0124] The acquisition module 302 is configured to acquire the load type of the server to be processed.
[0125] The determination module 304 is configured to determine the processing core information corresponding to the server to be processed according to the scheduling policy corresponding to the load type.
[0126] Binding module 306: is configured to determine the processing core to be bound according to the processing core information, and bind the server to be processed with the processing core to be bound, wherein the processing core to be bound executes the task thread corresponding to the server to be processed when bound with the server to be processed.
[0127] Optionally, the acquisition module 302 is further configured to:
[0128] Get the target game mode corresponding to the server to be processed;
[0129] Based on the load of the target game mode, determine the load type of the server to be processed.
[0130] Optionally, the determination module 304 is further configured to:
[0131] According to the scheduling strategy corresponding to the load type, the processing core type and processing core position relationship corresponding to the server to be processed are determined.
[0132] Optionally, the load type includes a low load type; the binding module 306 is further configured to:
[0133] According to the processing core types and the processing core position relationship, the first dedicated processing core and the target common processing core to be bound are determined.
[0134] Optionally, the load type includes a high load type; the binding module 306 is further configured to:
[0135] According to the processing core type and the processing core position relationship, the second dedicated processing core and the third dedicated processing core to be bound are determined, wherein the second dedicated processing core and the third dedicated processing core are adjacent to each other.
[0136] Optionally, the binding module 306 is further configured to:
[0137] Get the main thread and at least one auxiliary thread of the server to be processed;
[0138] The main thread and at least one auxiliary thread are respectively bound to the processing core to be bound.
[0139] Optionally, the load type of the server to be processed is a low load type, and the processing cores to be bound include the first dedicated processing core and the target public processing core; the binding module 306 is further configured to:
[0140] The main thread is bound to the first dedicated processing core, and at least one auxiliary thread is bound to the target common processing core.
[0141] Optionally, the load type of the server to be processed is a high load type, and the processing cores to be bound include the second dedicated processing core and the third dedicated processing core; the binding module 306 is further configured to:
[0142] The main thread is bound to the second dedicated processing core, and at least one auxiliary thread is bound to the third dedicated processing core, wherein the second dedicated processing core and the third dedicated processing core are located adjacent to each other.
[0143] By applying this embodiment, by determining the processing core information corresponding to the server to be processed according to the scheduling strategy corresponding to the load type, the task thread corresponding to the server to be processed can be scheduled according to the load type, thereby improving the task processing efficiency; by determining the processing core to be bound according to the processing core information, and binding the server to be processed with the processing core to be bound, the corresponding processing core can be bound to the task thread in each server to be processed, so that the task thread is executed in the bound processing core, avoiding multiple threads from occupying the same processing core, reducing task waiting time, improving task processing efficiency, and avoiding context switching loss and cache invalidation loss caused by threads switching back and forth between multiple processing cores, thereby improving CPU utilization.
[0144] The above is a schematic scheme of a thread scheduling device of this embodiment. It should be noted that the technical scheme of the thread scheduling device and the technical scheme of the thread scheduling method described above are of the same concept, and the details not described in detail in the technical scheme of the thread scheduling device can be found in the description of the technical scheme of the thread scheduling method described above.
[0145] Figure 4 The block diagram of a computing device 400 according to one embodiment of the present specification is shown. The components of the computing device 400 include but are not limited to a memory 410 and a processor 420. The processor 420 is connected to the memory 410 via a bus 430, and the database 450 is used to store data.
[0146] The computing device 400 also includes an access device 440 that enables the computing device 400 to communicate via one or more networks 460. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 440 may include one or more of any type of network interface, wired or wireless (e.g., a network interface card (NIC)), such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a World Wide Interoperability for Microwave Access (Wi-MAX) interface, an Ethernet interface, a Universal Serial Bus (USB) interface, a cellular network interface, a Bluetooth interface, and a Near Field Communication (NFC).
[0147] In one embodiment of the present specification, the above components of the computing device 400 and Figure 4 Other components not shown in the figure may also be connected to each other, for example, via a bus. It should be understood that Figure 4 The computing device structure block diagram shown is only for the purpose of illustration, and is not intended to limit the scope of this specification. Those skilled in the art can add or replace other components as needed.
[0148] The computing device 400 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smart phone), a wearable computing device (e.g., a smart watch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or a personal computer (PC). The computing device 400 may also be a mobile or stationary server.
[0149] The processor 420 is used to execute the following computer executable instructions, which implement the steps of the above-mentioned thread scheduling method when executed by the processor.
[0150] The above is a schematic scheme of a computing device of this embodiment. It should be noted that the technical scheme of the computing device and the technical scheme of the above thread scheduling method belong to the same concept, and the details not described in detail in the technical scheme of the computing device can be referred to the description of the technical scheme of the above thread scheduling method.
[0151] An embodiment of the present specification further provides a computer-readable storage medium storing computer-executable instructions, which can implement the steps of the above-mentioned thread scheduling method when executed by a processor.
[0152] The above is a schematic scheme of a computer-readable storage medium of this embodiment. It should be noted that the technical scheme of the storage medium and the technical scheme of the thread scheduling method described above are of the same concept, and the details not described in detail in the technical scheme of the storage medium can be found in the description of the technical scheme of the thread scheduling method described above.
[0153] An embodiment of the present specification also provides a computer program product, including a computer program / instruction, which implements the steps of the above-mentioned thread scheduling method when executed by a processor.
[0154] The above is a schematic solution of a computer program product of this embodiment. It should be noted that the technical solution of the computer program product and the technical solution of the thread scheduling method described above are of the same concept, and the details not described in detail in the technical solution of the computer program product can be found in the description of the technical solution of the thread scheduling method described above.
[0155] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0156] The computer instructions include computer program codes, which may be in source code form, object code form, executable files or some intermediate forms, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium may be appropriately increased or decreased according to the requirements of patent practice. For example, in some regions, according to patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0157] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the embodiments of this specification are not limited by the order of the actions described, because according to the embodiments of this specification, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the embodiments of this specification.
[0158] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0159] The preferred embodiments of this specification disclosed above are only used to help explain this specification. The optional embodiments do not describe all the details in detail, nor do they limit the invention to only the specific implementation methods described. Obviously, many modifications and changes can be made according to the content of the embodiments of this specification. This specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the embodiments of this specification, so that technicians in the relevant technical field can well understand and use this specification. This specification is only limited by the claims and their full scope and equivalents.
Claims
1. A thread scheduling method, characterized in that: include: Get the load type of the server to be processed; Determine the processing core information corresponding to the server to be processed according to the scheduling strategy corresponding to the load type; According to the processing core information, a processing core to be bound is determined, and the server to be processed is bound to the processing core to be bound, wherein the processing core to be bound executes the task thread corresponding to the server to be processed when bound to the server to be processed.
2. The method according to claim 1, characterized in that The obtaining of the load type of the server to be processed includes: Obtaining a target game mode corresponding to the server to be processed; Based on the load condition of the target game mode, determine the load type of the server to be processed.
3. The method according to claim 1, characterized in that The determining, according to the scheduling strategy corresponding to the load type, the processing core information corresponding to the server to be processed includes: According to the scheduling strategy corresponding to the load type, the processing core type and the processing core position relationship corresponding to the server to be processed are determined.
4. The method according to claim 3, characterized in that The load type includes a low load type; The determining, according to the processing core information, a processing core to be bound includes: According to the processing core type and the processing core position relationship, a first dedicated processing core and a target common processing core to be bound are determined.
5. The method according to claim 3, characterized in that: The load type includes a high load type; The determining, according to the processing core information, a processing core to be bound includes: According to the processing core type and the processing core position relationship, a second dedicated processing core and a third dedicated processing core to be bound are determined, wherein the second dedicated processing core and the third dedicated processing core are adjacent to each other.
6. The method according to any one of claims 1 to 5, characterized in that: The step of binding the to-be-processed server with the to-be-bound processing core includes: Obtain a main thread and at least one auxiliary thread of the server to be processed; The main thread and the at least one auxiliary thread are respectively bound to the processing core to be bound.
7. The method according to claim 6, characterized in that The load type of the server to be processed is a low load type, and the processing cores to be bound include a first dedicated processing core and a target public processing core; The step of respectively binding the main thread and the at least one auxiliary thread to the processing core to be bound comprises: The main thread is bound to the first dedicated processing core, and the at least one auxiliary thread is bound to the target common processing core.
8. The method according to claim 6, characterized in that The load type of the server to be processed is a high load type, and the processing cores to be bound include a second dedicated processing core and a third dedicated processing core; The step of respectively binding the main thread and the at least one auxiliary thread to the processing core to be bound comprises: The main thread is bound to the second dedicated processing core, and the at least one auxiliary thread is bound to the third dedicated processing core, wherein the second dedicated processing core and the third dedicated processing core are located adjacent to each other.
9. A thread scheduling device, characterized in that: include: An acquisition module is configured to acquire a load type of a server to be processed; A determination module, configured to determine the processing core information corresponding to the to-be-processed server according to the scheduling strategy corresponding to the load type; The binding module is configured to determine the processing core to be bound according to the processing core information, and bind the server to be processed with the processing core to be bound, wherein the processing core to be bound executes the task thread corresponding to the server to be processed when bound to the server to be processed.
10. A computing device, characterized in that: include: Memory and processor; The memory is used to store computer programs / instructions, and the processor is used to execute the computer programs / instructions. When the computer programs / instructions are executed by the processor, the steps of the thread scheduling method according to any one of claims 1 to 8 are implemented.
11. A computer-readable storage medium, characterized in that: It stores a computer program / instruction, which, when executed by a processor, implements the steps of the thread scheduling method described in any one of claims 1 to 8.
12. A computer program product, characterized in that The invention comprises a computer program / instruction, which, when executed by a processor, implements the steps of the thread scheduling method according to any one of claims 1 to 8.