Disclosure of Invention
In order to improve code auditing efficiency, the application provides a code auditing method, a device, a terminal and a storage medium.
In a first aspect, the present application provides a code auditing method, which adopts the following technical scheme:
a code auditing method that provides a plurality of servers for tasks of processing code audits, the method comprising:
acquiring current task information to be processed;
acquiring working condition information of each server;
selecting a server to be processed according to a preset rule based on the working condition information;
and sending the current task information to be processed to the server to be processed.
By adopting the technical scheme, a plurality of servers are set to simultaneously carry out code auditing, and if a new code auditing task appears, the server to which the servers are allocated to execute code auditing is determined according to the working condition information of each server, so that the code auditing efficiency is improved.
Optionally, the working condition information includes the number of tasks to be processed, a CPU occupancy rate, or a memory occupancy rate.
By adopting the technical scheme, the working condition information of each server can comprise the number of tasks to be processed, the CPU occupation rate or the memory occupation rate and other information, and the actual working condition of each server can be objectively evaluated by acquiring and judging the information, so that the audit task is distributed according to the actual working condition.
Optionally, the selecting a server to be processed according to a preset rule based on the working condition information includes: selecting a server with a small number of tasks to be processed as the server to be processed according to the number of the tasks to be processed of each server; or according to the CPU occupancy rate of each server, selecting a server with a smaller CPU occupancy rate as the server to be processed; or according to the memory occupancy of each server, selecting the server with smaller memory occupancy as the server to be processed.
By adopting the technical scheme, the server with smaller current workload is corresponding to the smaller number of the tasks to be processed, the smaller CPU occupancy or the smaller memory occupancy, and the newly added tasks are distributed to the server with smaller current workload, so that the whole code auditing efficiency is improved.
Optionally, the selecting a server to be processed according to a preset rule based on the working condition information includes: and selecting the server with higher weighted sum as the server to be processed according to the weighted sum of the number of tasks to be processed, the CPU occupation ratio and the memory occupation ratio of each server.
By adopting the technical scheme, the current workload of each server cannot be objectively reflected by single information such as the number of tasks to be processed, the CPU occupancy rate and the memory occupancy rate, and the current workload of each server can be objectively reflected by summing the information according to a certain weight, so that the code auditing efficiency is further improved.
Optionally, the working condition information includes an average processing speed, and the selecting a server to be processed according to a preset rule based on the working condition information includes: and selecting the server with the higher average processing speed as the server to be processed according to the average processing speed of each server.
By adopting the technical scheme, different servers are different in configuration and performance, the higher the configuration or the better the performance, the higher the average processing speed of the server is, the code audit task can be quickly processed, the code audit task is preferentially distributed to the server with the higher average processing speed, and the code audit efficiency can be further improved.
Optionally, at the time of first allocation, the speed of the average processing speed is determined by the configuration of the server.
By adopting the technical scheme, the average processing speed can be obtained only after the server processes one or more audit tasks, so that the speed of the average processing speed can be determined by the configuration of the server when the server is allocated for the first time, and the higher the configuration is, the faster the corresponding average processing speed is.
Optionally, the working condition information includes the number of tasks to be processed, and before the selecting a server to be processed according to a preset rule based on the working condition information, the method further includes: and judging whether the number of the tasks to be processed of each server is not less than a preset permission limit threshold, if not, sending the information of the current tasks to be processed to a queue for waiting, and suspending to continuously acquire the information of the current tasks to be processed.
By adopting the technical scheme, when code auditing is carried out, a maximum resource occupation amount is set, whether the number of the tasks to be processed of each server is not less than a preset permission limit threshold value or not is judged, if not, the information of the current tasks to be processed is sent to a queue to wait, and the information of the current tasks to be processed is suspended to continue to be obtained, so that the processing efficiency of the ongoing code auditing tasks is not influenced.
In a second aspect, the present application further provides a code auditing apparatus, which adopts the following technical scheme:
a code auditing apparatus, comprising:
a memory for storing a code auditing program;
and the processor executes the steps of the code auditing method when the code auditing program is run.
By adopting the technical scheme, the code auditing method is presented and stored in the memory in the form of the computer readable code, and the steps of the code auditing method are executed when the processor runs the computer readable code in the memory, so that the code auditing efficiency can be improved.
In a third aspect, the present application further provides a code auditing terminal, which adopts the following technical scheme:
a code auditing terminal, comprising:
the input device is used for inputting the current task information to be processed;
the servers are used for receiving and providing code auditing service according to the current task information to be processed;
the input end of the code auditing device is connected with the input device, and the output end of the code auditing device is connected with a plurality of servers.
By adopting the technical scheme, the terminal inputs the current task information to be processed by means of the input device, the collected signals are combined to determine which server is allocated to execute code audit through the working condition information of each server through the program in the terminal, and the code audit efficiency can be improved.
In a fourth aspect, the present application further provides a computer-readable storage medium, which adopts the following technical solutions:
a computer readable storage medium storing a computer program capable of being loaded by a processor and executing the code auditing method described above.
To sum up, this application carries out the code audit simultaneously through setting up many servers, if new code audit task appears, then confirms to which server execution code audit distributes through the behavior information of each server to improve code audit efficiency.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is further described in detail below with reference to fig. 1-2 and the embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
The following describes in further detail an embodiment of the code audit terminal of the present application with reference to the drawings of the specification.
The embodiment of the application provides a code auditing terminal, as shown in fig. 1, the terminal comprises aninput device 1, acode auditing device 2 and a plurality ofservers 3, wherein the input end of thecode auditing device 2 is connected with theinput device 1, and the output end of thecode auditing device 2 is connected with the plurality ofservers 3; thecode auditing device 2 is integrated with a memory and a processor, the memory is used for storing a code auditing program, and the processor is used for executing the steps of the code auditing method when the code auditing program is run; the input device is used for inputting the information of the current task to be processed, and the plurality ofservers 3 are used for receiving and providing code auditing service according to the information of the current task to be processed.
The following is a detailed description of the implementation of the code auditing method:
the embodiment of the application discloses a code auditing method, which comprises the steps of providing a plurality of servers for processing code auditing tasks, and determining which server is allocated to execute code auditing according to the working condition information of each server if a new code auditing task occurs, thereby improving the code auditing efficiency. Referring to fig. 2, the code auditing method includes the steps of:
s01: and acquiring the current task information to be processed.
Specifically, the current task information to be processed can be input by a code auditor through an input device, can also be issued by an external system, and can be selected according to actual conditions.
S02: and acquiring the working condition information of each server.
Specifically, the working condition information may include one or more of an average processing speed, the number of tasks to be processed, a CPU occupancy rate, or a memory occupancy rate, and by obtaining and judging the information, the actual working condition of each server can be objectively evaluated, so that the audit task is distributed according to the actual working condition.
S03: and selecting a server to be processed according to a preset rule based on the working condition information.
There are various ways for specifically selecting the server to be processed, and the corresponding preset rules are different according to different contents contained in the working condition information.
In an embodiment of the present application, the working condition information includes only one of an average processing speed, a number of tasks to be processed, a CPU occupancy rate, or a memory occupancy rate, and when the working condition information includes only the average processing speed, the average processing speeds corresponding to the servers are compared, and a server with a higher average processing speed is selected as the server to be processed; when the working condition information only comprises the number of the tasks to be processed, comparing the number of the tasks to be processed corresponding to each server, and selecting the server with less number of the tasks to be processed as the server to be processed; when the working condition information only comprises the CPU occupancy, comparing the CPU occupancy corresponding to each server, and selecting the server with smaller CPU occupancy as the server to be processed; and when the working condition information only comprises the memory occupancy, comparing the memory occupancy corresponding to each server, and selecting the server with smaller memory occupancy as the server to be processed. The server with smaller current workload is corresponding to the smaller number of tasks to be processed, the smaller CPU occupancy or the smaller memory occupancy, and the newly added tasks are distributed to the server with smaller current workload, so that the whole code auditing efficiency is improved.
The average processing speed can be obtained after the server processes one or more audit tasks, so that the speed of the average processing speed can be determined by the configuration of the server when the server is allocated for the first time, the higher the configuration is, the higher the corresponding average processing speed is, the higher the configuration is, or the higher the performance is, the higher the average processing speed of the server is, the code audit task can be processed quickly, the code audit task is preferentially allocated to the server with the higher average processing speed, and the code audit efficiency can be further improved.
In another embodiment of the present application, the working condition information includes the number of tasks to be processed, the CPU occupancy and the memory occupancy, and a server with a higher weighted sum may be selected as the server to be processed according to the weighted sum of the number of tasks to be processed, the CPU occupancy and the memory occupancy of each server.
Assuming that the weight of the number of the tasks to be processed is 0.4, the weight of the CPU occupancy is 0.3, and the weight of the memory occupancy is 0.3, wherein the score is lower when the number of the tasks to be processed is larger, for example, the score is 100 when the number of the tasks to be processed is 0, the score is 90 when the number of the tasks to be processed is 1, and so on; the higher the CPU occupancy, the lower the corresponding score, for example, the score is 100 when the CPU occupancy is 0%, the score is 90 when the CPU occupancy is 10%, and so on; the higher the memory occupancy, the lower the corresponding score, for example, the score is 100 when the memory occupancy is 0%, the score is 90 when the memory occupancy is 10%, and so on; thus, calculating the weighted sum of the number of tasks to be processed, the CPU occupation ratio and the memory occupation ratio, and selecting the server with higher weighted sum as the server to be processed; for example, if the number of tasks to be processed of the first server is 1 (corresponding to score 90), the CPU occupancy is 20% (corresponding to score 80), and the memory occupancy is 20% (corresponding to score 80), the number of tasks to be processed of the second server is 2 (corresponding to score 80), the CPU occupancy is 10% (corresponding to score 90), and the memory occupancy is 10% (corresponding to score 90), the weighted sum of the first server is 0.4 × 90+0.3 × 80=84, and the weighted sum of the second server is 0.4 × 80+0.3 × 90=86, and thus the second server with the higher weighted sum is selected as the server to be processed.
S04: and sending the current task information to be processed to a server to be processed.
In the related technology, all tasks are sequentially put into a server for processing according to a time sequence, the prior audit task needs more time for processing, and the prior audit task needs less time for processing is delayed, so that the audit efficiency is low. In the application, the server which is most suitable for processing the current task information to be processed is selected in the steps, the current task information to be processed is sent to the server to be processed to perform the code audit task, the task to be processed can be completed as soon as possible, and therefore the audit efficiency is improved.
In another embodiment of the present application, before step S03, the method further includes: and judging whether the number of the tasks to be processed of each server is not less than a preset permission limit threshold, if not, sending the information of the current tasks to be processed to a queue for waiting, and suspending the continuous acquisition of the information of the current tasks to be processed, thereby ensuring that the processing efficiency of the ongoing code audit task is not influenced.
For example, assuming that the preset permission limit threshold is 3, when the number of the tasks to be processed in all the servers is 3, it indicates that the number (3) of the tasks to be processed in each server is not less than the preset permission limit threshold (3), at this time, the information of the current tasks to be processed is sent to the queue to wait, and the current tasks to be processed are suspended from being continuously obtained, when the number of the tasks to be processed in one or more of the servers is less than the preset permission limit threshold, the information of the current tasks to be processed is extracted from the queue, and is sent to the server corresponding to the server whose number of the tasks to be processed is less than the preset permission limit threshold to be processed, and the current tasks to be processed are resumed to be continuously obtained.
Based on the same inventive concept, embodiments of the present application provide a computer-readable storage medium, which includes instructions that, when being loaded and executed by a processor, implement the steps in the code auditing method flow.
The computer-readable storage medium includes, for example: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
It will be clear to those skilled in the art that, for convenience and simplicity of description, the foregoing division of the functional modules is merely used as an example, and in practical applications, the above function distribution may be performed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to perform all or part of the above described functions. For the specific working processes of the system, the apparatus and the unit described above, reference may be made to the corresponding processes in the foregoing method embodiments, and details are not described here again.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other manners. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules or units is only one logical division, and there may be other divisions when actually implemented, for example, a plurality of units or components may be combined or may be integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application may be substantially implemented or contributed by the prior art, or all or part of the technical solution may be embodied in a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, a network device, or the like) or a processor (processor) to execute all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: u disk, removable hard disk, read only memory, random access memory, magnetic or optical disk, etc. for storing program codes.
The foregoing is a preferred embodiment of the present application and is not intended to limit the scope of the application in any way, and any features disclosed in this specification (including the abstract and drawings) may be replaced by alternative features serving equivalent or similar purposes, unless expressly stated otherwise. That is, unless expressly stated otherwise, each feature is only an example of a generic series of equivalent or similar features.