CN115221167A - Static data storage and query method and device and electronic device - Google Patents

Static data storage and query method and device and electronic device Download PDF

Info

Publication number
CN115221167A
CN115221167A CN202210820747.6A CN202210820747A CN115221167A CN 115221167 A CN115221167 A CN 115221167A CN 202210820747 A CN202210820747 A CN 202210820747A CN 115221167 A CN115221167 A CN 115221167A
Authority
CN
China
Prior art keywords
static data
hash
shared memory
storing
hash table
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.)
Pending
Application number
CN202210820747.6A
Other languages
Chinese (zh)
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.)
DBAPPSecurity Co Ltd
Original Assignee
DBAPPSecurity 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 DBAPPSecurity Co Ltd filed Critical DBAPPSecurity Co Ltd
Priority to CN202210820747.6A priority Critical patent/CN115221167A/en
Publication of CN115221167A publication Critical patent/CN115221167A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2255Hash tables

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application relates to a method, a device and an electronic device for storing and querying static data, wherein the method for storing the static data comprises the following steps: acquiring a plurality of static data to be stored and a shared memory for storing the static data; creating a hash table for storing the static data according to a preset first hash algorithm, wherein a plurality of hash indexes in the hash table respectively correspond to at least one piece of static data; and storing the static data in the shared memory according to the hash table, and recording the address information of the static data in the shared memory in the hash table. By the method and the device, the problem that the static data which is frequently inquired by adopting Redis storage in the related technology can not meet the requirement of high data inquiry efficiency under the condition of multi-process high concurrency is solved, and the effect of efficiently inquiring the data in parallel by the multi-process is realized.

Description

