Data issuing method and device, computer equipment and medium
Through the associated storage of data sharding and distributed hash tables between multiple servers, combined with load balancing and real-time data synchronization, the bottleneck problem of traditional data delivery methods under concurrent requests is solved, and efficient and reliable data are achieved. Processing and system stability.
Patent Information
- Application Number
- CN202411034851.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-31
- Publication Date
- 2024-09-13
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Traditional data delivery methods can easily cause bottlenecks when faced with a large number of concurrent requests, leading to increased latency, data loss, and system instability.
By sharding data and using distributed hash tables to associate storage with multiple servers, combined with load balancers and real-time data synchronization, we ensure the consistency and reliability of data across multiple servers, and use hash functions to quickly locate data. , and seamlessly recover in case of node failure.
It achieves data load balancing, improves system performance and efficiency, supports millions of concurrent data delivery, avoids single points of failure, and improves the overall performance, security and reliability of the system.
Smart Images

Figure CN118643102A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a data sending method, device, computer equipment and medium. Background Art
[0002] With the rapid development of the Internet of Things (IoT), 5G communication technology and big data, edge computing, as an emerging computing paradigm, is gaining increasing attention. By deploying computing resources at the edge of the network, edge computing can provide low latency, high bandwidth and localized data processing capabilities, effectively alleviating the pressure on cloud computing centers, while also improving the real-time and security of data processing.
[0003] Data delivery refers to the process of transmitting data from a central server to edge devices, which places strict requirements on real-time, reliability, and device response speed. Traditional data delivery methods often rely on centralized data storage and distribution, which can easily cause bottlenecks when faced with a large number of concurrent requests, leading to increased latency, data loss, and system instability. Summary of the invention
[0004] In view of this, an embodiment of the present invention provides a data delivery method to solve the technical problem in the prior art that data delivery is prone to bottlenecks when facing a large number of concurrent requests. The method includes: Slice the data to obtain a plurality of data slices, and associate and store the data slices with a plurality of servers respectively through a distributed hash table, wherein the distributed hash table is used to record the association relationship between each server and one of the data slices, and the distributed hash table runs on each of the servers; Distribute each data sending request sent by the client to one of the multiple servers through a load balancer; Maintain data consistency through real-time data synchronization between servers; In each of the servers, a hash value is calculated for the data requested by the data sending request based on a hash function, and the requested data is retrieved according to the hash value based on the distributed hash table; The retrieved data requested by the data sending request is returned to the client.
[0005] The embodiment of the present invention also provides a data sending device to solve the technical problem in the prior art that data sending is prone to bottlenecks when facing a large number of concurrent requests. The device includes: A shard storage module, used for sharding data to obtain multiple data slices, and storing the data slices in association with multiple servers respectively through a distributed hash table, wherein the distributed hash table is used to record the association relationship between each server and one data slice, and the distributed hash table runs on each server; A request distribution module, used for distributing each data sending request sent by the client to one of the multiple servers through a load balancer; Data synchronization module, used to maintain data consistency through real-time data synchronization between servers; A retrieval module, configured to calculate a hash value for the data requested by the data sending request based on a hash function in each of the servers, and retrieve the requested data according to the hash value based on the distributed hash table; The return module is used to return the retrieved data requested by the data sending request to the client.
[0006] An embodiment of the present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements any of the above-mentioned data sending methods when executing the computer program, so as to solve the technical problem in the prior art that data sending easily causes bottlenecks when facing a large number of concurrent requests.
[0007] An embodiment of the present invention also provides a computer-readable storage medium storing a computer program for executing any of the above-mentioned data sending methods to solve the technical problem in the prior art that data sending easily causes bottlenecks when facing a large number of concurrent requests.
[0008] Compared with the prior art, the beneficial effects that can be achieved by at least one of the above-mentioned technical solutions adopted in the embodiments of this specification include at least: slicing data to obtain multiple data slices, and associating and storing the data slices with multiple servers respectively through a distributed hash table, wherein the distributed hash table is used to record the association relationship between each server and a data slice, and the distributed hash table runs on each server; distributing each data sending request sent by the client to one of the multiple servers through a load balancer; maintaining data consistency through real-time data synchronization between servers; in each server, calculating a hash value for the data requested by the data sending request based on a hash function, and retrieving the requested data according to the hash value based on the distributed hash table; and returning the data requested by the retrieved data sending request to the client. This application stores data in shards on different server nodes to ensure data load balancing and improve the overall performance of the system; quickly locates data through hash functions, effectively improving the efficiency of data reading and writing; due to the sharded storage of data and real-time data synchronization between servers, when a server fails, the data can be seamlessly restored on other servers, improving the reliability of the system; at the same time, based on load balancing of multiple data delivery requests, real-time data synchronization between servers, and seamless recovery from failures, it can support concurrent data delivery of millions of devices, effectively handle large-scale concurrent requests, avoid the impact of single point failures, and improve the overall performance, security and reliability of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0010] Figure 1 is a flow chart of a data sending method provided by an embodiment of the present invention; Figure 2 is a structural block diagram of a computer device provided by an embodiment of the present invention; Figure 3 It is a structural block diagram of a data sending device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0011] The embodiments of the present application are described in detail below with reference to the accompanying drawings.
[0012] The following describes the implementation methods of the present application through specific specific examples, and those skilled in the art can easily understand other advantages and effects of the present application from the content disclosed in this specification. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. The present application can also be implemented or applied through other different specific implementation methods, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present application. It should be noted that, in the absence of conflict, the following embodiments and the features in the embodiments can be combined with each other. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work belong to the scope of protection of the present application.
[0013] In an embodiment of the present invention, a data sending method is provided, such as Figure 1 As shown, the method includes: Step S101, slicing the data to obtain a plurality of data slices, and associating and storing the data slices with a plurality of servers respectively through a distributed hash table, wherein the distributed hash table is used to record the association relationship between each server and one of the data slices, and the distributed hash table runs on each of the servers; Step S102: Distribute each data sending request sent by the client to one of the multiple servers through a load balancer; Step S103: Maintaining data consistency through real-time data synchronization between servers; Step S104: In each of the servers, a hash value is calculated for the data requested by the data sending request based on a hash function, and the requested data is retrieved according to the hash value based on the distributed hash table; Step S105: Return the retrieved data requested by the data sending request to the client.
[0014] In this embodiment, data shards are stored on different server nodes to ensure data load balancing and improve the overall performance of the system; data is quickly located through hash functions to effectively improve the efficiency of data reading and writing; due to the sharded storage of data and real-time data synchronization between servers, when a server fails, the data can be seamlessly restored on other servers, thereby improving the reliability of the system; at the same time, based on the load balancing of multiple data delivery requests, real-time data synchronization between servers, and seamless recovery of failures, it can support concurrent data delivery of millions of devices, effectively handle large-scale concurrent requests, avoid the impact of single point failures, and improve the overall performance, security, and reliability of the system.
[0015] In one embodiment, the data slices are associated and stored with a plurality of servers respectively through a distributed hash table, including: Creating a circular hash table, mapping multiple nodes to the circular hash table, wherein the nodes correspond to the servers one by one; Setting a preset number of virtual nodes for each of the nodes; Acquire multiple key-value pairs for each of the data slices, wherein the key is an identifier that uniquely identifies a data item in the data slice, and the value is a hash value calculated for the data item by the hash function; Each key-value pair of each data slice is associated with each virtual node of the node corresponding to the data slice and stored.
[0016] In a specific implementation, when deleting the node, all the virtual nodes corresponding to the node are removed from the distributed hash table; When searching for the node, a hash value of a given key is calculated, and a virtual node corresponding to the hash value is searched in the distributed hash table, or a virtual node closest to and greater than or equal to the hash value is searched.
[0017] Virtual nodes are designed in DHT (Distributed Hash Table) to improve load balancing. In traditional DHT design, each physical node may correspond to a fixed hash space interval, and all key-value pairs falling into this interval will be stored on this physical node. However, this may lead to uneven load distribution, because some nodes may happen to be located in the hash interval of hot data, while other nodes are relatively idle.
[0018] To solve this problem, virtual nodes are used in this embodiment. Each physical node (server) can have multiple virtual nodes, which are evenly distributed on the hash ring. In this way, even if the virtual nodes under some physical nodes contain hot data, the virtual nodes under other physical nodes can absorb the remaining data, thereby achieving better load balancing.
[0019] The virtual node itself does not store data directly, but represents a storage location on one or more physical nodes. When a key-value pair is inserted into the DHT, its hash value determines in which virtual node's interval it should be placed. This virtual node is then mapped to a specific physical node, and the data is ultimately stored on that physical node. Therefore, the data storage location is determined by calculating the hash value of the key through a hash function, and then mapping this hash value to a hash ring, where evenly distributed virtual nodes on the ring guide the key-value pair to the correct physical node. If there are N physical nodes in the system, and each physical node has M virtual nodes, then there are a total of N×M virtual nodes distributed on the hash ring. The data will fall on the nearest virtual node based on its hash value, thus determining its storage location.
[0020] In practice, the MD5 (Message-Digest Algorithm 5) algorithm is used to generate a hash value for the key and convert the result into an integer. MD5 is a widely used cryptographic hash function that can accept information of any length and generate a 128-bit (16-byte) hash value, also known as a "digest". The main purpose of the MD5 algorithm is to ensure data integrity and consistency.
[0021] This embodiment implements consistent hashing, by distributing data on multiple nodes and balancing the load through virtual nodes. For node management, the ZooKeeper (distributed, open source coordination service framework) tool can be used to manage the addition and removal of nodes and perform health checks. For data storage and replication, each node uses local storage (such as HashMap) to store data, and the replication mechanism is used for data fault tolerance and high availability.
[0022] A distributed hash table is a decentralized distributed system that can effectively manage and store data. The following functions can be achieved through the DHT system of this embodiment: Data sharding: Store data shards on different server nodes to ensure data load balancing; Efficient retrieval: quickly locate data through hash functions to improve the efficiency of data reading and writing; Fault-tolerance mechanism: When a server fails, data can be seamlessly restored on other servers, improving system reliability.
[0023] In one embodiment, retrieving the requested data according to the hash value based on the distributed hash table includes: According to the hash value, search the distributed hash table for a virtual node corresponding to the hash value or a virtual node that is closest to and greater than or equal to the hash value; Determine the server corresponding to the node to which the found virtual node belongs as the server where the requested data is located; Retrieve the requested data from the local storage (eg, HashMap) of the server where the requested data is located.
[0024] In one embodiment, the data sending method further includes: For each node, based on the traffic characteristics of the historical data of the node, the data traffic of the node in a future preset time period is calculated; when the calculated data traffic is lower than a first threshold, the number of virtual nodes of the node is reduced; when the calculated data traffic is higher than a second threshold, the number of virtual nodes of the node is increased, wherein the second threshold is greater than the first threshold, wherein the traffic characteristics include the size of the traffic and the geographical distribution of the traffic; or, For each node, the data flow and data processing capacity of the node in a future preset time period are calculated based on the traffic characteristics of the node's historical data; based on the calculated data flow and data processing capacity, the virtual node of the node is migrated between nodes.
[0025] In this embodiment, by predicting the load of the node, the number and distribution of the virtual nodes of the node are adjusted dynamically and timely. For example, when the predicted data flow is lower than a certain threshold, the number of virtual nodes is reduced to save resources; when the predicted flow is higher than a certain threshold, the number of virtual nodes is increased to improve the load balancing capability; the distribution of virtual nodes on different physical nodes can also be adjusted according to the geographical distribution of the flow to optimize the data transmission path. Alternatively, the migration direction of the virtual node is calculated according to the predicted node load and data processing capability, for example, the virtual node is migrated to a node with stronger performance and lower predicted load to reduce potential load imbalance; or, the virtual node is migrated from a node with weaker performance and higher predicted load to release resources and further improve the data processing capability of the system.
[0026] In one embodiment, the method further comprises: The servers realize the real-time data synchronization through a master-slave replication or a dual-master replication mechanism; The operating status of each server is monitored in real time, an alarm is issued when an abnormality occurs in the server, and the data sending request is switched to a server without abnormality.
[0027] In this embodiment, master-slave replication, dual-master replication and other technologies are used to maintain data consistency among multiple servers, thereby ensuring real-time synchronization of data.
[0028] In the master-slave replication architecture, there is a clear master server (Master) and one or more slave servers (Slave). All write operations first occur on the master server, and then propagate these write operations to the slave server through the logging and replay mechanism, so that the data of the slave server is consistent with the master server; the slave server can be used to process read requests, reduce the burden on the master server, and provide data redundancy. Master-slave replication has the following advantages: it provides read-write separation, which can share read operations to the slave database and improve read performance; the slave database can be used as a backup, and if the master database fails, it can be quickly switched to the slave database; the slave database can be used for data analysis, report generation, etc., and will not affect the performance of the master database.
[0029] Dual-master replication is a more complex synchronization model in which two or more servers can accept write operations and synchronize data with each other, that is, each server is both the "master" and "slave" of other servers. Dual-master replication has the following advantages: improved throughput of write operations, because multiple nodes can accept write operations; high availability, if one node fails, another node can immediately take over its work without causing service interruption; better disaster recovery capabilities, because data is synchronized between multiple nodes.
[0030] Furthermore, in order to support multi-server delivery and millions of concurrent requests, a load balancing mechanism can be combined: a load balancer is used to distribute multiple data delivery requests to different servers to ensure load balancing of each server and improve the overall performance of the system, as well as a failover mechanism: when a server fails, an alarm can be issued and the request can be quickly switched to other servers to ensure high availability of the system. Through data synchronization, load balancing and failover, multi-server data delivery can be achieved, large-scale concurrent requests can be effectively handled, single point failures can be avoided, and the overall performance, security and reliability of the system can be improved.
[0031] In one embodiment, returning the retrieved data requested by the data sending request to the client includes: When the requested data is distributed in a plurality of the servers, the data retrieved from each of the servers is aggregated and the aggregated data is returned to the client; When the requested data is distributed in one of the servers, the data retrieved from the server is directly returned to the client.
[0032] In one embodiment, the method further comprises: The server is automatically managed and configured through automated operation and maintenance tools.
[0033] In this embodiment, by achieving real-time data synchronization between servers and using automated operation and maintenance tools to achieve rapid deployment and configuration, this embodiment ensures data consistency and high availability of the system and reduces operation and maintenance costs and complexity.
[0034] In one embodiment, the method further comprises: A cache mechanism is set for the server, and hot data is stored through the cache mechanism.
[0035] In specific implementation, the caching mechanism of Memcached (memory cache) is used to store hot data. During data storage and retrieval, the caching mechanism is used to increase data access speed and reduce direct access pressure on the database. Memcached is a high-performance, distributed memory object caching system used to accelerate the running speed of dynamic Web applications and reduce database load. Therefore, by setting up a caching mechanism, combined with monitoring and alarming as well as automated operation and maintenance, fast and seamless switching can be achieved.
[0036] In one embodiment, the database system includes a MongoDB database (a huge database, a type of NoSQL database, mainly processing unstructured and semi-structured data) and an InfluxDB database (a data influx database, an open source time series database). Specifically, MongoDB in the NoSQL database implements an efficient storage and fast access mechanism for large-scale distributed data. MongoDB is an open source, distributed file storage-based database system, which belongs to the document database type in the NoSQL (Not Only SQL, non-relational database management system) database category; MongoDB can be used to provide highly scalable and high-performance data storage solutions, especially suitable for Web applications that need to process large amounts of data and high concurrent access, with the following advantages: Dynamic mode: no predefined mode is required, and documents can change structure without notifying the database. This flexibility enables MongoDB to adapt to rapidly changing application requirements; Replication and high availability: MongoDB supports replication sets, which can automatically fail over to ensure data redundancy and high availability; Sharding: MongoDB can shard data onto multiple servers to achieve horizontal expansion and handle large data sets and high concurrent requests.
[0037] The InfluxDB database in the time series database is optimized for storing and querying time series data. It is mainly used to store and process time-stamped data in Internet of Things (IoT) devices. It has the following advantages: High-performance reading and writing: InfluxDB is designed to efficiently handle high-throughput write and read operations, suitable for real-time data collection and analysis; Time series data optimization: Its internal data model and storage engine are optimized for time series data, and can efficiently store and query this type of data; No external dependencies: InfluxDB is an independent database service that does not require additional databases or dependencies to run.
[0038] Therefore, in this embodiment, by optimizing the database, a basis is provided for fast data retrieval and data consistency under high concurrency.
[0039] In one embodiment, the method further comprises: In the .proto file (protocol buffer definition file, or simply referred to as Protobuf definition file), define the service interface HashmapService (hash map service) to describe the interaction mode between the server and the client, including defining the put method (storage method), the get method (retrieval method) and the message type corresponding to each method; Create a server-side HashmapServer class (hash map server class), use ServerBuilder (server builder) to build a server instance, and add a service implementation HashmapServiceImpl (hash map service implementation class), where HashmapServiceImpl is the implementation class that instantiates the service interface; Each data sending request sent by the client is received through the put method of HashmapServiceImpl, and the data requested by the data sending request is returned to the client through the get method of HashmapServiceImpl.
[0040] In this embodiment, when the client communicates with the server, gRPC is used for communication (gRPC is a high-performance, open source remote procedure call (RPC) framework), which uses Protocol Buffers as the interface definition language. Protocol Buffers is a data description language and serialization framework developed by Google for serialization of structured data. In this embodiment, gRPC is used for communication between the client and the server to implement the storage and retrieval functions of key-value pairs.
[0041] In specific implementation, the communication between the client and the server includes the following steps: Step 1: Define gRPC services and messages.
[0042] In the .proto file, define the service interface HashmapService, which contains two methods: Put and Get. Each method has its request and response message types, as follows: PutRequest (storage request): contains key-value pairs and is used to send data to the server; PutResponse: contains a Boolean value indicating whether the data was successfully stored; GetRequest: contains a key and is used to retrieve data from the server; GetResponse: contains a value as a response to the GetRequest; Step 2: Implement the server in Java.
[0043] (1) Create the server class HashmapServer, including: Start the server (start() method): specify the port that the server listens on (for example, 50051); Use ServerBuilder to build a server instance and add the service implementation HashmapServiceImpl (which implements the gRPC service interface HashmapService); start the server and set the JVM (Java Virtual Machine) shutdown hook to ensure that the server can be shut down gracefully; Stop the server (stop() method): shut down the server and release all resources; Block until the server is shut down (blockUntilShutdown() method): wait for the server to terminate; Main method (main() method): creates a HashmapServer instance, starts the server, and waits for it to shut down; (2) Implement the service method HashmapServiceImpl, including: put method: Receive the PutRequest object and extract the key and value from it; Store the key-value pairs into dataStore (data storage, a HashMap); Creates and sends a PutResponse object that contains an indication of the success of the operation.
[0044] Get method: Receive the GetRequest object and extract the key from it; Get the corresponding value from dataStore; Creates and sends a GetResponse object that contains the requested values.
[0045] Through the method in this embodiment, the logical steps of communication between the client and the server can be organized as follows: Define the protocol: define services and messages through .proto files; Compile the protocol: use the protoc compiler (protocol buffer compiler) to generate Java code; Server implementation: create servers, add service implementations, start and manage server lifecycle; Processing requests: handling client requests, storing and retrieving data in service implementations; Run the server: Start the server in the main method and keep it running.
[0046] Through the above steps, HashmapServer is the main class of the server, responsible for starting the service and listening to client requests; HashmapServiceImpl implements the RPC method defined in the service interface and is the carrier of business logic; these two parts together constitute a complete gRPC server implementation. The server can receive client requests through gRPC, process data storage and retrieval, and then return the corresponding response.
[0047] In this embodiment, a computer device is provided, such as Figure 2 As shown, it includes a memory 201, a processor 202, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, any of the above-mentioned data sending methods is implemented.
[0048] Specifically, the computer device may be a computer terminal, a server or a similar computing device.
[0049] In this embodiment, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program for executing any of the above-mentioned data sending methods.
[0050] Specifically, computer-readable storage media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer-readable storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable storage media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0051] Based on the same inventive concept, a data sending device is also provided in an embodiment of the present invention, as described in the following embodiments. Since the principle of solving the problem by the data sending device is similar to that of the data sending method, the implementation of the data sending device can refer to the implementation of the data sending method, and the repeated parts will not be repeated. As used below, the term "unit" or "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0052] Figure 3 is a structural block diagram of a data sending device according to an embodiment of the present invention. Figure 3 As shown, it includes: a shard storage module 301, a request distribution module 302, a data synchronization module 303, a retrieval module 304 and a return module 305. The structure is described below.
[0053] A shard storage module 301 is used to shard the data to obtain multiple data slices, and associate the data slices with multiple servers respectively for storage through a distributed hash table, wherein the distributed hash table is used to record the association relationship between each server and one data slice, and the distributed hash table runs on each server; A request distribution module 302, configured to distribute each data sending request sent by the client to one of the multiple servers through a load balancer; A data synchronization module 303 is used to maintain data consistency through real-time data synchronization between servers; A retrieval module 304 is used to calculate a hash value for the data requested by the data sending request based on a hash function in each of the servers, and retrieve the requested data according to the hash value based on the distributed hash table; The return module 305 is used to return the retrieved data requested by the data sending request to the client.
[0054] In one embodiment, the shard storage module 301 is further used to: Creating a circular hash table, mapping multiple nodes to the circular hash table, wherein the nodes correspond to the servers one by one; Setting a preset number of virtual nodes for each of the nodes; Acquire multiple key-value pairs for each of the data slices, wherein the key is an identifier that uniquely identifies a data item in the data slice, and the value is a hash value calculated for the data item by the hash function; Each key-value pair of each data slice is associated with each virtual node of the node corresponding to the data slice and stored.
[0055] In one embodiment, the retrieval module 304 is further configured to: According to the hash value, search the distributed hash table for a virtual node corresponding to the hash value or a virtual node that is closest to and greater than or equal to the hash value; Determine the server corresponding to the node to which the found virtual node belongs as the server where the requested data is located; The requested data is retrieved from the local storage of the server where the requested data is located.
[0056] In one embodiment, the apparatus further comprises: A first prediction module is used to calculate the data flow of each node within a preset time period in the future based on the flow characteristics of the historical data of the node; when the calculated data flow is lower than a first threshold, the number of virtual nodes of the node is reduced; when the calculated data flow is higher than a second threshold, the number of virtual nodes of the node is increased, wherein the second threshold is greater than the first threshold, wherein the flow characteristics include the size of the flow and the geographical distribution of the flow; or, The second prediction module is used to calculate the data flow and data processing capacity of each node within a future preset time period based on the flow characteristics of the node's historical data; and migrate the virtual node of the node between nodes based on the calculated data flow and data processing capacity.
[0057] In one embodiment, the apparatus further comprises: A synchronization module, used to achieve the real-time data synchronization between the servers through a master-slave replication or a dual-master replication mechanism; The monitoring and alarm module is used to monitor the operating status of each server in real time, issue an alarm when an abnormality occurs in the server, and switch the data sending request to a server without abnormality based on the real-time data synchronization.
[0058] In one embodiment, the returning module 305 is further used to: When the requested data is distributed in a plurality of the servers, the data retrieved from each of the servers is aggregated and the aggregated data is returned to the client; When the requested data is distributed in one of the servers, the data retrieved from the server is directly returned to the client.
[0059] In one embodiment, the apparatus further comprises: A service interface definition module, used to define a service interface hash mapping service in a protocol buffer definition file to describe an interaction mode between the server and the client, including defining a storage method, a retrieval method, and a message type corresponding to each method; A server-side hash map server class creation module is used to create a server-side hash map server class, use a server builder to build a server instance, and add a service implementation hash map service implementation class, where the hash map service implementation class is an implementation class that instantiates the service interface; A receiving and returning module is used to receive each data sending request sent by the client through the storage method of the hash mapping service implementation class, and return the data requested by the data sending request to the client through the retrieval method of the hash mapping service implementation class.
[0060] The embodiments of the present invention achieve the following technical effects: data is sliced to obtain multiple data slices, and the data slices are associated with multiple servers for storage through a distributed hash table, wherein the distributed hash table is used to record the association relationship between each server and a data slice, and the distributed hash table runs on each server; each data sending request sent by the client is distributed to one of the multiple servers through a load balancer; data consistency is maintained through real-time data synchronization between servers; in each server, a hash value is calculated for the data requested by the data sending request based on a hash function, and the requested data is retrieved according to the hash value based on the distributed hash table; and the data requested by the retrieved data sending request is returned to the client. This application stores data in shards on different server nodes to ensure data load balancing and improve the overall performance of the system; quickly locates data through hash functions, effectively improving the efficiency of data reading and writing; due to the sharded storage of data and real-time data synchronization between servers, when a server fails, the data can be seamlessly restored on other servers, improving the reliability of the system; at the same time, based on load balancing of multiple data delivery requests, real-time data synchronization between servers, and seamless recovery from failures, it can support concurrent data delivery of millions of devices, effectively handle large-scale concurrent requests, avoid the impact of single point failures, and improve the overall performance, security and reliability of the system.
[0061] Obviously, those skilled in the art should understand that the modules or steps of the above-mentioned embodiments of the present invention can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, and optionally, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the embodiments of the present invention are not limited to any specific combination of hardware and software.
[0062] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the embodiments of the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A data sending method, characterized in that: include: Slice the data to obtain a plurality of data slices, and associate and store the data slices with a plurality of servers respectively through a distributed hash table, wherein the distributed hash table is used to record the association relationship between each server and one of the data slices, and the distributed hash table runs on each of the servers; Distribute each data sending request sent by the client to one of the multiple servers through a load balancer; Maintain data consistency through real-time data synchronization between servers; In each of the servers, a hash value is calculated for the data requested by the data sending request based on a hash function, and the requested data is retrieved according to the hash value based on the distributed hash table; The retrieved data requested by the data sending request is returned to the client.
2. The data sending method according to claim 1, characterized in that: The data slices are respectively associated and stored with a plurality of servers through a distributed hash table, including: Creating a circular hash table, mapping multiple nodes to the circular hash table, wherein the nodes correspond to the servers one by one; Setting a preset number of virtual nodes for each of the nodes; Acquire multiple key-value pairs for each of the data slices, wherein the key is an identifier that uniquely identifies a data item in the data slice, and the value is a hash value calculated for the data item by the hash function; Each key-value pair of each data slice is associated with each virtual node of the node corresponding to the data slice and stored.
3. The data sending method according to claim 2, characterized in that: The retrieving the requested data according to the hash value based on the distributed hash table includes: According to the hash value, search the distributed hash table for a virtual node corresponding to the hash value or a virtual node that is closest to and greater than or equal to the hash value; Determine the server corresponding to the node to which the found virtual node belongs as the server where the requested data is located; The requested data is retrieved from the local storage of the server where the requested data is located.
4. The data sending method according to claim 2, characterized in that: The method further comprises: For each node, based on the traffic characteristics of the historical data of the node, the data traffic of the node in a future preset time period is calculated; when the calculated data traffic is lower than a first threshold, the number of virtual nodes of the node is reduced; when the calculated data traffic is higher than a second threshold, the number of virtual nodes of the node is increased, wherein the second threshold is greater than the first threshold, wherein the traffic characteristics include the size of the traffic and the geographical distribution of the traffic; or, For each node, the data flow and data processing capacity of the node in a future preset time period are calculated based on the traffic characteristics of the node's historical data; based on the calculated data flow and data processing capacity, the virtual node of the node is migrated between nodes.
5. The data sending method according to claim 1, characterized in that: The method further comprises: The servers realize the real-time data synchronization through a master-slave replication or a dual-master replication mechanism; The operating status of each server is monitored in real time, an alarm is issued when an abnormality occurs in the server, and the data sending request is switched to a server without abnormality.
6. The data sending method according to claim 1, characterized in that: The step of returning the retrieved data requested by the data sending request to the client includes: When the requested data is distributed in a plurality of the servers, the data retrieved from each of the servers is aggregated and the aggregated data is returned to the client; When the requested data is distributed in one of the servers, the data retrieved from the server is directly returned to the client.
7. The data sending method according to claim 1, characterized in that: The method further comprises: In the protocol buffer definition file, a service interface hash map service is defined to describe the interaction mode between the server and the client, including defining a storage method, a retrieval method, and a message type corresponding to each method; Create a server-side hash map server class, use the server builder to build a server instance, and add a service implementation hash map service implementation class, where the hash map service implementation class is an implementation class that instantiates the service interface; Each of the data sending requests sent by the client is received through the storage method of the hash mapping service implementation class, and the data requested by the data sending request is returned to the client through the retrieval method of the hash mapping service implementation class.
8. A data sending device, characterized in that: include: A shard storage module, used for sharding data to obtain multiple data slices, and storing the data slices in association with multiple servers respectively through a distributed hash table, wherein the distributed hash table is used to record the association relationship between each server and one data slice, and the distributed hash table runs on each server; A request distribution module, used for distributing each data sending request sent by the client to one of the multiple servers through a load balancer; Data synchronization module, used to maintain data consistency through real-time data synchronization between servers; A retrieval module, configured to calculate a hash value for the data requested by the data sending request based on a hash function in each of the servers, and retrieve the requested data according to the hash value based on the distributed hash table; The return module is used to return the retrieved data requested by the data sending request to the client.
9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the data sending method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program for executing the data sending method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Prediction-based network traffic load balancing method
CN108632159A
Data reading method and system
CN113535068A
Data resource storage method and device, query method and device and electronic equipment
CN116368482A
Message pushing method and device, computer equipment and storage medium
CN117176796A
Distributed processing system, dispatcher, and distributed processing management device
JP2013178677A
Cited By
Network data optimization management system and method based on artificial intelligence
CN119449627A
