Background
In the field of computer application software, especially software running on a single machine or client software running on a C/S architecture, in order to quickly and flexibly cope with different running environments, adapt to different requirements and subsequent additions and changes, usually, the contents of a large number of options and the contents of data classes are not directly written in codes, but are separately stored outside the program in other files or modes, and when the software is started to run, the configuration options and the data are read in from the external storage, so that the program can normally run and display different forms to adapt to different requirements. When the environment and the requirements are adjusted and changed within the design scope, the aim can be achieved by only modifying the data in the external configuration files without re-writing codes, compiling and releasing software. Storing configuration data externally is the most important and versatile means to achieve software flexibility and flexibility.
The current methods for storing configuration data mainly include three methods:
1) Using an external configuration of the formatted text file, the formatted text typically includes an INI format, an XML format, a jason format, etc. The text format has obvious advantages, the content of the text can be checked and modified by using a universal text editor, the specific meaning of each item is simple and clear, and the text format is easy to find, modify and add after random positioning, so that the text format is the simplest way for a developer to use and is the most convenient for maintenance and modification. However, the defects are obvious, and the formatted texts have the characteristic of random single read-write, so that the read-write speed is very slow, when the data volume in the configuration file is relatively large, the time consumption is relatively long, the software is directly slow to start, and the efficiency is seriously influenced especially for multi-process automatic processing software needing repeated and rapid start.
2) External configuration modes of binary format files are used, and the binary format files are usually configuration files stored after the structural contents of data in a memory are serialized in a binary stream mode. The advantage of using binary format configuration files is also clear, because binary streams are read sequentially in batches, the access speed is extremely fast, and even if the configuration data amount is large, the influence on software start-up is basically negligible. However, this mode has the natural defect that it is not easy to view, modify and append, and any general binary file tool cannot easily and clearly view the specific meaning of the data because of the binary special format, and is not easy to modify and append. So using binary formatted configuration files, it is often necessary to additionally develop dedicated configuration data access and modification software to view and modify the maintenance data content through a dedicated UI interface. This is very inconvenient for the use of configuration files and the associated effort is great when the format changes.
3) And the configuration mode of the external database is used, the configuration data are stored in the database, and the configuration data are read from the database when the software is started. The speed of accessing configuration data through the database is between the format text file mode and the binary file mode, which has the disadvantages of higher cost, needing to deploy database service, designing corresponding table structure, being only suitable for the system which is designed with the database in advance under partial C/S architecture and has convenient access, and being not suitable for single machine software.
Disclosure of Invention
Therefore, the embodiment of the invention provides a system and a method for quickly reading configuration files, a server and a medium, which are convenient to edit and maintain and ensure that software can quickly start new configuration data storage access.
In a first aspect of the embodiment of the present invention, a method for quickly reading a configuration file is provided, where the method for quickly reading a configuration file includes the following contents:
setting a formatted text reading function, a binary data storage function and a binary data reading function;
when the software is started, comparing the updating time of the formatted text configuration file and the binary data configuration file;
when the updating time of the formatted text configuration file is later or the binary data configuration file does not exist, calling a formatted text reading function, reading data in the formatted text configuration file into a memory structure, calling a binary data storage function, serializing the data in the memory structure to generate a new binary data configuration file, replacing the original binary data configuration file and storing the new binary data configuration file into an external file;
and when the updating time of the binary data configuration file is later, calling a binary data reading function to read the data in the binary data configuration file into the memory structure.
In a second aspect of the embodiment of the present invention, a system for quickly reading a configuration file is provided, where the system for quickly reading a configuration file includes the following functional modules:
the formatted text reading module is configured to read the data of the formatted text configuration file into the memory structure in a single random access mode;
the binary data storage module is configured to convert the structured data in the memory into a binary configuration file in a serialization mode and store the binary configuration file into an external file;
and the binary data reading module is configured to read the data in the binary configuration file into the memory structure.
In a third aspect of the embodiments of the present invention, there is provided a server comprising a memory, a processor and a computer program stored in said memory and executable on said processor, said processor implementing the steps of the method of fast reading a configuration file as described above when said computer program is executed.
In a fourth aspect of embodiments of the present invention, there is provided a computer readable storage medium storing a computer program which, when executed by a processor, performs the steps of a method of quickly reading a configuration file as described above.
The method, the system, the server and the medium for quickly reading the configuration file combine the advantages of the configuration file in a formatted text mode and the binary format configuration file, so that the convenience requirements of configuration data use, checking, modification and addition can be met, the problem of low starting speed caused by large configuration data reading amount when software is started is solved, and the method, the server and the medium for quickly reading the configuration file are low in use cost and easy to realize. The method has the advantages of convenience in checking and modifying the formatted text configuration file, high-speed loading performance of the binary format configuration file, avoidance of the defects of the formatted text configuration file and the binary format configuration file, low use cost and low limitation.
Detailed Description
In order to make the objects, features and advantages of the present invention more comprehensible, the technical solutions in the embodiments of the present invention are described in detail below with reference to the accompanying drawings, and it is apparent that the embodiments described below are only some embodiments of the present invention, but not all embodiments of the present invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
As shown in fig. 1, a method for quickly reading a configuration file according to an embodiment of the present invention includes the following steps:
s1, setting a formatted text reading function, a binary data storage function and a binary data reading function;
s2, when the software is started, comparing the updating time of the formatted text configuration file and the binary data configuration file;
s3, when the updating time of the formatted text configuration file is later or the binary data configuration file does not exist, calling a formatted text reading function, reading data in the formatted text configuration file into a memory structure, calling a binary data storage function, serializing the data in the memory structure to generate a new binary data configuration file, replacing the original binary data configuration file and storing the new binary data configuration file into an external file;
s4, when the updating time of the binary data configuration file is later, calling a binary data reading function to read data in the binary data configuration file into the memory structure.
Specifically, the following 3 access functions are first pre-written.
The formatted text reading function can specifically adopt INI, XML, jason or any other format which is convenient to view, edit and append. This function is used to read configuration data in the formatted text configuration file into the memory structure in a single random access manner. The specific format of the configuration data content in the formatted text configuration file is defined by the developer on demand, but it is necessary to ensure that the read function matches the format.
The binary data storage function is characterized in that the binary data configuration file is a binary stream storage file with a custom format, and the function converts structured data in a memory into a binary stream in a serialization mode and stores the binary stream into an external file.
The binary data reading function acts in a positive opposition to the binary data storage function, which reads the data in the binary configuration file into the memory structure, and is a strictly sequential reverse serialization process because the binary configuration file is a memory-serialized binary stream.
At software start-up, it is checked whether a formatted text profile and a binary data profile exist. The formatted text profile belongs to a manually edited preset file and must exist. If the binary data configuration file does not exist, a formatted text reading function is called to read the data in the formatted text configuration file into the memory structure. And then, calling a binary data storage function, serializing the data in the memory structure, writing out the data to generate a binary data configuration file, and then, normally operating the software.
If the binary data profile already exists, the last modification times of the formatted text profile and the binary data profile are read, which time is later is compared with the formatted text profile, and if the formatted text profile is later, a formatted text reading function is called to read the data in the formatted text profile into the memory structure. And then, calling a binary storage function, serializing the data in the memory structure, writing out the data to generate a binary data configuration file, namely discarding the original binary data configuration file to generate a new binary data configuration file, and then, normally operating the software.
If the binary data configuration file time in the judgment is later, a binary data reading function is called, data in the binary data configuration file is read into a memory structure, and then software operates normally.
When the software is started, the time of the binary data configuration file is later than that of the formatted text configuration file, so that the software always automatically reads the configuration data from the binary data configuration file in a binary stream mode, the reading speed is extremely high, and the software starting is not influenced. When the configuration data needs to be modified and added, maintenance personnel only need to use a general formatted text editor to open the formatted text configuration file for adding/deleting/modifying/checking, and the method is convenient and easy. After the formatted text configuration file is modified, due to time variation, the software automatically reads the content of the formatted text configuration file to regenerate the binary data configuration file when the software is started for the first time, and the binary data configuration file is directly used by the subsequent starting, so that the situation that the speed is slower only occurs when the software is started for the first time. Since modification of the formatted text profile is a rare occurrence, updating the binary data profile is a rare occurrence, which is essentially negligible.
By using the method for quickly reading the configuration file, maintenance personnel only need to edit the formatted text file to modify the configuration data, software only needs to read the formatted text configuration data in time consumption when running for the first time, binary configuration data is used when starting daily, the purpose of convenient maintenance is achieved, the problem of starting speed is solved, and the application cost is low.
The invention provides a method for quickly reading configuration files, which combines the advantages of a configuration file in a formatted text mode and a binary format configuration file, so that the convenience requirements of configuration data use, checking, modification and addition can be met, the problem of low starting speed caused by large configuration data reading amount when software is started is solved, and the method is low in use cost and easy to realize. The method has the advantages of convenience in checking and modifying the formatted text configuration file, high-speed loading performance of the binary format configuration file, avoidance of the defects of the formatted text configuration file and the binary format configuration file, low use cost and low limitation.
It should be understood that the sequence number of each step in the foregoing embodiment does not mean that the execution sequence of each process should be determined by the function and the internal logic, and should not limit the implementation process of the embodiment of the present invention.
The foregoing has mainly described a method for quickly reading a configuration file, and a system for quickly reading a configuration file will be described in detail.
FIG. 2 is a functional block diagram of a system for fast reading of configuration files according to an embodiment of the present invention. As shown in fig. 2, the system for quickly reading the configuration file includes the following functional modules:
the formatted text reading module 10 is configured to read the data of the formatted text configuration file into the memory structure in a single random access mode;
a binary data storage module 20 configured to convert the structured data in the memory into a binary configuration file in a serialized manner and store the binary configuration file in an external file;
the binary data reading module 30 is configured to read the data in the binary configuration file into the memory structure.
Fig. 3 is a schematic diagram of a server structure for quickly reading a configuration file according to an embodiment of the present invention. The server is a device for providing a computing service, generally referred to as a computer having a high computing power and provided to a plurality of users through a network. As shown in fig. 3, the server 4 of this embodiment includes: the memory 41, the processor 42 and the system bus 43, the memory 41 comprising an executable program 411 stored thereon, it will be understood by those skilled in the art that the terminal device structure shown in fig. 3 does not constitute a limitation of the terminal device, and may comprise more or less components than illustrated, or may combine certain components, or a different arrangement of components.
The following describes the respective constituent elements of the terminal device in detail with reference to fig. 3:
the memory 41 may be used to store software programs and modules, and the processor 42 performs various functional applications of the terminal and data processing by running the software programs and modules stored in the memory 41. The memory 41 may mainly include a storage program area that may store an operating system, application programs required for at least one function (such as a sound playing function, an image playing function, etc.), and a storage data area; the storage data area may store data (such as audio data, phonebook, etc.) created according to the use of the terminal, etc. In addition, memory 41 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid-state storage device.
An executable program 411 containing a method for quickly reading configuration files on a memory 41, said executable program 411 may be divided into one or more modules/units stored in said memory 41 and executed by a processor 42 to complete the delivery of notifications and obtain notification implementation, said one or more modules/units may be a series of computer program instruction segments capable of performing specific functions describing the execution of said computer program 411 in said server 4. For example, the computer program 411 may be divided into an acquisition module, a comparison module, a splice module, and a transmission module.
The processor 42 is a control center of the server, connects respective parts of the entire terminal device using various interfaces and lines, and performs various functions of the terminal and processes data by running or executing software programs and/or modules stored in the memory 41 and calling data stored in the memory 41, thereby performing overall monitoring of the terminal. Optionally, the processor 42 may include one or more processing units; preferably, the processor 42 may integrate an application processor that primarily handles operating systems, applications, etc., with a modem processor that primarily handles wireless communications. It will be appreciated that the modem processor described above may not be integrated into the processor 42.
The system bus 43 is used to connect various functional components inside the computer, and can transfer data information, address information, and control information, and the types of which may be PCI bus, ISA bus, VESA bus, and the like. Instructions of the processor 42 are transferred to the memory 41 through the bus, the memory 41 feeds back data to the processor 42, and the system bus 43 is responsible for data and instruction interaction between the processor 42 and the memory 41. Of course, the system bus 43 may also access other devices, such as a network interface, a display device, etc.
The server should at least include a CPU, a chipset, a memory, a disk system, etc., and other components will not be described herein.
In the embodiment of the present invention, the executable program executed by the processor 42 included in the terminal is specifically: a method of quickly reading a configuration file, comprising:
setting a formatted text reading function, a binary data storage function and a binary data reading function;
at software start-up, comparing the update times of the formatted text profile and the binary data profile,
when the updating time of the formatted text configuration file is later or the binary data configuration file does not exist, calling a formatted text reading function, and reading the data in the formatted text configuration file into a memory structure;
invoking a binary data storage function, serializing the data in the memory structure to generate a new binary data configuration file, replacing the original binary data configuration file and storing the original binary data configuration file into an external file;
and when the updating time of the binary data configuration file is later, calling a binary data reading function to read the data in the binary data configuration file into the memory structure.
It will be clear to those skilled in the art that, for convenience and brevity of description, specific working procedures of the above-described systems, apparatuses and units may refer to corresponding procedures in the foregoing method embodiments, which are not repeated herein.
In the foregoing embodiments, the descriptions of the embodiments are emphasized, and in part, not described or illustrated in any particular embodiment, reference is made to the related descriptions of other embodiments.
Those of ordinary skill in the art will appreciate that the modules, units, and/or method steps of the various embodiments described in connection with the embodiments disclosed herein can be implemented as electronic hardware, or as a combination of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
The above embodiments are only for illustrating the technical solution of the present invention, and not for limiting the same; although the invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present invention.