Static data storage and query method and device and electronic device
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for storing and querying static data, and an electronic apparatus.
Background
The performance is always an irreconcilable topic in the software development process, and the performance improvement means that the same service can be provided with lower cost; in development, a type of data is usually changed less, and is updated only when upgraded, and such data may be referred to as static data, such as plug-in dependency information and description data in bug scans, but the static data is frequently queried by different processes.
It is currently common to store these static data in Redis, and services obtain queries from Redis through network IO. The method comprises the following specific steps: loading data when a Redis service is started, and organizing the data by the Redis through a hash table; the program interacts with Redis through a network socket and provides a key for data query of Redis service; and finally, the redis service returns the query result to the application program.
Although Redis is a high-performance component, the product performance is greatly improved; there are still points that can be lifted. Redis exists as a single service and is a single thread, so that multiple services are necessarily accessed serially, and the requirement of high data query efficiency under multi-process high concurrency cannot be met; secondly, each communication with Redis needs to be carried out through system call, the number of the system calls is in direct proportion to the number of the queries, and the system call has relatively large resource overhead.
Aiming at the problem that the static data which is frequently inquired by adopting Redis storage in the related technology cannot meet the requirement of high data inquiry efficiency under the condition of multi-process high concurrency, an effective solution is not provided at present.
Disclosure of Invention
The embodiment provides a method, a device and an electronic device for storing and querying static data, so as to solve the problem that the requirement of high data query efficiency under multi-process high concurrency cannot be met by storing frequently queried static data by Redis in the related art.
In a first aspect, in this embodiment, a storage method for static data is provided, where the storage method includes:
the method comprises the steps of obtaining a plurality of static data to be stored and obtaining a shared memory for storing the static data;
creating a hash table for storing the static data according to a preset first hash algorithm, wherein a plurality of hash indexes in the hash table respectively correspond to at least one piece of static data;
and storing the static data in the shared memory according to the hash table, and recording the address information of the static data in the shared memory in the hash table.
In some embodiments, the storing the static data in the shared memory according to the hash table comprises:
and according to the corresponding relation between the hash index and the static data, sequentially storing the static data corresponding to the hash indexes in the hash table in the shared memory.
In some embodiments, the storing the static data in the shared memory according to the hash table further comprises:
and when the same hash index corresponds to a plurality of pieces of static data, sequentially storing the plurality of pieces of static data in the shared memory.
In some embodiments, the recording the address information of the static data in the shared memory in the hash table includes:
and respectively recording initial storage addresses of the static data corresponding to the hash indexes in the shared memory in the hash table, wherein the initial storage addresses respectively correspond to the hash indexes.
In some embodiments, before the creating a hash table for storing the static data according to a preset first hash algorithm, the method further includes:
acquiring different multiple second hash algorithms, and generating multiple groups of hash indexes corresponding to the static data according to the multiple second hash algorithms respectively;
and respectively calculating the average collision times of the multiple groups of hash indexes, and marking a second hash algorithm corresponding to the group of hash indexes with the minimum average collision times as the first hash algorithm.
In a second aspect, in this embodiment, a method for querying static data is provided, where the method includes:
acquiring a storage address of static data to be queried in a shared memory, wherein the static data is stored in the shared memory by adopting the static data storage method of any one of the first aspect;
obtaining a hash index corresponding to target static data through a first hash algorithm, and determining a target position of the target static data in the shared memory according to the hash index;
and querying the target static data at a target position in the shared memory.
In some embodiments, the querying the target static data at the target location in the shared memory comprises:
and when hash collision is encountered, sequentially inquiring the target static data in the shared memory by taking the target position as a starting position.
In a third aspect, in this embodiment, there is provided a storage device for static data, the storage device comprising:
the acquisition module is used for acquiring a plurality of static data to be stored and acquiring a shared memory for storing the static data;
the creating module is used for creating a hash table used for storing the static data according to a preset first hash algorithm, wherein a plurality of hash indexes in the hash table correspond to at least one piece of static data respectively;
and the storage module is used for storing the static data in the shared memory according to the hash table and recording the address information of the static data in the shared memory in the hash table.
In a fourth aspect, in this embodiment, there is provided an apparatus for querying static data, the apparatus including:
a memory obtaining module, configured to obtain a storage address of static data to be queried in a shared memory, where the static data is stored in the shared memory by using the static data storage method according to any one of the first aspects;
the position determining module is used for acquiring a hash index corresponding to target static data through a first hash algorithm and determining a target position of the target static data in the shared memory according to the hash index;
and the data query module is used for querying the target static data at the target position in the shared memory.
In a third aspect, in this embodiment, there is provided an electronic apparatus, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor implements the method for storing static data according to the first aspect or implements the method for querying static data according to the second aspect when executing the computer program.
In a fourth aspect, in the present embodiment, there is provided a storage medium, on which a computer program is stored, the program, when executed by a processor, implementing the method for storing static data according to the first aspect or the method for querying static data according to the second aspect.
Compared with the related art, the static data storage and query method, device and electronic device provided in this embodiment read the static data from the database stored outside the computer, and store the static data in the shared memory by using the data structure of the hash table. Therefore, the subsequent process can directly inquire corresponding static data from the shared memory conveniently, the problem that the static data which is frequently inquired by adopting Redis storage in the related technology can not meet the requirement of high data inquiry efficiency under multi-process high concurrency is solved, and the data can be inquired efficiently under multi-process high concurrency.
The details of one or more embodiments of the application are set forth in the accompanying drawings and the description below to provide a more thorough understanding of the application.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the application and together with the description serve to explain the application and not to limit the application. In the drawings:
fig. 1 is a block diagram of a hardware configuration of a terminal of the static data storage or query method according to the present embodiment.
Fig. 2 is a flowchart of a method of storing static data according to the present embodiment.
Fig. 3 is a flowchart of a static data query method according to the present embodiment.
Fig. 4 is a flowchart of the static data storage method of the present preferred embodiment.
Fig. 5 is a flowchart of the query method of static data according to the preferred embodiment.
Fig. 6 is a block diagram showing the structure of the static data storage device according to the present embodiment.
Fig. 7 is a block diagram showing the configuration of the static data query device according to the present embodiment.
Detailed Description
For a clearer understanding of the objects, aspects and advantages of the present application, reference is made to the following description and accompanying drawings.
Unless defined otherwise, technical or scientific terms used herein shall have the same general meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The use of the terms "a" and "an" and "the" and similar referents in the context of this application do not denote a limitation of quantity, either in the singular or the plural. The terms "comprises," "comprising," "has," "having," and any variations thereof, as referred to in this application, are intended to cover non-exclusive inclusions; for example, a process, method, and system, article, or apparatus that comprises a list of steps or modules (elements) is not limited to the listed steps or modules, but may include other steps or modules (elements) not listed or inherent to such process, method, article, or apparatus. Reference in this application to "connected," "coupled," and the like is not intended to be limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. Reference to "a plurality" in this application means two or more. "and/or" describes the association relationship of the associated object, indicating that there may be three relationships, for example, "a and/or B" may indicate: a exists alone, A and B exist simultaneously, and B exists alone. In general, the character "/" indicates a relationship in which the objects associated before and after are an "or". The terms "first," "second," "third," and the like in this application are used for distinguishing between similar items and not necessarily for describing a particular sequential or chronological order.
The method embodiments provided in the present embodiment may be executed in a terminal, a computer, or a similar computing device. For example, the method is executed on a terminal, and fig. 1 is a block diagram of a hardware structure of the terminal according to the static data storage or query method of the present embodiment. As shown in fig. 1, the terminal may include one or more processors 102 (only one shown in fig. 1) and a memory 104 for storing data, wherein the processor 102 may include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA. The terminal may also include a transmission device 106 for communication functions and an input-output device 108. It will be understood by those of ordinary skill in the art that the structure shown in fig. 1 is merely an illustration and is not intended to limit the structure of the terminal described above. For example, the terminal may also include more or fewer components than shown in FIG. 1, or have a different configuration than shown in FIG. 1.
The memory 104 can be used for storing computer programs, for example, software programs and modules of application software, such as a computer program corresponding to the static data storage method or the query method in the embodiment, and the processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, so as to implement the above-mentioned methods. The memory 104 may include high speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include memory located remotely from the processor 102, which may be connected to the terminal over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The transmission device 106 is used to receive or transmit data via a network. The network described above includes a wireless network provided by a communication provider of the terminal. In one example, the transmission device 106 includes a Network adapter (NIC) that can be connected to other Network devices through a base station to communicate with the internet. In one example, the transmission device 106 may be a Radio Frequency (RF) module, which is used to communicate with the internet via wireless.
In this embodiment, a method for storing static data is provided, and fig. 2 is a flowchart of the method for storing static data of this embodiment, as shown in fig. 2, the flowchart includes the following steps:
step S210, a plurality of static data to be stored and a shared memory for storing the static data are obtained.
Specifically, the computer device applies for a shared memory for storing static data from an operating system, where the static data refers to data that is hardly changed and is generally updated only when the data is upgraded, such as plug-in dependency information data and description data in bug scanning. Before the method steps are executed, the static data is generally stored in a database in the external memory of the computer, so that the corresponding static data is read from the database in the step, and is stored in the shared memory in the subsequent step, so that the multiple processes can access the shared memory to inquire the corresponding static data.
Step S220, a hash table for storing static data is created according to a preset first hash algorithm, where a plurality of hash indexes in the hash table correspond to at least one piece of static data, respectively.
Specifically, the computer device calculates hash index values corresponding to the static data by using a first hash algorithm, and constructs a corresponding hash table based on the hash indexes. Each hash index at least corresponds to one piece of static data, so that the target static data can be conveniently retrieved through the hash index in the following process.
Step S230, storing the static data in the shared memory according to the hash table, and recording address information of the static data in the shared memory in the hash table.
Specifically, the computer device stores the static data in the shared memory by using a data structure such as a hash table, and records address information of the static data in the shared memory in the hash table, where the corresponding address information corresponds to the hash index. Therefore, in the subsequent data query process, the position of the static data in the shared memory can be determined through the hash index. Illustratively, the hash table data structure may include: space size, version number, state, hash option, hash index/start position, data storage segment; before static data is stored in a shared memory, initializing the shared memory by using the hash table structure; traversing the hash table, sequentially storing the static data under each hash index into a data segment, namely storing the static data at a corresponding position in a shared memory, and simultaneously recording the starting position of static data storage, wherein the starting position corresponds to the hash index; and after all the static data are loaded into the shared memory, filling fields such as the space size, the version number, the hash option, the state of the shared memory and the like.
Through the steps, the static data are read from the database stored outside the computer, and are stored in the shared memory by adopting a data structure of a hash table. Therefore, the subsequent process can directly inquire the corresponding static data from the shared memory. Compared with the prior art that the static data which is frequently inquired is stored in Redis, the static data storage method in the embodiment stores the static data in the shared memory by adopting the hash table, wherein the shared memory is the most efficient inter-process communication mode under the Linux operating system, and as the static data does not change, locking is not required when the shared memory is accessed, and a plurality of process services can be accessed in parallel. The use of the shared memory only needs less system calls and is not in proportion to the query times; meanwhile, in order to ensure high efficiency of query, the static data is organized by adopting a hash table, and the time complexity of the hash table is O (1).
In some embodiments, the step of storing the static data in the shared memory according to the hash table specifically includes:
and according to the corresponding relation between the hash index and the static data, sequentially storing the static data corresponding to the hash indexes in the hash table in the shared memory.
Specifically, each hash index corresponds to one or more pieces of static data, and when the static data is stored, all hash indexes in the hash table are traversed, and the static data under each hash index is stored in the shared memory in sequence. It should be noted that the static data corresponding to different hash indexes may not occupy a continuous storage space.
In some embodiments, the step of storing the static data in the shared memory according to the hash table further includes:
and when the same hash index corresponds to a plurality of pieces of static data, sequentially storing the plurality of pieces of static data in the shared memory.
Specifically, when one hash index corresponds to a plurality of pieces of static data, the plurality of pieces of static data are sequentially stored in a continuous space of the shared memory. In the common hash table structure, multiple pieces of static data under one hash index are usually stored in a link form, but in this embodiment, because the static data is not changed, a secondary hash table construction mode can be adopted, that is, a hash table is used in advance to find out the static data with the same hash index, and then the static data with the same hash index is sequentially stored on the hash table implemented by an array, so that when a hash conflict occurs in a subsequent data query process, the hash value is not recalculated to be positioned, but the static data is sequentially searched at an original position. Therefore, the static data is compactly stored in the continuous space, the utilization efficiency of the shared memory space is improved, and further, the larger index value can be adopted to reduce the occurrence of conflict without losing efficiency.
In some embodiments, the step of recording address information of the static data in the shared memory in the hash table specifically includes:
and respectively recording initial storage addresses of the static data corresponding to the hash indexes in the shared memory in the hash table, wherein the initial storage addresses respectively correspond to the hash indexes.
Specifically, after one or more pieces of static data are stored in the shared memory according to the hash indexes, the initial storage address of the static data under each hash index is recorded, and the initial storage address is recorded in the corresponding hash index.
In some embodiments, before the step of creating the hash table for organizing the static data according to the preset first hash algorithm, the method comprises the steps of:
acquiring different multiple second hash algorithms, and generating multiple groups of hash indexes corresponding to the static data according to the multiple second hash algorithms respectively;
and respectively calculating the average collision times of the multiple groups of hash indexes, and marking a second hash algorithm corresponding to the group of hash indexes with the minimum average collision times as a first hash algorithm.
Specifically, before the hash algorithm used by the static data is determined, a plurality of hash algorithms are obtained, an optimal hash algorithm is selected from the plurality of hash algorithms, and the quality of the hash algorithm is measured by calculating the average hash collision times. Specifically, the total hash collision number generated by all hash indexes of each hash algorithm is counted first, and then the total hash collision number is divided by the number of the hash indexes, so as to obtain the average hash collision number of each hash algorithm finally. And selecting the hash algorithm with the least average collision times as the final hash algorithm for constructing the static data hash table. In this embodiment, since the static data is stored without change, the collision average values of different hash algorithms can be calculated before storage, when the hash table is constructed, the optimal index value and the hash algorithm are pre-selected to be marked in the shared memory, and when the hash table is used, the mark is read to determine the index value and the hash algorithm which are currently used.
The embodiment also provides a static data query method. Fig. 3 is a flowchart of the query method of static data according to this embodiment, and as shown in fig. 3, the flowchart includes the following steps:
step S310, a storage address of the static data to be queried in the shared memory is obtained, where the static data is stored in the shared memory by using the static data storage method provided in this embodiment.
Specifically, the computer device first obtains a shared memory address for storing static data from the system according to an agreed key, and the corresponding static data is stored in the corresponding shared memory by the storage method in this embodiment.
Step S320, a hash index corresponding to the target static data is obtained through a first hash algorithm, and a target position of the target static data in the shared memory is determined according to the hash index.
Specifically, when a process needs to query specific static data, a hash index of target static data is obtained through a first hash algorithm, where the first hash algorithm is a hash algorithm used when the static data is stored, and the hash index carries address information of the static data, so that a target position of the target static data in the shared memory can be determined through the hash index.
In step S330, the target static data is queried at the target location in the shared memory.
Specifically, after the process obtains the target location, the process may directly read the target static data at the corresponding location in the shared memory. Preferably, when the hash collision is encountered, the target static data is sequentially queried in the shared memory by taking the target position as a starting position. Because a plurality of static data under the same hash index are sequentially stored in the shared memory, when hash conflicts occur, only the static data need to be searched along the target position sequence until the target static data is searched.
Through the steps, when the process needs to inquire specific static data, the process searches target static data from the corresponding shared memory through the Hash index. Because static data is not changed, locking is not needed when the process accesses the shared memory, so that a plurality of process services can be accessed in parallel. And the use of the shared memory only needs less system calls and is not in proportion to the query times, so that the use of system resources can be greatly reduced.
The technical solutions in the present application are described and illustrated below by means of preferred embodiments.
Fig. 4 is a flowchart of the static data storage method of the present preferred embodiment. As shown in fig. 4, the method for storing static data includes the following steps:
in step S410, a shared memory is applied from the system.
The user applies for a shared memory from the system, the shared memory is used for storing static data, and the size of the shared memory ensures that the static data can be stored sufficiently.
Step S420, load data from the database, and construct the data into a hash table according to the self-defined hash function.
Specifically, the hash table may be constructed by a common component, and the memory occupied by the hash table may not be continuous or may be continuous. Further specifically, different hash algorithms and hash index values are used to select the optimal configuration, and the hash algorithms and the index values are used as the generation configuration of the final array hash table. Wherein, self-defined hash table data structure includes: total space, version number, state, hash table index, data storage segment, etc. And each item stored in the data storage segment is in the form of a data length and a data content. The whole self-defined hash table data structure is in a continuous space.
Step S430, initialize the shared memory using the custom hash table structure.
Step S440, traversing the hash table constructed according to the customized hash function, sequentially storing the data under each hash index into the data segment, and recording the start position of data storage.
Specifically, if there are multiple pieces of data under the same hash index, the pieces of data are stored sequentially.
Step S450, after all the data are loaded into the shared memory, fill in the space size, version number, hash option, and shared memory status field.
Through the steps, the data structure of the hash table is adopted to load the data into the shared memory, so that the subsequent process can directly inquire corresponding static data from the shared memory conveniently. The above-described data loading process is only performed at each service initiation.
Fig. 5 is a flowchart of the query method of static data according to the preferred embodiment. As shown in fig. 5, the query method of static data includes the following steps:
step S510, obtaining the shared memory address for storing data from the system according to the agreed key.
Specifically, this step is performed only once at program start-up.
Step S520, convert the memory into a custom hash table format.
Specifically, this step is performed only once at program start-up.
Step S530, a hash index corresponding to the key value is calculated through a hash function, and the specific location of the data storage is directly searched through the index.
Specifically, if a conflicting value is encountered, then the next position is found in sequence.
The static data storage/query method provided in this embodiment provides a fast data query scheme to improve query efficiency. The shared memory is the most efficient inter-process communication mode under Linux, and because data is not changed, locking is not needed when the shared memory is accessed, and a plurality of services can be accessed in parallel; the use of the shared memory only needs less system calls and is not in proportion to the query times; in order to ensure the high efficiency of the query, the data is organized by using a hash table, and the time complexity of the hash table is O (1). Therefore, the requirement of high data query efficiency under multi-process high concurrency in Linux can be met. It should be noted that, after the data query service is finished, the shared memory may be directly deleted.
In this embodiment, a static data storage device and a static data query device are further provided, where the static data storage device is used to implement the foregoing embodiments and preferred embodiments, and details are not described again after the description. The terms "module," "unit," "sub-unit," and the like as used below may implement a combination of software and/or hardware of predetermined functions. Although the means described in the embodiments below are preferably implemented in software, an implementation in hardware or a combination of software and hardware is also possible and contemplated.
Fig. 6 is a block diagram showing the structure of the static data storage device according to the present embodiment, and as shown in fig. 6, the device includes:
an obtaining module 610, configured to obtain a plurality of static data to be stored and obtain a shared memory for storing the static data;
a creating module 620, configured to create a hash table for storing static data according to a preset first hash algorithm, where a plurality of hash indexes in the hash table correspond to at least one piece of static data respectively;
the storing module 630 is configured to store the static data in the shared memory according to the hash table, and record address information of the static data in the shared memory in the hash table.
Through the cooperation of the modules, static data are read from a database stored outside a computer, and are stored in a shared memory by adopting a data structure of a hash table. Therefore, the subsequent process can directly inquire the corresponding static data from the shared memory. Compared with the prior art in which frequently queried static data is stored in Redis, the static data storage device in this embodiment stores the static data in a shared memory by using a hash table, where the shared memory is the most efficient inter-process communication mode in the Linux operating system, and since the static data does not change, locking is not required when accessing the shared memory, and multiple process services can be accessed in parallel. The use of the shared memory only needs less system calls and is not in proportion to the query times; meanwhile, in order to ensure high efficiency of query, the static data is organized by adopting a hash table, and the time complexity of the hash table is O (1).
Fig. 7 is a block diagram of a static data query device according to this embodiment, and as shown in fig. 7, the device includes:
a memory obtaining module 710, configured to obtain a storage address of static data to be queried in a shared memory, where the static data is stored in the shared memory by using the static data storage device provided in this embodiment;
the position determining module 720 is configured to obtain a hash index corresponding to the target static data through a first hash algorithm, and determine a target position of the target static data in the shared memory according to the hash index;
and a data query module 730, configured to query the target static data at the target location in the shared memory.
Through the cooperation of the modules, when a process needs to inquire specific static data, the process searches target static data from the corresponding shared memory through the hash index. Because static data is not changed, locking is not needed when processes access the shared memory, so that a plurality of process services can be accessed in parallel. And the use of the shared memory only needs less system calls and is not in proportion to the query times, so that the use of system resources can be greatly reduced.
It should be noted that, the specific working process of the functional module is specifically described in the embodiment of the method, and is not described herein again.
It should be noted that the above modules may be functional modules or program modules, and may be implemented by software or hardware. For a module implemented by hardware, the modules may be located in the same processor; or the modules can be respectively positioned in different processors in any combination.
There is also provided in this embodiment an electronic device comprising a memory having a computer program stored therein and a processor arranged to run the computer program to perform the steps of any of the above method embodiments.
Optionally, the electronic apparatus may further include a transmission device and an input/output device, wherein the transmission device is connected to the processor, and the input/output device is connected to the processor.
Optionally, in this embodiment, the processor may be configured to execute the following steps by a computer program:
s1, obtaining a plurality of static data to be stored and obtaining a shared memory for storing the static data.
And S2, creating a hash table for storing the static data according to a preset first hash algorithm, wherein a plurality of hash indexes in the hash table correspond to at least one piece of static data respectively.
And S3, storing the static data in the shared memory according to the hash table, and recording the address information of the static data in the shared memory in the hash table.
It should be noted that, for specific examples in this embodiment, reference may be made to the examples described in the foregoing embodiments and optional implementations, and details are not described again in this embodiment.
In addition, in combination with the method for storing static data provided in the foregoing embodiment, a storage medium may also be provided in this embodiment. The storage medium having stored thereon a computer program; the computer program, when executed by a processor, implements a method of storing static data according to any one of the above embodiments.
It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) referred to in the present application are information and data authorized by the user or sufficiently authorized by each party.
It should be understood that the specific embodiments described herein are merely illustrative of this application and are not intended to be limiting. All other embodiments, which can be derived by a person skilled in the art from the examples provided herein without inventive step, shall fall within the scope of protection of the present application.
It is obvious that the drawings are only examples or embodiments of the present application, and it is obvious to those skilled in the art that the present application can be applied to other similar cases according to the drawings without creative efforts. Moreover, it should be appreciated that in the development of any such actual implementation, as in any engineering or design project, numerous implementation-specific decisions must be made to achieve the developers' specific goals, such as compliance with system-related and business-related constraints, which may vary from one implementation to another.
Reference throughout this application to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the present application. The appearances of such phrases in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is to be expressly or implicitly understood by one of ordinary skill in the art that the embodiments described in this application may be combined with other embodiments without conflict.
The above examples only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the patent protection. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, and these are all within the scope of protection of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.

