CN107463441B - Thread quantity control method and equipment - Google Patents

Thread quantity control method and equipment Download PDF

Info

Publication number
CN107463441B
CN107463441B CN201710525715.2A CN201710525715A CN107463441B CN 107463441 B CN107463441 B CN 107463441B CN 201710525715 A CN201710525715 A CN 201710525715A CN 107463441 B CN107463441 B CN 107463441B
Authority
CN
China
Prior art keywords
current
thread number
thread
maximum
preset
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201710525715.2A
Other languages
Chinese (zh)
Other versions
CN107463441A (en
Inventor
李峰
王赟
刘宇宁
赵雨佳
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Datang Software Technologies Co Ltd
Original Assignee
Datang Software Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Datang Software Technologies Co Ltd filed Critical Datang Software Technologies Co Ltd
Priority to CN201710525715.2A priority Critical patent/CN107463441B/en
Publication of CN107463441A publication Critical patent/CN107463441A/en
Application granted granted Critical
Publication of CN107463441B publication Critical patent/CN107463441B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • G06F9/505Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the load

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Power Sources (AREA)
  • Stored Programmes (AREA)

Abstract

The invention provides a thread quantity control method and equipment, and belongs to the technical field of computers. The thread quantity control method and the equipment provided by the embodiment of the invention can obtain the current system environment parameters, then determine the maximum thread quantity according to the current system environment parameters, and can realize the real-time adjustment of the maximum thread quantity when the current system environment parameters change, namely, the running state of the system changes, thereby ensuring that the system resources can be reasonably utilized to the maximum extent, ensuring that the utilization rate of the system resources can be kept optimal, simultaneously avoiding the problem of unstable system caused by the overlarge number of established threads, and ensuring the stability of the system.

Description

Thread quantity control method and equipment
Technical Field
The invention belongs to the technical field of computers, and particularly relates to a thread quantity control method and equipment.
Background
In a computer system, various system resources are used for task processing, when a task needs to be processed, the system receives a request for accessing a specified system resource, establishes a thread for the request, and then processes the request by using the established thread. In order to fully utilize system resources, a multi-thread mode is usually adopted to implement parallel processing of multiple requests. However, the too high number of threads may cause too much resource consumption in unnecessary task operations due to resource contention, thread switching, etc., so that the system may be unstable due to too much resource consumption, which may affect the efficiency of processing the request. Therefore, the number of threads needs to be controlled to optimize resource utilization.
In the prior art, a maximum thread number is usually set when a system is started, and the currently established thread number is controlled not to be greater than the preset maximum thread number, so as to realize thread control.
However, when the system has a large operation load, if the threads are continuously established according to the maximum number of threads preset in the prior art, the number of established threads may be too large, which may cause instability of the system, and further affect the resource utilization rate of the system.
Disclosure of Invention
The invention provides a method and equipment for controlling the number of threads, which are used for solving the problem that the resource utilization rate of a system is influenced due to the fact that the system is unstable due to the fact that the number of the threads is too large.
According to a first aspect of the present invention, there is provided a thread quantity control method, the method comprising:
acquiring a current system environment parameter value;
matching the current system environment parameter values in a preset thread mapping table to determine the current maximum thread number; the preset thread mapping table is used for representing the corresponding relation between the system environment parameter value and the maximum thread number; the current maximum thread number is the maximum thread number that the system can operate in the current state.
Optionally, the current system environment parameter values include: the current CPU occupancy value, the current packet loss value and the current CPU temperature value;
the step of matching the current system environment parameter values in a preset thread mapping table to determine the current maximum thread number comprises:
respectively matching the current CPU occupancy value, the current packet loss value and the current CPU temperature value in a preset thread mapping table, and determining a first thread number corresponding to the current CPU occupancy value, a second thread number corresponding to the current packet loss value and a third thread number corresponding to the current CPU temperature value;
and determining the minimum thread number in the first thread number, the second thread number and the third thread number as the current maximum thread number.
Optionally, the method further includes:
when the system is started, the preset maximum thread number is determined according to the configuration file and is used as the current maximum thread number.
Optionally, the step of determining the preset maximum thread number according to the configuration file includes:
acquiring an initial thread number in an initial configuration sub-file in a configuration file;
when the system is started for the first time, determining the initial thread number as a preset maximum thread number;
and when the system is not started for the first time, extracting the thread number with the highest utilization rate in the intermediate configuration sub-file in the configuration file, and determining the thread number with the highest utilization rate as the preset maximum thread number.
Optionally, the method further includes:
when a task is to be established in the system, judging whether the current thread number is smaller than the current maximum thread number;
and if the current thread number is less than the current maximum thread number, establishing a corresponding thread for the task to be established.
According to a second aspect of the present invention, there is provided a thread quantity control apparatus comprising:
the acquisition module is used for acquiring the environmental parameter value of the current system;
the first determining module is used for matching the current system environment parameter values in a preset thread mapping table to determine the current maximum thread number; the preset thread mapping table is used for representing the corresponding relation between the system environment parameter value and the maximum thread number; the current maximum thread number is the maximum thread number that the system can operate in the current state.
Optionally, the first determining module includes:
the matching sub-module is used for respectively matching the current CPU occupancy value, the current packet loss value and the current CPU temperature value in a preset thread mapping table, and determining a first thread number corresponding to the current CPU occupancy value, a second thread number corresponding to the current packet loss value and a third thread number corresponding to the current CPU temperature value;
and the first determining submodule is used for determining the minimum thread number in the first thread number, the second thread number and the third thread number as the current maximum thread number.
Optionally, the apparatus further comprises:
and the second determining module is used for determining the preset maximum thread number according to the configuration file when the system is started, and the preset maximum thread number is used as the current maximum thread number.
Optionally, the second determining module includes:
the obtaining submodule is used for obtaining the initial thread number in the initial configuration subfile in the configuration file;
the second determining submodule is used for determining the initial thread number as a preset maximum thread number when the system is started for the first time;
and the third determining submodule is used for extracting the highest-utilization-rate thread number in the intermediate configuration subfile in the configuration file when the system is not started for the first time, and determining the highest-utilization-rate thread number as the preset maximum thread number.
Optionally, the apparatus further comprises:
the judging module is used for judging whether the current thread number is smaller than the current maximum thread number when a task is to be built in the system;
and the establishing module is used for establishing a corresponding thread aiming at the task to be established if the current thread number is less than the current maximum thread number.
Aiming at the prior art, the invention has the following advantages:
the thread quantity control method and the equipment provided by the invention can acquire the current system environment parameters, then determine the maximum thread quantity according to the current system environment parameters, and can realize the real-time adjustment of the maximum thread quantity when the current system environment parameters change, namely, the running state of the system changes, thereby ensuring that the system resources can be reasonably utilized to the maximum extent, ensuring that the utilization rate of the system resources can be kept optimal, simultaneously avoiding the problem of unstable system caused by the overlarge number of established threads, and ensuring the stability of the system.
The foregoing description is only an overview of the technical solutions of the present invention, and the embodiments of the present invention are described below in order to make the technical means of the present invention more clearly understood and to make the above and other objects, features, and advantages of the present invention more clearly understandable.
Drawings
Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating the preferred embodiments and are not to be construed as limiting the invention. Also, like reference numerals are used to refer to like parts throughout the drawings. In the drawings:
FIG. 1 is a flowchart illustrating steps of a thread count control method according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating steps of another thread count control method according to a second embodiment of the present invention;
fig. 3 is a block diagram of a thread quantity control device according to a third embodiment of the present invention;
fig. 4 is a block diagram of another thread quantity control apparatus according to a fourth embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the invention are shown in the drawings, it should be understood that the invention can be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the invention to those skilled in the art.
Example one
Fig. 1 is a flowchart illustrating steps of a thread quantity control method according to an embodiment of the present invention, as shown in fig. 1, the method may include:
step 101, obtaining a current system environment parameter value.
The current system environment parameter value in the embodiment of the invention can reflect the operation condition of the current system. In the embodiment of the invention, the current system environment parameter value can be periodically detected, and the current maximum thread number is further determined according to the current system environment parameter value by acquiring the current system environment parameter value. Wherein the current system environment parameter values may include: a current Central Processing Unit (CPU) occupancy value, a current packet loss value, and a current CPU temperature value. The CPU occupancy rate refers to CPU resources occupied by the system in operation, and represents the current operation condition of the system, and the higher the CPU occupancy rate is, the more CPU resources occupied by the current system in operation are indicated, otherwise, the less CPU occupancy rate is; the packet loss rate is the ratio of the number of lost packets to the number of transmitted packets when the system transmits data. In practical applications, the current system environment parameter value may further include other parameter values, such as memory occupancy rate, which is not limited in the embodiment of the present invention.
And 102, matching the current system environment parameter values in a preset thread mapping table, and determining the current maximum thread number.
The current maximum thread number is the maximum thread number which can be operated by the system in the current state, and the preset thread mapping table is used for representing the corresponding relation between the system environment parameter value and the maximum thread number.
Because the preset thread mapping table represents the corresponding relationship between the system environment parameter value and the maximum thread number, the current system environment parameter value can be matched in the mapping table to determine the current maximum thread number corresponding to the current system environment parameter.
In summary, the thread quantity control method provided in the embodiment of the present invention may obtain the current system environment parameter, and then determine the maximum thread quantity according to the current system environment parameter, when the current system environment parameter changes, that is, when the running state of the system changes, the maximum thread quantity may be adjusted in real time, thereby ensuring that the system resources may be utilized reasonably to the maximum extent, so that the utilization rate of the system resources may be kept optimal, and simultaneously avoiding the problem of system instability caused by the too large number of established threads, and ensuring the stability of the system.
Example two
Fig. 2 is a flowchart illustrating steps of another thread quantity control method according to a second embodiment of the present invention, as shown in fig. 2, the method may include:
step 201, when the system is started, determining a preset maximum thread number according to the configuration file to serve as a current maximum thread number.
The system in the embodiment of the invention is a computer system, wherein the computer system consists of two parts, namely computer hardware and software. The hardware part may include central processor, memory, peripheral equipment, etc. and the software part may be the running program and corresponding file of the computer. The computer system can receive and store information, quickly calculate and judge according to programs, and output processing results. The configuration file is typically stored on a local hard drive of the system, and may typically include a collection of settings and files for the user to use the system.
Since each environmental parameter of the system is 0 when the system is just started, the maximum thread number cannot be determined according to the current environmental parameter value of the system. Therefore, the preset maximum thread number needs to be determined according to the configuration file to serve as the current maximum thread number. The problem that the current maximum thread number cannot be determined according to the current system environment parameter value when the system is just started is solved, and the stability of the system is ensured.
Specifically, step 201 may include:
step 2011, obtain the initial thread number in the initial configuration subfile in the configuration file.
The configuration file may include an initial configuration subfile, which may be a file preset by the system in a development stage, and may be represented by "config _ default. The initial configuration subfile stores a preset initial thread number, which may be a reasonable value that a developer determines to ensure that the system can bear according to the hardware configuration of the system.
Step 2012, when the system is started up for the first time, the initial thread number is determined as the preset maximum thread number.
In the embodiment of the invention, the system is started for the first time, which means that the system is started for the first time and runs, and at the moment, the configuration file only comprises the initial configuration sub-file, so that the initial thread number in the initial configuration sub-file can be extracted and determined as the preset maximum thread number.
For example, assume that the contents of the initial configuration subfile are:
# default thread Start number
default_thread_count=5;
It can be seen that the preset initial thread number is 5, and at this time, 5 may be determined as the preset maximum thread number.
And 2013, when the system is not started for the first time, extracting the highest occupancy rate thread number in the intermediate configuration subfiles in the configuration files, and determining the highest occupancy rate thread number as a preset maximum thread number.
In the embodiment of the invention, when the system is not started for the first time, the system is operated before, and an intermediate configuration subfile is generated in the operation process of the system generally. Therefore, when the system is not booted for the first time, the configuration file of the system includes an intermediate configuration subfile generated in the previous running process, which may be denoted by "config _ run. The intermediate configuration subfile in the embodiment of the present invention may include historical data of the maximum number of threads used in the previous system operation process, and the number of threads with the highest occupancy rate in the previous system operation process may be determined according to the historical data. At this time, the occupancy-rate-highest thread number may be determined as a preset maximum thread number. In the embodiment of the invention, the maximum occupancy rate thread number is determined as the preset maximum thread number, and the maximum occupancy rate thread number is determined as the preset maximum thread number because the maximum occupancy rate thread number is more consistent with the actual situation, so that the set maximum thread number is more reasonable when the system is just started to operate, and the normal operation and the stability of the system are further ensured.
For example, assume that the contents of the intermediate configuration subfile are:
thread number used the most
max_rate_thread_count=3;
Number of # threads 5 detected times
thread_count_5=2;
Number of # threads 4 detected times
thread_count_4=14;
Number of # threads 3 detected times
thread_count_3=35;
Number of # threads 2 detected times
thread_count_2=32;
Number of times # thread number 1 was detected
thread_count_1=20;
It can be seen that the number of times of the thread number 3 is used is the largest, and the thread number with the highest occupancy rate can be determined to be 3, and at this time, 3 can be determined to be the preset maximum thread number.
Step 202, obtaining a current system environment parameter value.
For example, when obtaining the current CPU utilization value, the CPU utilization value may be determined according to the time occupied by the current thread of the system. Assume that the system currently includes two threads, thread a and thread B. In the current period, the thread A occupies 10 milliseconds (ms), the thread B occupies 30ms and is idle for 60ms, and then the operations are repeated, wherein the thread A occupies 10ms, the thread B occupies 30ms and is idle for 60 ms; then the current CPU utilization value may be determined to be 40%; when the current packet loss rate is obtained, the rate of data packets sent by a data packet station which are lost when data are sent in the current period can be detected, and if 100 data packets are sent in the current period and 2 data packets are lost, the current packet loss rate value can be determined to be 2%; when the current CPU temperature is obtained, the current temperature of the CPU can be detected through a temperature sensor in the system, and then the detected temperature is determined as the current CPU temperature value.
In the embodiment of the present invention, the current system environment parameter value may be obtained periodically, for example, the current system environment parameter value may be obtained every 5 minutes, before obtaining the parameter value, whether the system currently has an established thread may be detected, and if yes, the current system environment parameter value may be obtained; if not, wait for the next cycle. In the embodiment of the present invention, the specific time of the period is not limited, and may be set according to actual requirements when the period is specifically implemented. And a reasonable period time is set, so that the problem that the working of the system is influenced by frequently replacing the current maximum thread number can be avoided. After the current system environment parameter value is obtained, the current system environment parameter value may be written into an intermediate configuration subfile of the system. For example, assume that the obtained current system environment parameter values are: the CPU occupancy value is 35%, the current packet loss value is 5%, and the current CPU temperature value is 55 degrees celsius (° c). The above data may be written into the intermediate configuration subfile "config _ run.
And 203, matching the current system environment parameter values in a preset thread mapping table to determine the current maximum thread number.
For example, the current system environment parameter value obtained in the step 202 may be read from the intermediate configuration subfile "config _ run.ini" of the system, and then the read current system environment parameter value is used to perform matching in the preset thread map, so as to determine the current maximum thread number.
Specifically, step 203 may include:
step 2031, matching the current CPU occupancy value, the current packet loss value and the current CPU temperature value in a preset thread mapping table, and determining a first thread number corresponding to the current CPU occupancy value, a second thread number corresponding to the current packet loss value and a third thread number corresponding to the current CPU temperature value.
The matching sequence is not limited in the embodiment of the present invention, for example, when matching is performed, the current CPU occupancy value may be first matched in a preset thread mapping table, a first thread number corresponding to the current CPU occupancy is determined, then the current packet loss value is matched in the preset thread mapping table, a second thread number corresponding to the current packet loss value is determined, and finally the current CPU temperature value is matched in the preset thread mapping table, and a third thread number corresponding to the current CPU temperature value is determined. Or matching the current CPU occupancy value, the current packet loss value and the current CPU temperature value in a preset thread mapping table, and determining a first thread number, a second thread number and a third thread number corresponding to the three parameter values respectively.
For example, assume that the preset thread mapping table is as follows:
maximum number of threads CPU occupancy (%) Packet loss ratio (%) CPU temperature (. degree.C.)
5 0-19 0-9 0-39
4 20-29 10-19 40-59
3 30-39 20-39 60-69
2 40-69 40-84 70-74
1 70-89 85-94 75-79
0 90-100 95-100 80-85
Preset thread mapping table
Assuming that the CPU occupancy rate is located in the column in the table, each row from top to bottom represents a first parameter interval of the CPU occupancy rate, a second parameter interval of the CPU occupancy rate, a third parameter interval of the CPU occupancy rate, a fourth parameter interval of the CPU occupancy rate and a fifth parameter interval of the CPU occupancy rate respectively; by analogy, each row of the columns where the packet loss rates are located from top to bottom respectively represents a first parameter interval of the packet loss rate value, a second parameter interval of the packet loss rate value, a third parameter interval of the packet loss rate value, a fourth parameter interval of the packet loss rate value and a fifth parameter interval of the packet loss rate value; and each row of the CPU temperature respectively represents a first parameter interval of the CPU temperature value, a second parameter interval of the CPU temperature value, a third parameter interval of the CPU temperature value, a fourth parameter interval of the CPU temperature value and a fifth parameter interval of the CPU temperature value from top to bottom. As can be seen from the above table, each parameter interval corresponds to a maximum number of threads.
Specifically, during matching, a parameter interval to which the current system environment parameter value belongs may be determined in a preset thread mapping table, and then a maximum thread number corresponding to the parameter interval to which the current system environment parameter value belongs may be determined as the thread number corresponding to the current system environment parameter value.
With the current system environment parameter values obtained in step 202 above: the current CPU occupancy rate is 35%, the current packet loss is 5%, and the current CPU temperature is 55 ℃, for example, by matching the CPU occupancy rate of 35% in the table, it is determined that the parameter interval to which the current CPU occupancy rate value belongs is within a third parameter interval "30-39" of the CPU occupancy rate value, and the maximum thread number 3 corresponding to the third parameter interval of the CPU occupancy rate value can be determined as the first thread number corresponding to the current CPU occupancy rate value; by matching the packet loss rate of 5% in the table, it is determined that the parameter interval to which the current packet loss rate value belongs is within a first parameter interval "0-9" of the packet loss rate value, and the maximum thread number 5 corresponding to the first parameter interval of the packet loss rate value can be determined as the second thread number corresponding to the current packet loss rate value; the CPU temperature is matched in the table at 55 ℃, the parameter interval to which the current CPU temperature value belongs is determined to be within the second parameter interval '40-59' of the CPU temperature value, and the maximum thread number 4 corresponding to the second parameter interval of the CPU temperature value can be determined to be the third thread number corresponding to the current CPU temperature value.
Step 2032, determining the minimum thread number of the first thread number, the second thread number and the third thread number as the current maximum thread number.
In the embodiment of the invention, the minimum thread number in the first thread number, the second thread number and the third thread number is determined as the current maximum thread number, so that the system can be ensured to stably run when running by the current maximum thread number. For example, if the first thread number determined according to the current CPU occupancy value is 3, the second thread number determined according to the current packet loss value is 4, the third thread number determined according to the current CPU temperature value is 5, and if the minimum thread number is not selected as the current maximum thread number, and if 5 is determined as the current maximum thread number, when the system runs with the maximum thread number of 5, the CPU occupancy and the packet loss rate may be higher, and a system is jammed, which may cause the system to be more unstable. Therefore, the minimum thread number, i.e. the first thread number 3 is determined as the current maximum thread number, so that the system can be ensured to keep a stable state when running at the maximum thread number 3.
The above process of determining the current maximum number of threads according to the current system environment parameters can be expressed in the form of a formula:
M=min(mach(′cpu′,cpu_value)mach(′PacketLossRate′,plr_value),mach(′tem perature′,tmp_value));
wherein "M" represents the current maximum number of threads; min (, denotes taking the minimum function, and mach (, is the matching function); "mach (' CPU ', CPU _ value) ' indicates that the current CPU occupancy value is matched in a preset thread mapping table, and a corresponding first thread number is determined; "map ('PacketLossRate', plr _ value)" indicates that the current packet loss rate value is matched in the preset thread mapping table, and determines the corresponding second thread number; "map (" temperature, "tmp _ value)" indicates that the current CPU temperature value is matched in the preset thread mapping table, and the corresponding third thread number is determined.
It should be noted that, in the embodiment of the present invention, after the current maximum thread number is determined, the current maximum thread number may be recorded in the intermediate configuration sub-file, so that the thread number with the highest occupancy rate may be counted under the recording of the current maximum thread number determined in each cycle, and is used as a data basis of the initial maximum thread number determined when the system is started.
And step 204, when the system has tasks to be built, judging whether the current thread number is smaller than the current maximum thread number.
The current thread number represents the thread number which is established by the system at present, and the current maximum thread number represents the thread number which can be established by the system at most at present. If the current thread number is less than the current maximum thread number, the system can also carry more threads at the moment. For example, the system may periodically detect whether a task is to be set up in the system, for example, the period duration may be 2 minutes. If the task to be built is detected, whether the current thread number is smaller than the current maximum thread number can be further judged; and if the task to be built is not detected, waiting for the next period.
And step 205, if the current thread number is smaller than the current maximum thread number, establishing a corresponding thread for the task to be established.
For example, suppose that there is task a to be created in the system, the current thread number is 3, and the current maximum thread number is 4. Because the current thread number 3 is less than the current maximum thread number 4, a corresponding new thread can be established for the task a to be established. In the embodiment of the invention, when the corresponding thread is established for the task to be established, the size relation between the current thread number and the current maximum thread number is compared, and whether a new thread is established or not is further determined. Therefore, the current thread number of the system can be ensured not to exceed the maximum thread number, and the stable operation of the system is ensured. In practical application, the embodiment of the invention can be realized by utilizing C development language based on a raspberry host computer. Therefore, the realization cost is low, the codes are relatively simplified, and the execution efficiency is high. Specifically, other types of computers may be used, for example, a computer based on a linux system or a computer based on a windows system, which is not limited by the embodiment of the present invention.
In summary, in the method for controlling thread count according to the second embodiment of the present invention, when the system is started, the preset maximum thread count may be determined according to the configuration file, so as to serve as the current maximum thread count. The problem that the current maximum thread number cannot be determined according to the current system environment parameter value when the system is just started is solved, and the stability of the system is ensured; meanwhile, in the operation process, the current system environment parameters can be obtained, then the maximum thread number is determined according to the current system environment parameters, when the current system environment parameters change, namely the operation state of the system changes, the real-time adjustment of the maximum thread number can be realized, the system resources can be reasonably utilized to the maximum extent, the utilization rate of the system resources can be kept optimal, the problem that the system is unstable due to the fact that the number of the established threads is too large is avoided, and the stability of the system is ensured; when a corresponding thread is established for a task to be established, the size relationship between the current thread number and the current maximum thread number is compared, and whether a new thread is established or not is determined. Therefore, the current thread number of the system can be ensured not to exceed the maximum thread number, and the stable operation of the system is further ensured.
EXAMPLE III
Fig. 3 is a block diagram of a thread quantity control apparatus according to a third embodiment of the present invention, and as shown in fig. 3, the apparatus 30 may include:
an obtaining module 301, configured to obtain a current system environment parameter value.
A first determining module 302, configured to match the current system environment parameter value in a preset thread mapping table, and determine a current maximum thread number; the preset thread mapping table is used for representing the corresponding relation between the system environment parameter value and the maximum thread number; the current maximum thread number is the maximum thread number that the system can operate in the current state.
In summary, the thread quantity control device provided in the third embodiment of the present invention may obtain the current system environment parameter, and then determine the maximum thread quantity according to the current system environment parameter, when the current system environment parameter changes, that is, when the running state of the system changes, the maximum thread quantity may be adjusted in real time, which ensures that the system resources may be utilized reasonably to the maximum extent, so that the utilization rate of the system resources may be kept optimal, and simultaneously, the problem of system instability due to the too large number of established threads is avoided, and the stability of the system is ensured.
Example four
Fig. 4 is a block diagram of another thread quantity control apparatus according to a fourth embodiment of the present invention, and as shown in fig. 4, the apparatus 40 may include:
an obtaining module 401, configured to obtain a current system environment parameter value.
A first determining module 402, configured to match the current system environment parameter value in a preset thread mapping table, and determine a current maximum thread number; the preset thread mapping table is used for representing the corresponding relation between the system environment parameter value and the maximum thread number; the current maximum thread number is the maximum thread number that the system can operate in the current state.
The second determining module 403 is configured to determine, according to the configuration file, a preset maximum thread count as a current maximum thread count when the system is powered on.
The determining module 404 is configured to determine whether the current thread count is smaller than the current maximum thread count when a task is to be created in the system.
An establishing module 405, configured to establish a corresponding thread for the task to be established if the current thread number is smaller than the current maximum thread number.
Optionally, the first determining module 402 may include:
and the matching sub-module is used for respectively matching the current CPU occupancy value, the current packet loss value and the current CPU temperature value in a preset thread mapping table, and determining a first thread number corresponding to the current CPU occupancy value, a second thread number corresponding to the current packet loss value and a third thread number corresponding to the current CPU temperature value.
And the first determining submodule is used for determining the minimum thread number in the first thread number, the second thread number and the third thread number as the current maximum thread number.
Optionally, the second determining module 403 may include:
and the obtaining submodule is used for obtaining the initial thread number in the initial configuration subfile in the configuration file.
And the second determining submodule is used for determining the initial thread number as the preset maximum thread number when the system is started for the first time.
And the third determining submodule is used for extracting the highest-utilization-rate thread number in the intermediate configuration subfile in the configuration file when the system is not started for the first time, and determining the highest-utilization-rate thread number as the preset maximum thread number.
In summary, the thread count control device according to the fourth embodiment of the present invention may determine the preset maximum thread count according to the configuration file when the system is started, so as to serve as the current maximum thread count. The problem that the current maximum thread number cannot be determined according to the current system environment parameter value when the system is just started is solved, and the stability of the system is ensured; meanwhile, in the operation process, the current system environment parameters can be obtained, then the maximum thread number is determined according to the current system environment parameters, when the current system environment parameters change, namely the operation state of the system changes, the real-time adjustment of the maximum thread number can be realized, the system resources can be reasonably utilized to the maximum extent, the utilization rate of the system resources can be kept optimal, the problem that the system is unstable due to the fact that the number of the established threads is too large is avoided, and the stability of the system is ensured; when a corresponding thread is established for a task to be established, the size relationship between the current thread number and the current maximum thread number is compared, and whether a new thread is established or not is determined. Therefore, the current thread number of the system can be ensured not to exceed the maximum thread number, and the stable operation of the system is further ensured.
For the above device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and for the relevant points, refer to the partial description of the method embodiment.
The embodiments in the present specification are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
As is readily imaginable to the person skilled in the art: any combination of the above embodiments is possible, and thus any combination between the above embodiments is an embodiment of the present invention, but the present disclosure is not necessarily detailed herein for reasons of space.
The thread quantity control methods provided herein are not inherently related to any particular computer, virtual system, or other apparatus. Various general purpose systems may also be used with the teachings herein. The structure required to construct a system incorporating aspects of the present invention will be apparent from the description above. Moreover, the present invention is not directed to any particular programming language. It is appreciated that a variety of programming languages may be used to implement the teachings of the present invention as described herein, and any descriptions of specific languages are provided above to disclose the best mode of the invention.
In the description provided herein, numerous specific details are set forth. It is understood, however, that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure an understanding of this description.
Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the invention and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be interpreted as reflecting an intention that: that the invention as claimed requires more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of this invention.
Those skilled in the art will appreciate that the modules in the device in an embodiment may be adaptively changed and disposed in one or more devices different from the embodiment. The modules or units or components of the embodiments may be combined into one module or unit or component, and furthermore they may be divided into a plurality of sub-modules or sub-units or sub-components. All of the features disclosed in this specification (including any accompanying claims, abstract and drawings), and all of the processes or elements of any method or apparatus so disclosed, may be combined in any combination, except combinations where at least some of such features and/or processes or elements are mutually exclusive. Each feature disclosed in this specification (including any accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
Furthermore, those skilled in the art will appreciate that while some embodiments described herein include some features included in other embodiments, rather than other features, combinations of features of different embodiments are meant to be within the scope of the invention and form different embodiments. For example, in the claims, any of the claimed embodiments may be used in any combination.
The various component embodiments of the invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It will be appreciated by those skilled in the art that a microprocessor or Digital Signal Processor (DSP) may be used in practice to implement some or all of the functions of some or all of the components of the method of identifying background music in video according to embodiments of the present invention. The present invention may also be embodied as apparatus or device programs (e.g., computer programs and computer program products) for performing a portion or all of the methods described herein. Such programs implementing the present invention may be stored on computer-readable media or may be in the form of one or more signals. Such a signal may be downloaded from an internet website or provided on a carrier signal or in any other form.
It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention may be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means may be embodied by one and the same item of hardware. The usage of the words first, second and third, etcetera do not indicate any ordering. These words may be interpreted as names.

Claims (6)

1. A method for thread count control, the method comprising:
acquiring a current system environment parameter value;
matching the current system environment parameter values in a preset thread mapping table to determine the current maximum thread number; the preset thread mapping table is used for representing the corresponding relation between the system environment parameter value and the maximum thread number; the current maximum thread number is the maximum thread number which can be operated by the system in the current state;
when a task is to be established in the system, judging whether the current thread number is smaller than the current maximum thread number;
if the current thread number is smaller than the current maximum thread number, establishing a corresponding thread for the task to be established;
wherein the current system environment parameter values include: the current CPU occupancy value, the current packet loss value and the current CPU temperature value;
the step of matching the current system environment parameter values in a preset thread mapping table to determine the current maximum thread number comprises:
respectively matching the current CPU occupancy value, the current packet loss value and the current CPU temperature value in a preset thread mapping table, and determining a first thread number corresponding to the current CPU occupancy value, a second thread number corresponding to the current packet loss value and a third thread number corresponding to the current CPU temperature value;
and determining the minimum thread number in the first thread number, the second thread number and the third thread number as the current maximum thread number.
2. The method of claim 1, further comprising:
when the system is started, the preset maximum thread number is determined according to the configuration file and is used as the current maximum thread number.
3. The method of claim 2, wherein the step of determining the preset maximum number of threads according to the configuration file comprises:
acquiring an initial thread number in an initial configuration sub-file in a configuration file;
when the system is started for the first time, determining the initial thread number as a preset maximum thread number;
and when the system is not started for the first time, extracting the thread number with the highest utilization rate in the intermediate configuration sub-file in the configuration file, and determining the thread number with the highest utilization rate as the preset maximum thread number.
4. A thread count control apparatus, characterized in that the apparatus comprises:
the acquisition module is used for acquiring the environmental parameter value of the current system;
the first determining module is used for matching the current system environment parameter values in a preset thread mapping table to determine the current maximum thread number; the preset thread mapping table is used for representing the corresponding relation between the system environment parameter value and the maximum thread number; the current maximum thread number is the maximum thread number which can be operated by the system in the current state;
wherein the first determining module comprises:
the matching sub-module is used for respectively matching the current CPU occupancy value, the current packet loss value and the current CPU temperature value in a preset thread mapping table, and determining a first thread number corresponding to the current CPU occupancy value, a second thread number corresponding to the current packet loss value and a third thread number corresponding to the current CPU temperature value;
the first determining submodule is used for determining the minimum thread number in the first thread number, the second thread number and the third thread number as the current maximum thread number;
the judging module is used for judging whether the current thread number is smaller than the current maximum thread number when a task is to be built in the system;
and the establishing module is used for establishing a corresponding thread aiming at the task to be established if the current thread number is less than the current maximum thread number.
5. The apparatus of claim 4, further comprising:
and the second determining module is used for determining the preset maximum thread number according to the configuration file when the system is started, and the preset maximum thread number is used as the current maximum thread number.
6. The apparatus of claim 5, wherein the second determining module comprises:
the obtaining submodule is used for obtaining the initial thread number in the initial configuration subfile in the configuration file;
the second determining submodule is used for determining the initial thread number as a preset maximum thread number when the system is started for the first time;
and the third determining submodule is used for extracting the highest-utilization-rate thread number in the intermediate configuration subfile in the configuration file when the system is not started for the first time, and determining the highest-utilization-rate thread number as the preset maximum thread number.
CN201710525715.2A 2017-06-30 2017-06-30 Thread quantity control method and equipment Active CN107463441B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710525715.2A CN107463441B (en) 2017-06-30 2017-06-30 Thread quantity control method and equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710525715.2A CN107463441B (en) 2017-06-30 2017-06-30 Thread quantity control method and equipment

Publications (2)

Publication Number Publication Date
CN107463441A CN107463441A (en) 2017-12-12
CN107463441B true CN107463441B (en) 2020-10-27

Family

ID=60544089

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710525715.2A Active CN107463441B (en) 2017-06-30 2017-06-30 Thread quantity control method and equipment

Country Status (1)

Country Link
CN (1) CN107463441B (en)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109471716A (en) * 2018-09-26 2019-03-15 努比亚技术有限公司 A kind of application thread processing method, terminal and computer readable storage medium
CN109840141B (en) * 2018-12-15 2024-05-03 平安科技(深圳)有限公司 Thread control method and device based on cloud monitoring, electronic equipment and storage medium
CN109840142B (en) * 2018-12-15 2024-03-15 平安科技(深圳)有限公司 Thread control method and device based on cloud monitoring, electronic equipment and storage medium
CN109684228B (en) * 2019-01-07 2022-07-05 武汉斗鱼鱼乐网络科技有限公司 Performance test method, device, system and storage medium
CN111049914B (en) * 2019-12-18 2021-02-09 珠海格力电器股份有限公司 Load balancing method and device and computer system
CN114138469B (en) * 2021-11-16 2023-11-14 苏州浪潮智能科技有限公司 Thread self-adaptive distribution method and device for solid state disk and solid state disk

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102779062A (en) * 2011-05-09 2012-11-14 阿里巴巴集团控股有限公司 Method and device for controlling number of threads accessing system resources
CN103888279A (en) * 2012-12-20 2014-06-25 阿里巴巴集团控股有限公司 Resource pool dynamic management method and system based on feedback control cycle
CN105630606A (en) * 2015-12-22 2016-06-01 山东中创软件工程股份有限公司 Method and device for adjusting capacity of thread pools
WO2016150183A1 (en) * 2015-03-24 2016-09-29 Huawei Technologies Co., Ltd. System and method for parallel optimization of database query using cluster cache
CN106557369A (en) * 2016-11-25 2017-04-05 武汉斗鱼网络科技有限公司 A kind of management method and system of multithreading

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102779062A (en) * 2011-05-09 2012-11-14 阿里巴巴集团控股有限公司 Method and device for controlling number of threads accessing system resources
CN103888279A (en) * 2012-12-20 2014-06-25 阿里巴巴集团控股有限公司 Resource pool dynamic management method and system based on feedback control cycle
WO2016150183A1 (en) * 2015-03-24 2016-09-29 Huawei Technologies Co., Ltd. System and method for parallel optimization of database query using cluster cache
CN105630606A (en) * 2015-12-22 2016-06-01 山东中创软件工程股份有限公司 Method and device for adjusting capacity of thread pools
CN106557369A (en) * 2016-11-25 2017-04-05 武汉斗鱼网络科技有限公司 A kind of management method and system of multithreading

Also Published As

Publication number Publication date
CN107463441A (en) 2017-12-12

Similar Documents

Publication Publication Date Title
CN107463441B (en) Thread quantity control method and equipment
EP3255553B1 (en) Transmission control method and device for direct memory access
USRE49781E1 (en) Method for reducing execution jitter in multi-core processors within an information handling system
US9619289B2 (en) Workload optimized server for intelligent algorithm trading platforms
RU2639353C2 (en) Method and device for sending tips as a message
US10348815B2 (en) Command process load balancing system
US11144330B2 (en) Algorithm program loading method and related apparatus
US20170201566A1 (en) File downloading method, apparatus, and terminal device
US20170093963A1 (en) Method and Apparatus for Allocating Information and Memory
WO2017107843A1 (en) Periodic task processing method and apparatus, computer program, and readable medium
CN102708006A (en) Processing optimization load adjustment
KR20200084707A (en) Master device for managing distributed processing of task, task processing device for processing task and method for operating thereof
CN112908321A (en) Device control method, device, storage medium, and electronic apparatus
JP2020053013A (en) Request processing method and device
CN111782409A (en) Task processing method, risk identification task processing device and electronic equipment
CN115827253A (en) Chip resource calculation allocation method, device, equipment and storage medium
CN102622274B (en) Computer device and interrupt task allocation method thereof
CN108833532B (en) Service processing method, device and system based on Internet of things
US20220188153A1 (en) System and method of executing task of operating system for vehicle
CN104182264B (en) The start optimization method and its device of a kind of eMMC
US20140139533A1 (en) Graphic processing unit virtual apparatus, graphic processing unit host apparatus, and graphic processing unit program processing methods thereof
CN110019448B (en) Data interaction method and device
CN103197959A (en) Switching method of multi-core CPUs (Central Processing Unit)
CN111078293B (en) Operation method, device and related product
US9740660B2 (en) CPU control method, electronic system control method and electronic system for improved CPU utilization in executing functions

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant