A method and apparatus for graph data distribution in a distributed system
By employing an N*N dimensional device matrix arrangement and hash function mapping rules in a distributed system, the problem of load imbalance in graph data sharding is solved, achieving more efficient graph computation and memory utilization, and reducing the risk of data redundancy and memory overflow.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ALIPAY (HANGZHOU) INFORMATION TECH CO LTD
- Filing Date
- 2023-09-27
- Publication Date
- 2026-05-12
AI Technical Summary
In distributed systems, existing graph data sharding methods cannot effectively solve the problems of memory usage, load balancing, and efficiency, especially when the number of working devices is uneven, leading to memory overflow and load imbalance.
The working devices are arranged in an N*N dimensional device matrix. The node data is mapped to row and column indices through hash functions and mapping rules to achieve uniform distribution of graph data in the device matrix. The node allocation is optimized through iteration and data synchronization to ensure load balance.
It improves query efficiency and memory utilization for graph computing tasks, reduces data redundancy, reduces the risk of memory overflow, and achieves load balancing among multiple devices.
Smart Images

Figure CN117194690B_ABST
Abstract
Description
Technical Field
[0001] This specification relates to one or more embodiments in the field of graph processing, and more particularly to a method and apparatus for graph data distribution in a distributed system. Background Technology
[0002] In recent years, graph data applications, such as knowledge graphs, have been widely used in various scenarios. With the expansion of these applications, the scale of graph data has increased dramatically, far exceeding the memory limitations of a single machine. This poses challenges to downstream applications such as graph computing and graph deep learning. Currently, the traditional strategy in this field is to adopt a distributed approach, dividing large-scale graph data into multiple pieces through graph sharding, with each machine loading one piece and performing computations in a distributed manner.
[0003] In distributed solutions, the quality of sharding (the graph connectivity within a single shard and the degree of data redundancy between different shards) determines the memory usage, load balancing, and efficiency of downstream tasks. Conventional sharding solutions often cannot meet these requirements, so it is necessary to design more efficient graph sharding methods. Summary of the Invention
[0004] This specification describes one or more embodiments of a method and apparatus for graph data allocation in a distributed system, which aims to balance memory load among multiple working devices, reduce data redundancy, and improve operating efficiency.
[0005] In a first aspect, a method for graph data distribution in a distributed system is provided, the distributed system comprising N*N working devices arranged in an N*N-dimensional device matrix, the method being executed through any first working device therein, comprising:
[0006] Obtain node data of several nodes and edge data of several connecting edges in the first graph data, wherein the edge data indicates the two nodes connected by the corresponding connecting edge;
[0007] Based on the node data of any node, a preset mapping function is used to determine the target number of the node, wherein the mapping function is used to map the node data into integer data;
[0008] For any target connection edge, the first mapping rule is used to map the two target numbers of the two target nodes in its edge data to the row index and column index in the N*N dimensional device matrix, respectively, and the target working device is determined in the device matrix according to the row index and column index.
[0009] The relevant data of the target connection edge and the two target nodes are sent to the target working device.
[0010] In one possible implementation, the first map data is a portion of the map data randomly allocated to the first working device from the full map data.
[0011] In one possible implementation, the mapping function is a hash function.
[0012] In one possible implementation, it also includes:
[0013] Receive node and connection edge data sent by other working devices and store it as second graph data.
[0014] In one possible implementation, it also includes:
[0015] Identify an unlabeled node from the current second graph data as the seed node and label it;
[0016] Perform multiple iterations until all nodes in the second graph data are labeled, where any iteration includes:
[0017] Using the first mapping rule, the target number of the seed node is mapped to a first index number. Multiple working devices are determined from the device matrix based on the first index number. The multiple working devices include the working devices in the row indicated by the first index number and the working devices in the column indicated by the first index number.
[0018] Send a first request to the multiple working devices, the first request being used to request the unmarked neighbor nodes of the seed node and their corresponding connection edges;
[0019] The nodes received from the multiple working devices are stored in the second graph data and marked.
[0020] At least one node is selected from the received nodes as a new seed node.
[0021] In one possible implementation, the node data includes the node's initial number and type attribute; based on the node data of any node, a target number of the node is determined using a preset mapping function, including:
[0022] The initial number and the type attribute are concatenated to obtain the first string;
[0023] The first string is input into the mapping function to obtain the target number.
[0024] In one possible implementation, the target numbers of the two target nodes are respectively a first target number and a second target number, and the first target number is less than the second target number; using a first mapping rule, the two target numbers of the two target nodes in their edge data are respectively mapped to row indices and column indices in an N*N dimensional device matrix, including:
[0025] Using the first mapping rule, the first target number is mapped to the row index;
[0026] Using the first mapping rule, the second target number is mapped to the column index.
[0027] In one possible implementation, the first mapping rule is to take the modulo of N with respect to the corresponding target number.
[0028] In one possible implementation, it also includes:
[0029] Each time the first working device completes an iteration, it synchronizes its data with other working devices.
[0030] In one possible implementation, the data synchronization is accomplished via a message passing interface (MPI).
[0031] Secondly, an apparatus for graph data distribution in a distributed system is provided, the distributed system comprising N*N working devices arranged in an N*N dimensional device matrix, the apparatus being deployed on any first working device therein, comprising:
[0032] The acquisition unit is configured to acquire node data of several nodes and edge data of several connecting edges in the first graph data, wherein the edge data indicates the two nodes connected by the corresponding connecting edge;
[0033] The first determining unit is configured to determine the target number of the node based on the node data of any node using a preset mapping function, wherein the mapping function is used to map the node data into integer data.
[0034] The mapping unit is configured to, for any target connection edge, use the first mapping rule to map the two target numbers of the two target nodes in its edge data to the row index and column index in the N*N dimensional device matrix, and determine the target working device in the device matrix according to the row index and column index.
[0035] The sending unit is configured to send the relevant data of the target connection edge and the two target nodes to the target working device.
[0036] In one possible implementation, it also includes:
[0037] The receiving unit is configured to receive node and connection edge data sent by other working devices and store it as second graph data.
[0038] In one possible implementation, it also includes:
[0039] The second determining unit is configured to determine an unmarked node from the current second graph data as a seed node and mark it.
[0040] The iteration unit is configured to perform multiple iterations until all nodes in the second graph data are labeled, wherein any iteration includes:
[0041] Using the first mapping rule, the target number of the seed node is mapped to a first index number. Multiple working devices are determined from the device matrix based on the first index number. The multiple working devices include the working devices in the row indicated by the first index number and the working devices in the column indicated by the first index number.
[0042] Send a first request to the multiple working devices, the first request being used to request the unmarked neighbor nodes of the seed node and their corresponding connection edges;
[0043] The nodes received from the multiple working devices are stored in the second graph data and marked.
[0044] At least one node is selected from the received nodes as a new seed node.
[0045] In one possible implementation, it also includes:
[0046] The data synchronization unit is configured such that the first working device performs a data synchronization with other working devices once for each iteration.
[0047] Thirdly, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the method of the first aspect.
[0048] Fourthly, a computing device is provided, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, it implements the method of the first aspect.
[0049] This specification provides a method and apparatus for graph data allocation in a distributed system. The method can balance the memory load among multiple working devices, reduce the probability of multiple hotspots in the graph being distributed on the same group of working devices, thereby reducing data redundancy and improving operating efficiency. Attached Figure Description
[0050] To more clearly illustrate the technical solutions of the various embodiments disclosed in this specification, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only a few embodiments disclosed in this specification. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0051] Figure 1 This illustration shows an implementation scenario of a method for graph data allocation in a distributed system according to one embodiment.
[0052] Figure 2 A flowchart illustrating a method for graph data allocation in a distributed system according to one embodiment;
[0053] Figure 3 This diagram illustrates how a node and its neighboring nodes are distributed across multiple working devices according to one embodiment.
[0054] Figure 4 A flowchart illustrating a method for allocating nodes and connecting edges in one iteration according to one embodiment;
[0055] Figure 5 A schematic block diagram of an apparatus for distributing graph data in a distributed system according to one embodiment is shown. Detailed Implementation
[0056] The solution provided in this specification will now be described with reference to the accompanying drawings.
[0057] As mentioned earlier, in distributed systems, the quality of graph sharding (the connectivity within a single shard and the redundancy of graph data between different shards) determines the memory usage, load balancing, and efficiency of downstream tasks. In some schemes, multiple worker devices in the distributed system are arranged in an R x C rectangular array (R and C are not equal). Each worker device then reads a portion of the entire graph data according to certain rules before performing subsequent sharding operations. However, in these schemes, when the difference between R and C is large, memory load imbalances can occur among the multiple worker devices during reading and sharding, increasing the risk of memory overflow for the worker device with the highest memory usage. Therefore, in one or more embodiments of this specification, the number of worker devices in the distributed system is set to N*N, arranged in an N*N square array, i.e., R = C = N. The beneficial effects of this setting will be explained in detail in subsequent embodiments.
[0058] Figure 1 This diagram illustrates an implementation scenario of a method for graph data allocation in a distributed system according to one embodiment. Figure 1In the example, the distributed system consists of N*N worker devices. Any two worker devices can communicate with each other and can read graph data from a storage device that holds the complete graph data. The graph data consists of several nodes and the edges connecting the nodes. All N*N worker devices form an N*N dimensional matrix with a topological structure, and are numbered sequentially from 0 to N*N-1, starting from 0, in a left-to-right and top-to-bottom order. The N*N dimensional matrix also has row and column numbers, numbered from 0 to N-1, respectively.
[0059] First, in the initial allocation, all N*N working devices in the distributed system read a portion of subgraph data from the storage device containing the full graph data to be sharded. The union of these subgraph data constitutes the full graph data. Then, for any target connection edge of the subgraph data stored in its own storage, each working device uses a preset first mapping rule, based on the target node number, to map the two nodes connected by the target connection edge to the row and column indices of the device matrix, respectively. Then, it finds the corresponding target working device based on the row and column indices and sends the target connection edge and its two connected nodes to the target working device. After all working devices have sent the connection edges and nodes to their corresponding target working devices according to the above rules, the initial allocation is complete.
[0060] The initial allocation ensures that for any target node, all its one-hop neighbors (i.e., all nodes directly connected to it by edges) and their corresponding edges are distributed across only 2N-1 working devices in the r-th row or r-th column, where r is the target node's target number and the first mapping rule. In this way, for any subsequent graph sharding or other graph computation tasks based on finding neighbor nodes, each working device only needs to search for all neighbor nodes of a node from at most 2N-1 working devices, instead of searching from N*N working devices, thus improving query efficiency.
[0061] Optionally, after the first allocation, a second allocation is performed. Each worker device determines a node as a seed node from the graph data stored in its own memory and marks it. Then, it calculates the corresponding r value based on the target number of the seed node using the first mapping rule. Following the indication of the r value, it sends a request to at most 2N-1 worker devices in the r-th row or r-th column, requesting them to send the unmarked neighbor nodes of the seed node stored in their respective memory, along with their corresponding connecting edges. It receives these neighbor nodes and marks them. Then, it selects one or more nodes from the received neighbor nodes as new seed nodes, and performs the next round of requests and receptions until all nodes on all worker devices are marked, completing the second allocation.
[0062] The second allocation results in nodes that are close in distance to each other in the original graph being assigned to the same worker as much as possible. This leads to high graph connectivity in the subgraphs of a single worker and low redundancy of graph data between different workers. Furthermore, based on the results of the first allocation, in the second allocation process, any worker only needs to search for all neighboring nodes of a node from at most 2N-1 worker devices, thereby improving the efficiency of the second allocation.
[0063] The following describes the specific implementation steps of the above-mentioned distributed knowledge graph sharding method with reference to specific embodiments. Figure 2 A flowchart illustrating a method for graph data allocation in a distributed system according to one embodiment is provided. The method can be executed by any platform, server, or device cluster with computing and processing capabilities. It should be noted that the distributed system comprises N*N working devices arranged in an N*N dimensional device matrix. Figure 2 This only demonstrates the implementation steps on any one of the first working devices. Implementation steps on other working devices in the distributed system can be found by referring to [the previous section]. Figure 2 The steps in the process are as follows.
[0064] Figure 2This document illustrates a method for graph data allocation in a distributed system according to one embodiment. The distributed system comprises N*N working devices arranged in an N*N-dimensional device matrix. The method is executed through any first working device and includes at least the following steps: Step 202, acquiring node data of a plurality of nodes and edge data of a plurality of connecting edges in first graph data, wherein the edge data indicates the two nodes connected by the corresponding connecting edge; Step 204, determining the target number of the node based on the node data of any node using a preset mapping function, wherein the mapping function is used to map the node data into integer data; Step 206, for any target connecting edge, using a first mapping rule, mapping the two target numbers of the two target nodes in its edge data to row indices and column indices in the N*N-dimensional device matrix, respectively, and determining the target working device in the device matrix based on the row indices and column indices; Step 208, sending the relevant data of the target connecting edge and the two target nodes to the target working device.
[0065] First, in step 202, node data of several nodes and edge data of several connecting edges in the first graph data are obtained, wherein the edge data indicates the two nodes connected by the corresponding connecting edge.
[0066] The first graph data corresponds to a portion of the full graph data to be allocated; or, in other words, the first graph data is a subgraph of the full graph.
[0067] In a distributed system, all N*N worker devices read a portion of the subgraph data from the storage device containing the full graph data to be partitioned. The union of these subgraph data forms the full graph data. The full graph data can be split into several subgraphs using any method. For example, the full graph can be randomly divided into N*N subgraphs of the same size, with the first worker device reading its corresponding subgraph data; or the nodes / edges can be numbered and then divided into N*N equal subgraphs, with the first worker device reading its corresponding subgraph data.
[0068] In one embodiment, the first map data is a portion of the map data randomly assigned to the first working device from the full map data.
[0069] During the process of partitioning graph data into subgraphs, without any redundant storage, certain triples of the form Node 1-connecting edge-Node 2 in the entire graph will be irreversibly partitioned and stored on two working devices. For example, working device 1 stores Node 1-connecting edge, and working device 2 stores Node 2. During the recovery process, it becomes impossible to determine which node the other end of the connecting edge connects to, thus making it impossible to recover the triple. To recover triples stored on two working devices, redundant storage is necessary. This is typically done through two methods: edge partitioning and vertex partitioning. In edge partitioning, any connecting edge may be stored on multiple working devices, but any node will only be stored on one working device; that is, edge partitioning provides redundant storage for connecting edges. In vertex partitioning, any node may be stored on multiple working devices, but any connecting edge will only be stored on one working device; that is, vertex partitioning provides redundant storage for nodes. In edge partitioning, a restored triple can be obtained by merging the nodes at both ends of the same connecting edge stored on two working devices; in point partitioning, a triple consisting of all neighboring nodes and connecting edges of the same node stored on multiple working devices can be obtained by merging multiple neighboring nodes and their corresponding connecting edges of the node.
[0070] In one embodiment, the first working device reads the first graph data from the whole graph in a point-segmentation manner, so that there is redundancy of nodes between the graph data read by the first working device and other working devices, but no redundancy of connecting edges.
[0071] In step 204, based on the node data of any node, a preset mapping function is used to determine the target number of the node, wherein the mapping function is used to map the node data into integer data.
[0072] In one embodiment, the mapping function is a hash function, which can be any hash function that maps a string to integer data, such as MD5, SHA1, SHA256, etc., and is not limited here.
[0073] In one embodiment, node data includes an initial node number and a type attribute. The initial node number and the type attribute are concatenated to obtain a first string. The first string is then input into the mapping function to obtain the target node number.
[0074] Specifically, for a node, assuming its initial number is id and its type attribute is type, its corresponding target number newid = hash(id + type), where + represents concatenating the strings id and type.
[0075] Step 204 uses a mapping function to renumber the nodes based on their original data, so that the numbers of multiple nodes can be distributed more evenly in an integer space, making it easier to distribute the nodes and connecting edges to the working devices in subsequent steps.
[0076] In step 206, for any target connection edge, the first mapping rule is used to map the two target numbers of the two target nodes in its edge data to the row index and column index in the N*N dimensional device matrix, respectively, and the target working device is determined in the device matrix according to the row index and column index.
[0077] In one embodiment, the target numbers of the two target nodes are a first target number and a second target number, respectively, and the first target number is less than the second target number. In this case, the first mapping rule is used to map the first target number to the row index, and at the same time, the first mapping rule is used to map the second target number to the column index.
[0078] In one embodiment, the first mapping rule is to take the modulo of N with respect to the corresponding target number.
[0079] Specifically, as mentioned above, all N*N working devices form an N*N dimensional matrix with a topological structure. They are numbered sequentially from 0 to N*N-1, starting from left to right and from top to bottom. The N*N dimensional matrix also has row and column numbers, which are numbered from 0 to N-1, starting from 0.
[0080] For a connecting edge p, where the target number of its head node is s and the target number of its tail node is o, then according to the first mapping rule, the row index is min(s,o)%N and the column index is max(s,o)%N. That is, the row index is determined based on the node with the smaller target number, and the column index is determined based on the node with the larger target number. The number of the target working device in the device matrix is determined by (min(s,o)%N)*N+max(s,o)%N, which is the row index multiplied by the number of devices N in each row, plus the column index.
[0081] In step 208, the relevant data of the target connection edge and the two target nodes are sent to the target working device.
[0082] Step 208 ensures that any connecting edge in the entire graph is stored on only one working device, but any node may be stored on multiple devices, i.e., point splitting.
[0083] Through steps 206 and 208, for any node with target number e, e%N = r, then its neighboring nodes with target numbers less than e and the connecting edges between them will be assigned to at most N working devices in the r-th column, and its neighboring nodes with target numbers greater than e and the connecting edges between them will be assigned to at most N working devices in the r-th row. Considering that the working device in the r-th row and r-th column may appear in both the r-th row and r-th column, we need to decrement by 1 when counting. Therefore, all one-hop neighboring nodes of the node with target number e and their corresponding connecting edges can only be distributed in at most 2N-1 working devices in the r-th row or r-th column.
[0084] In a specific example Figure 3 This diagram illustrates how a node and its neighboring nodes are distributed across multiple worker devices according to one embodiment. Figure 3 As shown in (b), the distributed system has a total of 16 working devices arranged in a 4*4 device matrix, N=4, with horizontal and vertical numbering from 0 to 3. Each working device is represented by a square, and the content of the square represents the nodes and connections stored on that working device. Figure 3 As shown in (a), consider a node with a target number of 17 and all its neighboring nodes. The target numbers of the nodes are written inside the corresponding circles, and the line segments between the circles represent the connecting edges between the corresponding nodes. It should be noted that, for the sake of simplicity, this example hides the possible connecting edges between two neighboring nodes of node 17, and only considers the connecting edge between node 17 and its neighboring nodes. In other embodiments, there may also be connecting edges between two neighboring nodes. In some other embodiments, the connecting edges between nodes may also be directed edges, which are not shown in this example. For ease of representation, it is agreed that (node 1, node 2) represents the connecting edge between node 1 and node 2.
[0085] First, for the working device that stores the connecting edge (5,17), according to the first mapping rule, its corresponding target working device is in row (5%4) and column (17%4), that is, in row 1 and column 1. Therefore, this working device sends the connecting edge (5,17) and nodes 5 and 17 to the working device in row 1 and column 1. Figure 3 The content of the cell in the first row and first column of (b) is shown. Similarly, the working devices that store the connecting edges (6,17), (11,17), (12,17), and (16,17) send these connecting edges and their corresponding nodes to the target working device determined according to the first mapping rule, as follows. Figure 3(b) shows the contents of the four cells in row 0, column 1 to row 3, column 1. It can be seen that for the connection edge formed between a neighbor node with a target number less than 17 and node 17, it will only be sent to the four working devices in column 1. Furthermore, node 17 will be stored on multiple working devices, creating node redundancy, but any connection edge will only be sent and stored on one device.
[0086] Then, for the working device that has stored the connecting edge (17,20), according to the first mapping rule, its corresponding target working device is in row (17%4) and column (20%4), that is, row 1 and column 0. Therefore, this working device will send the connecting edge (17,20) and nodes 17 and 20 to the working device in row 1 and column 0, as follows: Figure 3 The content of the cell in row 1, column 0 of (b) is shown. Similarly, the working devices that store the connecting edges (17,21), (17,22), and (17,27) send these connecting edges and their corresponding nodes to the target working device determined according to the first mapping rule, as follows: Figure 3 The contents of the four cells in row 1, column 0 to row 1, column 3 of (b) are shown. It can be seen that for the connection edge formed between a neighbor node with a target number greater than 17 and node 17, it will only be sent to the four working devices in row 1. Furthermore, node 17 will be stored on multiple working devices, creating node redundancy, but any connection edge will only be sent and stored on one device.
[0087] After the allocation is complete, all neighboring nodes of node 17 and their corresponding edges are stored only on 7 working devices in the first row and first column (2*4-1=7 devices in total). Therefore, in subsequent steps, if a working device needs to find the devices that have stored the neighboring nodes and corresponding edges of node 17, it only needs to send a request to the 7 working devices in the first row and first column based on the result of taking 17 modulo 4 (1) to find all neighboring nodes and corresponding edges of node 17. This eliminates the need to send requests to all 16 working devices, improving query and communication efficiency.
[0088] It should be noted that in the above example, the target numbers of the nodes were intentionally designed to be very close to each other for ease of description and calculation. This does not constitute a limitation on the scheme. In other embodiments, the target numbers of multiple neighboring nodes of a node may be very far apart. For example, the target number of one neighboring node of node 319 may be 32563342, while the target number of another neighboring node may be 43245.
[0089] In conventional solutions, nodes are often numbered sequentially starting from a single number (e.g., 0 or 1) (rather than renumbering nodes using a mapping function to determine the target number). In some extreme cases, for node e, e % N = r, the modulo of N for all its neighboring nodes is equal, say b. Therefore, all neighbors and their corresponding edges will be assigned to only two workstations: the one at row b, column e, and the one at row e, column b, instead of the more evenly distributed 2N-1 workstations as intended. In even more extreme cases, when b = e, all neighbors and their corresponding edges will be assigned to only one workstation (row e, column e), leading to load imbalance across different workstations. If node e is also a hotspot, meaning its number of neighbors is much greater than other nodes, then all neighbors and their edges will be stored on even just one or two workstations, further causing load imbalance. Thus, in the second allocation in some subsequent embodiments, when a certain working device wants to request to receive multiple neighbor nodes of node e from other working devices, it can only communicate with the above two or even one working device, while the other working devices can only wait, causing a bottleneck.
[0090] It should be noted that in the more extreme case described above, node e's neighboring nodes appear to have been assigned to the same working device, let's say the first working device, thus seemingly achieving the goal of the subsequent second allocation. However, this is only a special case for a single node. Furthermore, according to the subsequent steps of the second allocation, node e and its neighboring nodes will ultimately be assigned to the second working device, which is not necessarily the first working device. In this situation, the second working device can only communicate with the first working device, not with at most 2N-1 working devices, thus still presenting a bottleneck.
[0091] By using step 204 in the embodiments of this specification to renumber the nodes using the mapping function, the target numbers of multiple neighboring nodes of any node can be evenly distributed in the integer space. After taking the modulo of N, they will also be more evenly distributed in the N positions from 0 to N-1, which greatly reduces the possibility of the above extreme cases occurring and makes the load of multiple working devices more balanced, that is, the memory usage on different working devices is more similar.
[0092] In some possible implementations, it also includes:
[0093] Step 210: Receive node and connection edge data sent by other working devices and store it as second graph data.
[0094] The second graph data refers to the graph data saved on the first working device after the first allocation is completed.
[0095] After obtaining the second graph data, for any target node, all its one-hop neighbor nodes (and corresponding connecting edges) will be distributed across at most 2N-1 working devices in the r-th row or r-th column, where r is the value calculated based on the target node's target number and the first mapping rule. In this way, when performing any graph sharding task or other graph computation task based on finding neighbor nodes, any working device only needs to search for all neighbor nodes of a node from at most 2N-1 working devices, instead of searching from N*N working devices, thus improving query efficiency. For example, a heuristic expansion method based on finding neighbor nodes can be used to shard the entire graph into multiple subgraphs.
[0096] Arranging N*N work devices in a square has the advantage of reducing the difference in memory usage between multiple work devices.
[0097] Consider a hotspot e, where e % N = r. Assume its neighboring nodes and corresponding edges are evenly distributed across 2N-1 working devices in row r and column r. Specifically, assume its m neighboring nodes with numbers less than the target number and their edges are evenly distributed across N working devices in column r, with each working device storing m / N edges; and its m neighboring nodes with numbers greater than the target number and their edges are evenly distributed across N working devices in row r, with each working device storing m / N edges. Under these assumptions, the working device in row r and column r stores m / N + m / N = 2m / N edges, while the other working devices store m / N edges. The maximum memory usage is twice the minimum memory usage.
[0098] If N*N working devices are arranged in a rectangle, for example, in 2N rows and N / 2 columns, for the hotspot e, its m neighboring nodes with numbers smaller than the target number and their connecting edges are evenly distributed on the N / 2 working devices in the e%(N / 2)th column, with each working device storing 2m / N connecting edges; its m neighboring nodes with numbers larger than the target number and their connecting edges are evenly distributed on the 2N working devices in the e%(2N)th row, with each working device storing m / (2N) connecting edges. At this time, the working device in the e%(2N)th row and e%(N / 2)th column stores (2m / N+m / 2N) = 5m / (2N) connecting edges, which is 5 times the number of connecting edges with the smallest memory footprint, m / (2N).
[0099] Therefore, arranging the working devices in a square can greatly reduce the difference in memory usage among multiple working devices, making the load of the distributed system more balanced.
[0100] In some possible implementations, the second allocation of the full-map data, which assigns multiple closely spaced nodes to the same working device as much as possible, also includes:
[0101] In step 212, an unmarked node is identified from the current second graph data as a seed node and then marked.
[0102] In step 214, multiple iterations are performed until all nodes in the second graph data are labeled, where any iteration can be performed as follows: Figure 4 As shown. Figure 4 A flowchart illustrating a method for allocating nodes and connecting edges in one iteration according to one embodiment is shown.
[0103] In step 402, the target number of the seed node is mapped to a first index number using the first mapping rule. Multiple working devices are determined from the device matrix based on the first index number. The multiple working devices include the working devices in the row indicated by the first index number and the working devices in the column indicated by the first index number.
[0104] Specifically, using the first mapping rule, the target number based on the seed node is mapped to r, and 2N-1 working devices in the r-th row and r-th column are determined from the device matrix.
[0105] In step 404, a first request is sent to the plurality of working devices. The first request is used to request the acquisition of the unmarked neighbor nodes of the seed node and the corresponding connection edges.
[0106] Specifically, the first working device sends a first request to the 2N-1 working devices in row r and column r. After receiving the request, the 2N-1 working devices search for the unmarked neighbor nodes of the target node in their stored graph data, and send the connecting edges between the neighbor nodes (i.e., the target node and the neighbor nodes) to the first working device.
[0107] In step 406, the nodes received from the multiple working devices are stored in the second graph data and marked.
[0108] In step 408, at least one node is determined from the received nodes as a new seed node.
[0109] Labeling a node ensures that any node in the entire graph will be reassigned one and only once.
[0110] Finding neighboring nodes based on seed nodes is a heuristic expansion process that ensures that nodes with close distances across the entire graph are assigned to the same working device as much as possible. It is understandable that if multiple nodes are identified as new seed nodes in step 408, the next iteration will involve parallel expansion based on these multiple seed nodes.
[0111] In some possible implementations, it also includes:
[0112] Each time the first working device completes an iteration, it synchronizes its data with other working devices.
[0113] Data synchronization enables any working device to obtain the latest status of other working devices. At the same time, after completing its current iteration expansion, it will wait for other working devices to complete their own iteration expansion before entering the next iteration.
[0114] During steps 402 to 408, if the numbers were not renumbered in step 204, as mentioned earlier, in extreme cases, the neighbor nodes of a hotspot might only be distributed across 1 or 2 working devices. When expanding this hotspot, these 1 or 2 working devices would frequently search for and send information about the hotspot's neighbor nodes, while other working devices would wait, creating a bottleneck in distributed computing. The renumbering in step 204 significantly reduces the likelihood of this bottleneck, ensuring that the target numbers of multiple neighbor nodes for any given node are evenly distributed in the integer space. After taking the modulo of N, the numbers are evenly distributed across the N positions from 0 to N-1, greatly reducing the probability of the aforementioned extreme situation and resulting in a more balanced load across multiple working devices.
[0115] In one embodiment, the data synchronization is accomplished through the Message Passing Interface (MPI).
[0116] According to another embodiment, an apparatus for distributing graph data in a distributed system is also provided. Figure 5 A schematic block diagram of an apparatus for graph data distribution in a distributed system according to one embodiment is shown. This apparatus can be deployed in any device, platform, or cluster of devices with computing and processing capabilities. Figure 5 As shown, the distributed system comprises N*N working devices arranged in an N*N dimensional device matrix, and the device 500 is deployed on any first working device therein, comprising:
[0117] The acquisition unit 501 is configured to acquire node data of several nodes and edge data of several connecting edges in the first graph data, wherein the edge data indicates the two nodes connected by the corresponding connecting edge.
[0118] The first determining unit 502 is configured to determine the target number of the node based on the node data of any node using a preset mapping function, wherein the mapping function is used to map the node data into integer data.
[0119] The mapping unit 503 is configured to, for any target connection edge, use the first mapping rule to map the two target numbers of the two target nodes in its edge data to the row index and column index in the N*N dimensional device matrix, respectively, and determine the target working device in the device matrix according to the row index and column index.
[0120] The sending unit 504 is configured to send the relevant data of the target connection edge and the two target nodes to the target working device.
[0121] In some possible implementations, it also includes:
[0122] The receiving unit 505 is configured to receive node and connection edge data sent by other working devices and store it as second graph data.
[0123] In some possible implementations, it also includes:
[0124] The second determining unit 506 is configured to determine an unmarked node from the current second graph data as a seed node and mark it.
[0125] Iteration unit 507 is configured to perform multiple iterations until all nodes in the second graph data are labeled, wherein any iteration includes:
[0126] Using the first mapping rule, the target number of the seed node is mapped to a first index number. Multiple working devices are determined from the device matrix based on the first index number. The multiple working devices include the working devices in the row indicated by the first index number and the working devices in the column indicated by the first index number.
[0127] Send a first request to the multiple working devices, the first request being used to request the unmarked neighbor nodes of the seed node and their corresponding connection edges;
[0128] The nodes received from the multiple working devices are stored in the second graph data and marked.
[0129] At least one node is selected from the received nodes as a new seed node.
[0130] In some possible implementations, it also includes:
[0131] The data synchronization unit 508 is configured such that the first working device performs a data synchronization with other working devices once for each iteration.
[0132] According to another embodiment, a computer-readable storage medium is also provided, on which a computer program is stored, which, when executed in a computer, causes the computer to perform the methods described in any of the above embodiments.
[0133] According to another embodiment, a computing device is also provided, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, it implements the method described in any of the above embodiments.
[0134] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the apparatus embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0135] The foregoing has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.
[0136] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes the element.
[0137] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0138] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for graph data allocation in a distributed system, the distributed system comprising N*N working devices arranged in an N*N dimensional device matrix, wherein any two working devices can communicate with each other; the method is executed through any first working device therein, comprising: Obtain node data of several nodes and edge data of several connecting edges in the first graph data, wherein the edge data indicates the two nodes connected by the corresponding connecting edge; Based on the node data of any node, a preset mapping function is used to determine the target number of the node, wherein the mapping function is used to map the node data into integer data; For any target connection edge, the first mapping rule is used to map the two target numbers of the two target nodes in its edge data to the row index and column index in the N*N dimensional device matrix, respectively, and the target working device is determined in the device matrix according to the row index and column index. The relevant data of the target connection edge and the two target nodes are sent to the target working device.
2. The method according to claim 1, wherein, The first map data is a portion of the map data randomly allocated to the first working device from the full map data.
3. The method according to claim 1, wherein, The mapping function is a hash function.
4. The method according to claim 1, further comprising: Receive node and connection edge data sent by other working devices and store it as second graph data.
5. The method according to claim 2, further comprising: Identify an unlabeled node from the current second graph data as the seed node and label it; Perform multiple iterations until all nodes in the second graph data are labeled, where any iteration includes: Using the first mapping rule, the target number of the seed node is mapped to a first index number. Multiple working devices are determined from the device matrix based on the first index number. The multiple working devices include the working devices in the row indicated by the first index number and the working devices in the column indicated by the first index number. Send a first request to the multiple working devices, the first request being used to request the unmarked neighbor nodes of the seed node and their corresponding connection edges; The nodes received from the multiple working devices are stored in the second graph data and marked. At least one node is selected from the received nodes as a new seed node.
6. The method according to claim 1, wherein, The node data includes the node's initial number and type attribute; based on the node data of any node, a target number of the node is determined using a preset mapping function, including: The initial number and the type attribute are concatenated to obtain the first string; The first string is input into the mapping function to obtain the target number.
7. The method according to claim 1, wherein, The target numbers of the two target nodes are the first target number and the second target number, respectively, with the first target number being less than the second target number. Using the first mapping rule, the two target numbers of the two target nodes in their edge data are mapped to row and column indices in an N*N dimensional device matrix, respectively, including: Using the first mapping rule, the first target number is mapped to the row index; Using the first mapping rule, the second target number is mapped to the column index.
8. The method according to claim 1, wherein, The first mapping rule is to take the modulo of N on the corresponding target number.
9. The method according to claim 5, further comprising: Each time the first working device completes an iteration, it synchronizes its data with other working devices.
10. The method according to claim 9, wherein, The data synchronization is accomplished through the information transmission interface (MPI).
11. An apparatus for graph data distribution in a distributed system, the distributed system comprising N*N working devices arranged in an N*N dimensional device matrix, wherein any two working devices can communicate with each other; the apparatus is deployed on any first working device therein, comprising: The acquisition unit is configured to acquire node data of several nodes and edge data of several connecting edges in the first graph data, wherein the edge data indicates the two nodes connected by the corresponding connecting edge; The first determining unit is configured to determine the target number of the node based on the node data of any node using a preset mapping function, wherein the mapping function is used to map the node data into integer data. The mapping unit is configured to, for any target connection edge, use the first mapping rule to map the two target numbers of the two target nodes in its edge data to the row index and column index in the N*N dimensional device matrix, and determine the target working device in the device matrix according to the row index and column index. The sending unit is configured to send the relevant data of the target connection edge and the two target nodes to the target working device.
12. The apparatus of claim 11, further comprising: The receiving unit is configured to receive node and connection edge data sent by other working devices and store it as second graph data.
13. The apparatus of claim 12, further comprising: The second determining unit is configured to determine an unmarked node from the current second graph data as a seed node and mark it. The iteration unit is configured to perform multiple iterations until all nodes in the second graph data are labeled, wherein any iteration includes: Using the first mapping rule, the target number of the seed node is mapped to a first index number. Multiple working devices are determined from the device matrix based on the first index number. The multiple working devices include the working devices in the row indicated by the first index number and the working devices in the column indicated by the first index number. Send a first request to the multiple working devices, the first request being used to request the unmarked neighbor nodes of the seed node and their corresponding connection edges; The nodes received from the multiple working devices are stored in the second graph data and marked. At least one node is selected from the received nodes as a new seed node.
14. The apparatus of claim 13, further comprising: The data synchronization unit is configured such that the first working device performs a data synchronization with other working devices once for each iteration.
15. A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the method of any one of claims 1-10.
16. A computing device comprising a memory and a processor, wherein, The memory stores executable code, and when the processor executes the executable code, it implements the method of any one of claims 1-10.