Claims (10)

1. A method for storing static data, the method comprising:
the method comprises the steps of obtaining a plurality of static data to be stored and obtaining a shared memory for storing the static data;
creating a hash table for storing the static data according to a preset first hash algorithm, wherein a plurality of hash indexes in the hash table respectively correspond to at least one piece of static data;
and storing the static data in the shared memory according to the hash table, and recording the address information of the static data in the shared memory in the hash table.
2. The method according to claim 1, wherein the storing the static data in the shared memory according to the hash table comprises:
and according to the corresponding relation between the hash index and the static data, sequentially storing the static data corresponding to the hash indexes in the hash table in the shared memory.
3. The method according to claim 2, wherein the storing the static data in the shared memory according to the hash table further comprises:
and when the same hash index corresponds to a plurality of pieces of static data, sequentially storing the plurality of pieces of static data in the shared memory.
4. The method for storing static data according to claim 2 or claim 3, wherein the recording address information of the static data in the shared memory in the hash table includes:
and respectively recording initial storage addresses of the static data corresponding to the hash indexes in the shared memory in the hash table, wherein the initial storage addresses respectively correspond to the hash indexes.
5. The method for storing static data according to claim 1, wherein before the creating a hash table for storing the static data according to a preset first hash algorithm, the method comprises:
acquiring different multiple second hash algorithms, and generating multiple groups of hash indexes corresponding to the static data according to the multiple second hash algorithms respectively;
and respectively calculating the average collision times of the multiple groups of hash indexes, and marking a second hash algorithm corresponding to the group of hash indexes with the minimum average collision times as the first hash algorithm.
6. A query method for static data is characterized in that the query method comprises the following steps:
acquiring a storage address of static data to be queried in a shared memory, wherein the static data is stored in the shared memory by using the static data storage method of any one of claims 1 to 5;
obtaining a hash index corresponding to target static data through a first hash algorithm, and determining a target position of the target static data in the shared memory according to the hash index;
and querying the target static data at a target position in the shared memory.
7. The method according to claim 6, wherein the querying the target static data at the target location in the shared memory comprises:
and when hash collision is encountered, sequentially inquiring the target static data in the shared memory by taking the target position as a starting position.
8. A storage device for static data, the storage device comprising:
the acquisition module is used for acquiring a plurality of static data to be stored and acquiring a shared memory for storing the static data;
the creating module is used for creating a hash table used for storing the static data according to a preset first hash algorithm, wherein a plurality of hash indexes in the hash table correspond to at least one piece of static data respectively;
and the storage module is used for storing the static data in the shared memory according to the hash table and recording the address information of the static data in the shared memory in the hash table.
9. An apparatus for querying static data, the apparatus comprising:
a memory obtaining module, configured to obtain a storage address of static data to be queried in a shared memory, where the static data is stored in the shared memory by using the static data storage method according to any one of claims 1 to 5;
the position determining module is used for acquiring a hash index corresponding to the target static data through a first hash algorithm and determining a target position of the target static data in the shared memory according to the hash index;
and the data query module is used for querying the target static data at the target position in the shared memory.
10. An electronic device comprising a memory and a processor, wherein the memory has stored therein a computer program;
the processor is arranged to run the computer program to perform the method of storing static data of any one of claims 1 to 5;
or the processor is arranged to run the computer program to perform the method of querying static data as claimed in claim 6 or claim 7.
CN202210820747.6A 2022-07-13 2022-07-13 Static data storage and query method and device and electronic device Pending CN115221167A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210820747.6A CN115221167A (en) 2022-07-13 2022-07-13 Static data storage and query method and device and electronic device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210820747.6A CN115221167A (en) 2022-07-13 2022-07-13 Static data storage and query method and device and electronic device

