Detailed Description
In order to enable those skilled in the art to better understand the present application, the following description will make clear and complete descriptions of the technical solutions according to the embodiments of the present application with reference to the accompanying drawings.
In the related art, the execution frequency of a command is reduced as much as possible by searching for a service that has an excessively high execution frequency and has a large influence on the execution frequency of the command from the service layer. However, the service is updated continuously, and if the service with too high frequency of executing command and larger influence is searched for each time of updating the service, the workload of service personnel is increased, so that the mode has poor universality. And, the Input/output read/write rate (Input/Output Operations Per Second, IOPS) corresponding to the software or hardware is lowered.
Moreover, when commands are executed, these commands are communicated directly with hardware or software and issue Non-native command sequence (Non-Native Command Queuing, non-NCQ) instructions, which not only increase the load of the hardware or software, but may also cause the native command sequence (Native Command Queuing, NCQ) instructions to reorder, which in turn severely affects Input/Output (IO).
Aiming at the problems in the background technology, the inventor provides a method, a device, computer equipment and a storage medium for acquiring a command execution result. The historical execution results of the execution commands are cached in the cache files, before the target execution commands to be executed are executed, the target execution commands are not required to be executed, the historical execution results corresponding to the target execution commands can be obtained as the execution results of the execution commands at this time only by determining the target cache files corresponding to the target execution commands, so that the execution times of the target execution commands are reduced, the occupation of resources of computer equipment is reduced, the execution efficiency of the execution commands is improved, meanwhile, the execution commands are not required to be searched, the workload of service personnel is not required to be increased, and the universality of the acquisition of the execution results is improved.
The method, apparatus, computer device and storage medium for obtaining command execution results provided in the embodiments of the present application will be described in detail below with reference to the accompanying drawings.
Referring to fig. 1, fig. 1 is a flowchart illustrating a method for obtaining a command execution result according to an embodiment of the present application. The command execution result acquisition method can be applied to the command execution result acquisition device 300 shown in fig. 9 and the computer apparatus 100 (fig. 10) provided with the command execution result acquisition device 300.
The method for acquiring the command execution result specifically comprises the following steps:
Step S110, responding to a target execution command to be executed, and determining a target cache file corresponding to the target execution command.
Wherein, executing the command refers to inputting, generating or reading the command according to a specific format or syntax in a computer, an operating system, a software application or a command line interface, and then letting the computer or the system execute the command to complete the task or operation. The execution commands include, but are not limited to, hardware commands, software commands, and the like. The target execution command to be executed refers to an execution command that has been determined but not executed by the computer or system.
The target cache file is a file in which information related to a target execution command is stored. For example, the target cache file includes, but is not limited to, execution software information, execution hardware information, and execution results corresponding to the target execution command.
In the embodiment of the application, the target cache file is determined in response to the target execution command to be executed, and the mapping relationship between the target execution command and the target cache file can be established first, so that the target cache file corresponding to the target execution command can be determined according to the mapping relationship. And a mapping relation can be established between the target execution command and the storage path of the target cache file, and after the target execution command is determined, the storage path corresponding to the target execution command can be determined according to the mapping relation, and then the target cache file is determined according to the storage path. The manner of determining the target cache file according to the target execution command to be executed may be set according to actual situations, and is not specifically limited herein.
Step S120, obtaining a history execution result corresponding to the target execution command from the target cache file, as an execution result of executing the target execution command at this time.
The historical execution result can be an execution result obtained after the target execution command is executed last time. Or the execution result obtained after the target execution command is executed after the execution event corresponding to the target execution command is changed. The execution result obtained after the target execution command is executed at the preset frequency may also be obtained. It should be noted that, the target cache file may include all the historical execution results of the target execution command, or may include only the latest historical execution result, and the number of the historical execution results in the cache file is not specifically limited.
In the embodiment of the application, the historical execution result of the target execution command is obtained from the target cache file, the latest historical execution result is obtained, the historical execution result is used as the execution result of the current execution target execution command, and the target execution command does not need to be executed again.
According to the scheme provided by the embodiment, the historical execution results of the execution command are cached in the cache file, before the target execution command to be executed is executed, the target execution command is not required to be executed, the historical execution results corresponding to the target execution command can be obtained only by determining the target cache file corresponding to the target execution command and used as the execution results of the execution command, so that the execution times of the target execution command are reduced, the occupation of resources of computer equipment is reduced, the execution efficiency of the execution command is improved, meanwhile, the execution command is not required to be searched, the workload of service personnel is not required to be increased, and the universality of the acquisition of the execution result is improved.
Referring to fig. 2, fig. 2 is a flowchart illustrating a method for obtaining a command execution result according to another embodiment of the application.
And step S210, responding to the acquired target service, and acquiring the target execution command carried by the target service.
The target service may be obtained by determining an operation in response to a selection of a user in a man-machine interaction device, which includes but is not limited to a terminal device, a computer device, and other devices with an interaction function. The selection determination operation includes, but is not limited to, a click determination operation, a drag determination operation, an input operation, and the like, and the man-machine interaction device and the selection determination operation are not particularly limited herein.
Further, the acquiring manner of the target execution command carried by the target service may be that the target service is parsed according to a preset parsing manner, so as to acquire the target execution command carried by the target service. The method can also be used for acquiring keywords in the target service and determining a target execution command corresponding to the target service according to the keywords. The specific acquisition mode of the target execution command carried by the acquisition target service is not limited herein.
Illustratively, the target execution command is determined according to the keywords in the target service. The obtained target service is the disk state of inquiring disk id 1, and the keywords in the target service are the inquiry, id 1 and disk state. From the key, the target execution command is determined to be SEARCH SCSI _id=1.
Step S220, determining a target inquiry command corresponding to the target execution command according to the target execution command.
The target query command may be a target query command determined according to the target cache file after determining the target cache file corresponding to the target execution command according to the target execution command. And the soft link command of the target execution command can also be used for pointing to the target cache file corresponding to the target execution command. A soft link, also called symbolic link, is in fact a file that contains the pathname of another file. Soft links may point to any file or directory, even files that can link different file systems. That is, when the target query command is located at the soft link of the target execution command, the target query command includes the pathname of the target cache file, so as to implement the query of the execution result corresponding to the target execution command.
Illustratively, the target execution command test is renamed to test. And the created soft link test is used as a target query instruction corresponding to the target execution command. For replacing test commands.
In some embodiments, determining the target query command corresponding to the target execution command according to the target execution command comprises replacing an original name of the target execution command with a target name, and establishing the target query command corresponding to the target execution command, wherein the name of the target query command is the original name.
In the embodiment of the application, in order to ensure that the user accesses the target service, the execution target execution command carried by the target service.
And step S230, executing the target inquiry command, and determining a target cache file corresponding to the target execution command from the cached files.
In the embodiment of the application, because the target query command includes the path name of the target cache file, when the target query command is executed, the target cache file corresponding to the target execution command can be determined from the cached files.
In some embodiments, caching of the cached files is achieved through a plug-in mode. The plug-in mode includes, but is not limited to, file storage backend, distributed key value pair (etcd) storage backend, and other storage modes. The file storage backend refers to a storage backend based on a file system, and is also a default storage backend. So that it uses a file directory as a storage directory, and each different command's cache uses a separate file storage and is named in a specific naming format. The distributed key-value pair storage backend refers to a storage backend based on distributed key-value pairs, designed to reliably store and retrieve data, and provide high availability and consistency guarantees.
Referring to fig. 3, fig. 3 is a schematic diagram of a memory structure according to an embodiment of the application. And determining a storage position corresponding to each cache file according to the resource identifier corresponding to the cache file, determining the storage position corresponding to the resource identifier according to the resource type to which the resource identifier belongs, and finally managing and controlling all the resource types by the root directory to realize the caching of the cache file.
Step 240, obtaining a history execution result corresponding to the target execution command from the target cache file, and taking the history execution result as an execution result of executing the target execution command at this time.
The detailed description of step S240 refers to step S120 in the foregoing embodiment, and is not repeated here.
And step S250, updating the historical execution result in the target cache file in response to the monitored change of the target event corresponding to the target execution command.
In the embodiment of the application, in order to ensure timeliness and accuracy of the historical execution result, the target event corresponding to each execution command is monitored, and when the target event changes, the historical result is updated according to the change of the target event. When the target event changes, the target execution command can be executed in time to obtain the latest historical execution result after the target event changes.
Illustratively, when the disk sda device is monitored, the relevant changes of the target event are immediately sent to the outside. If the sda device is pulled off, the storage path associated with the sda device is deleted, and cache data and files associated with the sda device are cleaned up. If the sda device is inserted, the storage path associated with the sda device is updated, and the associated cache data and file are updated.
In some embodiments, the method for updating the historical execution result in the target cache file may also be to use a polling mechanism to detect whether the target event changes, and update the data and the file of the target event in time after detecting that the target event changes.
For example, the status of the disk array raid card 0 queried at 10 o ' clock is ok, and the status of the raid card 0 queried at 10 o ' clock 1 o ' clock is bad, which indicates that the status of the raid card 0 changes, and then related data and files corresponding to the raid card 0 need to be updated.
In other embodiments, the cache validity period of the execution result corresponding to the target event may be monitored in real time, and when the cache of the execution result has expired, the target execution command is executed to update the execution result. It should be noted that the buffer validity period is greater than the execution frequency of the target execution command, so as to achieve a lower update frequency than the execution frequency, and improve and reduce the execution times of the target execution command.
For example, the cache validity period of the execution result of the target event 1 is 10 days, and after the cache validity period is reached, the target execution command is executed to update the execution result corresponding to the target event 1.
Referring to fig. 4, fig. 4 is a schematic diagram illustrating updating of a command execution result in the method for obtaining a command execution result according to the embodiment of the present application. The event listeners, pollers and cache expiration scanners collectively listen for multiple events. When the event meeting the corresponding condition exists, a buffer memory to be updated is allocated for each event to be updated, and the buffer memory to be updated is added into a task queue, so that the update of the buffer memory file corresponding to the event to be updated is realized through a buffer memory refreshing thread, and the execution result of the target execution command is updated. It is necessary to mainly update the cache in series through the deduplication task queue and a single task (worker) in order to reduce the influence on the whole system to the greatest extent in the embodiment of the application, so that only one command is in an operation state at the same time. Multiple tasks may also be configured as needed to speed up the cache update process.
In a specific implementation process, a history execution result is cached in a cache file through a caching tool (cached-tool), a multi-level caching mode of a cache warehouse (cache store) is utilized for caching, and a cache refresh device (CACHE REFRESHER) is combined for refreshing the history execution result, so that when a target service is generated, an execution result obtained by a target execution command corresponding to the target service is the latest execution result, and timeliness of the acquisition of the execution result is ensured.
Referring to fig. 5, fig. 5 is a hardware schematic diagram illustrating a method for obtaining a command execution result in an embodiment of the application. In fig. 5, a cache tool is first utilized to establish a query command according to an execution command, and a correspondence between the query command and a cache repository is established, and the cache repository updates a historical execution result according to a cache flusher. When an execution command corresponding to a service required by a user is acquired, the corresponding historical execution result in the cache warehouse is directly acquired through the query command to serve as the execution result of the time, so that the execution of the execution command is reduced, and the efficiency of acquiring the execution result is improved.
According to the scheme provided by the embodiment, the corresponding target query command is established according to the target execution command, so that the target cache file corresponding to the target execution command is queried according to the target query command, and further, the historical execution result in the target cache file is obtained to be used as the execution result of the host vehicle execution target execution command, the execution action is replaced by the query action, the target execution command is not required to be executed, the execution times of the target execution command are further reduced, meanwhile, the load of software or hardware is also reduced, meanwhile, the service is transparent, no modification is required to the service, no worry about negative influence on the function is required, and service developers do not need to worry about repeated introduction of the same problem.
Referring to fig. 6, fig. 6 is a flowchart illustrating a method for obtaining a command execution result according to another embodiment of the application.
And step S310, responding to the acquired target service, and acquiring the target execution command carried by the target service.
Step S320, determining a target inquiry command corresponding to the target execution command according to the target execution command.
The detailed description of steps S310-S320 is referred to steps S210-S220 in the foregoing embodiments, and will not be repeated here.
Step S330, obtaining the command type corresponding to the target inquiry command.
Wherein the command types include, but are not limited to, cacheable types and non-cacheable types. The determining of the command type can be determined according to the parameters of the target query command, can be determined according to the specific command form of the target query command, or can be determined according to the configuration information corresponding to the target query command. The manner of determining the type of command is not specifically limited here.
Further, the configuration information includes, but is not limited to, a cache option, an event identifier, a cache validity period, and an associated event type, etc. The cache option comprises a short option which does not need to be cached and a long option which does not need to be cached, when the configuration information is the short option which does not need to be cached, the command type is represented as a cacheable type, and when the configuration information is the long option which does not need to be cached, the command type is represented as a non-cacheable type.
Illustratively, the command type is determined based on the configuration information in a manner determined as an example. When the target query command is test, the corresponding configuration information is short option dont _cache_short=1, long option dont _cache_long=0, cache valid period cache_time=1 min, event identifier id_ getter =1 and event type is disk, and the command type corresponding to the target query command is a cacheable type.
And step 340, if the command type is a cacheable type, executing the target query command, and determining a target cache file corresponding to the target execution command from the cached files.
In the embodiment of the application, when the command type is a cacheable type, the historical execution result corresponding to the target execution command is cached in the target cache file, and at this time, after the target query command is executed, the target cache file corresponding to the target execution command is directly determined from the cached file, and the execution result corresponding to the target execution command is not required to be acquired by executing the target execution command.
In some embodiments, when the command type is a non-cacheable type, the historical execution result corresponding to the target execution command cannot be cached, and at this time, the target execution command is executed to obtain the execution result corresponding to the target execution command, which is the execution result after the target execution command is executed this time.
Step 350, obtaining a history execution result corresponding to the target execution command from the target cache file, and taking the history execution result as an execution result of executing the target execution command at this time.
The detailed description of step S350 refers to step S120 in the foregoing embodiment, and is not repeated here.
According to the scheme provided by the embodiment, whether the historical execution result of the execution command is stored or not is determined according to the command type of the execution command, so that whether the execution command needs to be executed or not is determined, a service person is not required to manually screen the command or service, and the efficiency of acquiring the execution result is improved.
Referring to fig. 7, fig. 7 is a flowchart illustrating a method for obtaining a command execution result according to still another embodiment of the present application.
Step S410, according to the target execution command, obtaining a target cache path corresponding to the target execution command.
The cache path refers to a path for caching data or files, and in the embodiment of the present application, the target cache path refers to a path for caching a target cache file corresponding to a target execution command.
In the embodiment of the present application, the method for acquiring the target cache path according to the target execution command may be different in the creation and the acquisition methods of the cache paths of the data and the file in different operating systems or application software, and the creation and the acquisition methods of the target cache path are not specifically limited.
In some embodiments, obtaining the target cache path corresponding to the target execution command according to the target execution command includes obtaining a target hash value corresponding to the target execution command according to the target execution command. And determining the target cache path according to the target hash value.
Wherein the hash, also called pre-map, can transform an arbitrary length input into a fixed length output by a hashing algorithm. In the embodiment of the application, the target execution command is hashed, so that the hashed target execution command is a hash value with a fixed length. When the same target execution command is input, the same hash value is generated, and then the target cache path of the target execution command can be determined according to the hash value.
Illustratively, the target execution command is scsi_id, and caching is enabled for the execution result of the target execution command. Then when the target execution command carried by the target service is/lib/udev/scsi_id-replace-whitespace-whitelisted/dev/sda, the hardware type associated with the command is disk according to the configuration file of the target execution command, and the hard disk identifier is sda is obtained from the command, and the hash value of the parameter "- -replace-whitespace-whitelisted/dev/sda" is calculated to be 16b2c576be38c5f0fb329bd7e3ca571d. The path of the obtained cache file is/var/lib/cache/disk/sda/scsi_id+16b2c576 be38c5f0fb329bd7e3ca571d, and the cache file exists, and the command result is 336c92bf000a17aa3 and is finally obtained through reading the cache file and output.
Step S420, obtaining the target cache file according to the target cache path.
In the embodiment of the application, the target cache file corresponding to the target execution command can be determined according to the target cache path, and then the target cache file corresponding to the target execution command is obtained.
Step S430, obtaining a history execution result corresponding to the target execution command from the target cache file, and taking the history execution result as an execution result of executing the target execution command at this time.
The detailed description of step S430 refers to step S120 in the foregoing embodiment, and is not repeated here.
According to the scheme provided by the embodiment, the target cache path is determined according to the target execution command, and then the target cache file in the target cache path is accurately acquired, so that the historical execution result corresponding to the target execution command is accurately acquired to be used as the execution result of the execution command, the execution times of the target execution command are reduced, the load of software or hardware is reduced, meanwhile, the execution command is not required to be searched, further, the workload of service personnel is not required to be increased, and the universality of the acquisition of the execution result is improved.
Referring to fig. 8, fig. 8 shows a comparison result between a storage utilization rate corresponding to the method for obtaining a command execution result and a storage utilization rate of the command execution result in the related art according to the embodiment of the present application. As can be seen from fig. 7, in the same service, the space gap required for caching the command execution result is large in the related art. However, after the method for acquiring the command execution results provided by the application is used, the space required for caching each command execution result is approximately the same. And under the same business, the requirement of the buffer memory space used by friends is larger. Therefore, as can be seen from fig. 7, the method for acquiring the command execution result provided by the application saves the cache space of the command execution result.
Referring to fig. 9, a block diagram of a command execution result acquisition device 300 according to an embodiment of the application is shown. The device 300 for obtaining the command execution result is applied to the computer device 100, and the device 300 for obtaining the command execution result comprises a target cache file determining module 310, a target cache file processing module and a target cache file processing module, wherein the target cache file determining module 310 is used for determining a target cache file corresponding to a target execution command in response to the target execution command to be executed; and the execution result obtaining module 320 is configured to obtain, from the target cache file, a historical execution result corresponding to the target execution command, as an execution result of executing the target execution command at this time.
In some embodiments of the present application, the target cache file determining module 310 includes a target execution command obtaining unit, configured to obtain, in response to an obtained target service, the target execution command carried by the target service, a target query command determining unit, configured to determine, according to the target execution command, a target query command corresponding to the target execution command, and a target cache file determining unit, configured to execute the target query command, and determine, from cached files, a target cache file corresponding to the target execution command.
In some embodiments of the present application, the target query command determination unit includes a target query command creation subunit configured to replace an original name of the target execution command with a target name, and create a target query command corresponding to the target execution command, where the name of the target query command is the original name.
In some embodiments of the present application, the target cache file determining module 310 further includes a command type obtaining unit, configured to obtain a command type corresponding to the target query command, and the target cache file determining unit further includes a target cache file determining subunit, configured to execute the target query command if the command type is a cacheable type, and determine a target cache file corresponding to the target execution command from the cached files.
In some embodiments of the present application, the target cache file determining module 310 includes a target cache path obtaining unit, configured to obtain, according to the target execution command, a target cache path corresponding to the target execution command, and a target cache file obtaining unit, configured to obtain, according to the target cache path, the target cache file.
In some embodiments of the present application, the target cache path obtaining unit includes a target hash value obtaining subunit, configured to obtain, according to the target execution command, a target hash value corresponding to the target execution command, and a target cache path determining subunit, configured to determine the target cache path according to the target hash value.
In some embodiments of the present application, the device 300 for obtaining a command execution result further includes an image evaluation command execution result obtaining module, configured to update a historical execution result in the target cache file in response to a monitored change of a target event corresponding to the target execution command.
It will be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working process of the apparatus and modules described above may refer to the corresponding process in the foregoing method embodiment, which is not repeated herein.
In several embodiments provided by the present application, the coupling of the modules to each other may be electrical, mechanical, or other.
In addition, each functional module in each embodiment of the present application may be integrated into one processing module, or each module may exist alone physically, or two or more modules may be integrated into one module. The integrated modules may be implemented in hardware or in software functional modules.
The embodiment of the application provides a structural block diagram of computer equipment. Referring to fig. 10, a block diagram of a computer device according to an embodiment of the application is shown. The computer device 100 may be a computer device, such as a computer, a server, or the like, capable of running an application program. Computer device 100 in the present application may include one or more processors 101, memory 102, and one or more application programs, where the one or more application programs may be stored in memory 102 and configured to be executed by the one or more processors 101, the one or more program(s) configured to perform the methods as described in the foregoing method embodiments.
Processor 101 may include one or more processing cores. The processor 101 utilizes various interfaces and lines to connect various portions of the overall computer device 100, perform various functions of the computer device 100 and process data by executing or executing commands, programs, code sets, or command sets stored in the memory 102, and invoking data stored in the memory 102. Alternatively, the processor 101 may be implemented in at least one hardware form of digital signal Processing (DIGITAL SIGNAL Processing, DSP), field-Programmable gate array (Field-Programmable GATE ARRAY, FPGA), programmable Logic Array (PLA). The processor 101 may integrate one or a combination of several of a central processing unit (CentralProcessing Unit, CPU), an image processor (Graphics Processing Unit, GPU), and a modem, etc. The CPU mainly processes an operating system, a user interface, an application program and the like, the GPU is used for rendering and drawing display contents, and the modem is used for processing wireless communication. It will be appreciated that the modem may not be integrated into the processor 101 and may be implemented solely by a single communication chip.
Memory 102 may include random access Memory (Random Access Memory, RAM) or Read-Only Memory (ROM). Memory 102 may be used to store commands, programs, code sets, or command sets. The memory 102 may include a stored program area and a stored data area, wherein the stored program area may store commands for implementing an operating system, commands for implementing at least one function (such as a touch function, a sound playing function, an image playing function, etc.), commands for implementing the various method embodiments described below, etc. The storage data area may also store data created by the computer device 100 in use (e.g., phonebook, audiovisual data, chat log data), and the like.
Referring to fig. 11, a block diagram of a computer readable storage medium according to an embodiment of the present application is shown. The computer readable storage medium 200 has stored therein program code that can be invoked by a processor to perform the methods described in the method embodiments described above.
The computer readable storage medium 200 may be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read only memory), an EPROM, a hard disk, or a ROM. Optionally, computer readable storage medium 200 comprises a non-volatile computer readable medium (non-transitory computer-readable storage medium). The computer readable storage medium 200 has storage space for program code 210 that performs any of the method steps described above. The program code can be read from or written to one or more computer program products. Program code 210 may be compressed, for example, in a suitable form.
It should be noted that the above-mentioned embodiments are merely for illustrating the technical solution of the present application and not for limiting the same, and although the present application has been described in detail with reference to the above-mentioned embodiments, it will be understood by those skilled in the art that the technical solution described in the above-mentioned embodiments may be modified or some technical features may be equivalently replaced, and these modifications or replacements do not drive the essence of the corresponding technical solution to deviate from the spirit and scope of the technical solution of the embodiments of the present application.