Publications (1)

Publication Number Publication Date
CN115221167A true CN115221167A (en) 2022-10-21

Family

ID=83612547

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210820747.6A Pending CN115221167A (en) 2022-07-13 2022-07-13 Static data storage and query method and device and electronic device

Country Status (1)

Country Link
CN (1) CN115221167A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115576954A (en) * 2022-11-24 2023-01-06 恒生电子股份有限公司 Hash table determining method and device

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115576954A (en) * 2022-11-24 2023-01-06 恒生电子股份有限公司 Hash table determining method and device
CN115576954B (en) * 2022-11-24 2023-04-07 恒生电子股份有限公司 Hash table determining method and device

Similar Documents

Publication Publication Date Title
CN109710655B (en) Database query method, device, terminal equipment and storage medium
CN106503008B (en) File storage method and device and file query method and device
CN101958838A (en) Data access method and device
CN108228799B (en) Object index information storage method and device
CN113553339B (en) Data query method, middleware, electronic device and storage medium
CN115221167A (en) Static data storage and query method and device and electronic device
CN113704307A (en) Data query method, device, server and computer readable storage medium
CN112328458A (en) Data processing method and device based on flink data engine
CN111859127A (en) Subscription method and device of consumption data and storage medium
CN115221119A (en) File searching method and device, storage medium and electronic equipment
CN112148477A (en) Service process processing method, electronic device and storage medium
CN110928900B (en) Multi-table data query method, device, terminal and computer storage medium
US9836491B1 (en) Method and apparatus for hardware-implemented AVL tree updates
CN112905600B (en) Data query method and device, storage medium and electronic equipment
CN114116952A (en) Graph data access method, electronic device and storage medium
CN115905168B (en) Self-adaptive compression method and device based on database, equipment and storage medium
CN106446080B (en) Data query method, query service equipment, client equipment and data system
CN115357606A (en) Data source query method, system, computer equipment and storage medium
CN111400266A (en) Data processing method and system, and diagnosis processing method and device of operation event
CN114661762A (en) Query method and device for embedded database, storage medium and equipment
CN115599801A (en) Data query method, system, electronic equipment and storage medium
CN109101595A (en) A kind of information query method, device, equipment and computer readable storage medium
CN111200608B (en) Link information processing method and device
CN114416371A (en) Grid space management method, storage medium and electronic device
CN112699149A (en) Target data acquisition method and device, storage medium and electronic device

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