Graph data processing method, apparatus, device, storage medium, and program product
By employing multi-threaded parallel processing and shared memory techniques, the problems of high resource consumption and low efficiency in graph data layout are solved, achieving efficient graph data layout and improving user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- TENCENT TECHNOLOGY (SHENZHEN) CO LTD
- Filing Date
- 2023-04-27
- Publication Date
- 2026-07-10
AI Technical Summary
In existing technologies, the layout process of graph data is completed in the browser, resulting in high resource consumption and low efficiency. In particular, when there are many nodes, the page will lag, which will affect the user experience.
A multi-threaded parallel processing method is adopted. The main layout thread initializes shared memory and allocates nodes to multiple layout child threads. Each child thread reads node data from shared memory in parallel and adjusts its position. The main thread updates the node data until the stopping condition is met, thus completing the layout of the graph data.
It significantly improves layout speed and efficiency, reduces browser CPU usage, and enhances the user experience, especially when there are many nodes.
Smart Images

Figure CN118861364B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of network graph layout technology, and in particular to a graph data processing method, apparatus, computer equipment, storage medium and program product. Background Technology
[0002] With the continuous improvement and popularization of internet and computer technologies, data on the network can form complex graphs. Graphs, also known as network graphs or relationship graphs, are an abstract data type that includes nodes and edges, used to represent the relationships between multiple objects. Graph data layout, or graph data visualization, refers to the concrete display of abstract graph data through layout algorithms. However, graph data layout is usually done in the browser, and since graph data is often large, the layout process consumes browser resources and CPU, leading to page lag and low layout efficiency. Summary of the Invention
[0003] Therefore, it is necessary to provide a graph data processing method, apparatus, device, storage medium, and program product that can improve layout efficiency in response to the above-mentioned technical problems.
[0004] Firstly, this application provides a graph data processing method. The method includes:
[0005] Obtain graph data to be laid out, the graph data including multiple nodes and edge weights between adjacent nodes;
[0006] Create a main layout thread and multiple parallel layout sub-threads;
[0007] The layout main thread initializes shared memory based on the graph data and allocates different nodes to each layout sub-thread; the shared memory is used to record node data of each node, including node position, adjacent nodes, and edge weights between adjacent nodes;
[0008] Each of the layout sub-threads traverses the allocated nodes, reads the node data of the traversed nodes from the shared memory, and adjusts the node position of the traversed nodes according to the read node data.
[0009] The layout main thread updates the node data of the traversed nodes in the shared memory according to the adjusted node positions;
[0010] After each node in the shared memory is traversed, the step of allocating different nodes to each of the layout sub-threads through the layout main thread is returned to continue execution until the stopping condition is met, and the layout position of each node is obtained; the layout position is used to visualize the graph data.
[0011] Secondly, this application also provides a graph data processing apparatus. The apparatus includes:
[0012] The acquisition module is used to acquire graph data to be laid out, the graph data including multiple nodes and edge weights between adjacent nodes among the multiple nodes;
[0013] A multi-threaded creation module is used to create the main layout thread and multiple parallel layout sub-threads;
[0014] The node allocation module is used to initialize shared memory based on the graph data through the layout main thread, and to allocate different nodes to each of the layout sub-threads; the shared memory is used to record the node data of each node, and the node data includes the node position, adjacent nodes, and edge weights between adjacent nodes;
[0015] The node position update module is used to traverse the allocated nodes through each of the layout sub-threads, read the node data of the traversed nodes from the shared memory, and adjust the node position of the traversed nodes according to the read node data.
[0016] The shared memory update module is used to update the node data of the traversed nodes in the shared memory according to the adjusted node positions through the layout main thread;
[0017] The iterative loop module is used to return to the step of allocating different nodes to each of the layout sub-threads through the layout main thread after each node in the shared memory has been traversed, and continue execution until the stopping condition is met, so as to obtain the layout position of each node; the layout position is used to visualize the graph data.
[0018] In one embodiment, the acquisition module is further configured to: monitor graph data layout requests;
[0019] Upon detecting a graph data layout request sent by a client, establish a connection with the client;
[0020] After establishing a connection, the system receives the graph data to be laid out from the client.
[0021] In one embodiment, the multi-threaded creation module is further configured to: create a layout main thread, and during the initialization of the layout main thread, create a first parameter class, a first graph data class, and multiple computing unit classes through the layout main thread; the first parameter class is used to initialize the adjustment parameters for node positions and to update the adjustment parameters for node positions, the first graph data class is used to update the node data of each node recorded in the shared memory, and the multiple computing unit classes are used to create multiple parallel layout sub-threads;
[0022] During the initialization of each layout sub-thread, a second parameter class, a second graph data class, and a calculation class are created through each layout sub-thread. The second parameter class is used to synchronize the adjustment parameters from the first parameter class of the layout main thread. The second graph data class is used to read the node data of the allocated nodes from the shared memory. The calculation class is used to traverse the allocated nodes, read the node data of the traversed nodes from the shared memory, and adjust the node position of the traversed nodes according to the read node data.
[0023] In one embodiment, the node allocation module is further configured to: randomly determine the initial node position of each node in the graph data through the layout main thread;
[0024] Based on the initial node position, adjacent nodes, and edge weights between adjacent nodes, the node data of each node in the graph data is determined;
[0025] The node identifier of each node and the corresponding node data are stored in the shared memory.
[0026] In one embodiment, the node allocation module is further configured to: divide the shared memory into multiple memory locations, wherein each memory location has a mapping relationship with the node identifier of each node in the graph data;
[0027] According to the mapping relationship, the node data of each node in the graph data is stored in the memory location corresponding to the node identifier.
[0028] In one embodiment, the node position update module is further configured to: obtain the allocated node list from the layout main thread through each of the layout sub-threads;
[0029] Iterate through the node identifiers in the node list;
[0030] Read the node data of the traversed node from the memory location corresponding to the node identifier in the shared memory.
[0031] In one embodiment, the node position update module is further configured to: calculate the current neighborhood energy of the traversed node based on the read node data;
[0032] Read the adjustment parameters used to update the node positions from the main thread of the layout;
[0033] Based on the node positions of the traversed nodes in the read node data and the adjustment parameters, determine the position to be adjusted for the traversed nodes.
[0034] Based on the neighboring nodes of the traversed node, the edge weights between the traversed nodes, and the position to be adjusted in the read node data, calculate the adjusted neighborhood energy of the traversed node.
[0035] Based on the current neighborhood energy and the adjusted neighborhood energy, determine whether to adjust the node position of the traversed node.
[0036] In one embodiment, the node position update module is further configured to: calculate the current neighborhood attraction and current surrounding density of the traversed node based on the read node data;
[0037] The current neighborhood energy of the traversed node is calculated based on the current neighborhood gravity and the current surrounding density.
[0038] In one embodiment, the node position update module is further configured to: read the node position of the adjacent node from the shared memory based on the adjacent nodes of the traversed node in the read node data;
[0039] Calculate the distance between the node position of the traversed node and the node positions of the adjacent nodes;
[0040] The neighborhood attraction of the traversed nodes is obtained by weighting and summing the corresponding distances based on the edge weights between the nodes and their neighboring nodes in the read node data.
[0041] In one embodiment, the node position update module is further configured to: determine the surrounding area with the traversed node as the center of the region based on the node position of the traversed node in the read node data;
[0042] Based on the location range of the surrounding area, iterate through the total number of nodes in the shared memory whose node positions fall within the location range;
[0043] The ratio of the total quantity to the surrounding area is used as the current surrounding density of the traversed node.
[0044] In one embodiment, the node position update module is further configured to: calculate the adjusted neighborhood attraction and adjusted surrounding density of the traversed node based on the neighboring nodes of the traversed node, the edge weights between the neighboring nodes, and the position to be adjusted in the read node data.
[0045] The adjusted neighborhood energy of the traversed nodes is calculated based on the adjusted neighborhood attraction and the adjusted surrounding density.
[0046] In one embodiment, the node position update module is further configured to: if the current neighborhood energy is less than or equal to the adjusted neighborhood energy, then not adjust the node position of the traversed node;
[0047] If the current neighborhood energy is greater than the adjusted neighborhood energy, then the node position of the traversed node is adjusted to the position to be adjusted.
[0048] In one embodiment, the iteration loop module is further configured to: read the node position of each node from the shared memory via the layout main thread;
[0049] The nodes and their corresponding positions are fed back to the client, so that the client can visualize the nodes in the graph data based on the node positions and the graph data.
[0050] Thirdly, this application also provides a computer device. The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to perform the following steps:
[0051] Obtain graph data to be laid out, the graph data including multiple nodes and edge weights between adjacent nodes;
[0052] Create a main layout thread and multiple parallel layout sub-threads;
[0053] The layout main thread initializes shared memory based on the graph data and allocates different nodes to each layout sub-thread; the shared memory is used to record node data of each node, including node position, adjacent nodes, and edge weights between adjacent nodes;
[0054] Each of the layout sub-threads traverses the allocated nodes, reads the node data of the traversed nodes from the shared memory, and adjusts the node position of the traversed nodes according to the read node data.
[0055] The layout main thread updates the node data of the traversed nodes in the shared memory according to the adjusted node positions;
[0056] After each node in the shared memory is traversed, the step of allocating different nodes to each of the layout sub-threads through the layout main thread is returned to continue execution until the stopping condition is met, and the layout position of each node is obtained; the layout position is used to visualize the graph data.
[0057] Fourthly, this application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program thereon, which, when executed by a processor, performs the following steps:
[0058] Obtain graph data to be laid out, the graph data including multiple nodes and edge weights between adjacent nodes;
[0059] Create a main layout thread and multiple parallel layout sub-threads;
[0060] The layout main thread initializes shared memory based on the graph data and allocates different nodes to each layout sub-thread; the shared memory is used to record node data of each node, including node position, adjacent nodes, and edge weights between adjacent nodes;
[0061] Each of the layout sub-threads traverses the allocated nodes, reads the node data of the traversed nodes from the shared memory, and adjusts the node position of the traversed nodes according to the read node data.
[0062] The layout main thread updates the node data of the traversed nodes in the shared memory according to the adjusted node positions;
[0063] After each node in the shared memory is traversed, the step of allocating different nodes to each of the layout sub-threads through the layout main thread is returned to continue execution until the stopping condition is met, and the layout position of each node is obtained; the layout position is used to visualize the graph data.
[0064] Fifthly, this application also provides a computer program product. The computer program product includes a computer program that, when executed by a processor, performs the following steps:
[0065] Obtain graph data to be laid out, the graph data including multiple nodes and edge weights between adjacent nodes;
[0066] Create a main layout thread and multiple parallel layout sub-threads;
[0067] The layout main thread initializes shared memory based on the graph data and allocates different nodes to each layout sub-thread; the shared memory is used to record node data of each node, including node position, adjacent nodes, and edge weights between adjacent nodes;
[0068] Each of the layout sub-threads traverses the allocated nodes, reads the node data of the traversed nodes from the shared memory, and adjusts the node position of the traversed nodes according to the read node data.
[0069] The layout main thread updates the node data of the traversed nodes in the shared memory according to the adjusted node positions;
[0070] After each node in the shared memory is traversed, the step of allocating different nodes to each of the layout sub-threads through the layout main thread is returned to continue execution until the stopping condition is met, and the layout position of each node is obtained; the layout position is used to visualize the graph data.
[0071] The aforementioned graph data processing method, apparatus, device, storage medium, and program product, after acquiring the graph data to be laid out, create a main layout thread and multiple parallel layout sub-threads. The main layout thread initializes shared memory based on the graph data and allocates different nodes to each layout sub-thread. This shared memory is used to record the node data of each node, including the node position, adjacent nodes, and edge weights between adjacent nodes. In this way, each layout sub-thread can traverse the allocated nodes, read the node data of the traversed nodes from the shared memory, and adjust the node position of the traversed nodes based on the read node data. Each layout sub-thread only needs to process the allocated nodes, which is time-efficient. Furthermore, the parallel reading of node data from the shared memory by multiple sub-threads can improve the efficiency of adjusting the position of each node and significantly improve the position update speed. Then, the layout main thread updates the node data of the traversed nodes in the shared memory according to the adjusted node positions. After each node in the shared memory is traversed, the step of allocating different nodes to each layout sub-thread by the layout main thread is returned to continue execution until the stopping condition is met, and the layout position of each node is obtained. The whole process is extremely efficient and improves the overall layout speed. Attached Figure Description
[0072] Figure 1 This is an application environment diagram of the data processing method in one embodiment;
[0073] Figure 2 This is a flowchart illustrating a data processing method in one embodiment;
[0074] Figure 3 This is a schematic diagram of the various threads in one embodiment;
[0075] Figure 4 This is a schematic diagram illustrating the application of graph data in a knowledge graph system in one embodiment;
[0076] Figure 5 This is a schematic diagram illustrating the interaction flow between the server and the client during the layout process in one embodiment;
[0077] Figure 6 This is a schematic diagram of the layout main thread and layout sub-threads in one embodiment;
[0078] Figure 7 This is a schematic diagram of the data structure of node locations in shared memory in one embodiment;
[0079] Figure 8 This is a schematic diagram of the storage structure of node locations in shared memory in one embodiment;
[0080] Figure 9 This is a schematic diagram illustrating the application flow of the data processing method in one embodiment;
[0081] Figure 10 This is a schematic diagram illustrating layout time data for different thread counts in one embodiment.
[0082] Figure 11 This is a schematic diagram illustrating the layout time consumption when different numbers of threads are enabled in one embodiment.
[0083] Figure 12 This is a diagram illustrating the comparison of layout time in one embodiment;
[0084] Figure 13 This diagram illustrates the CPU usage of data layout in related technologies.
[0085] Figure 14 This is a schematic diagram illustrating the CPU usage during data layout in one embodiment;
[0086] Figure 15 This is a structural block diagram of the data processing device in one embodiment;
[0087] Figure 16 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0088] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0089] The technical terms used in this embodiment are explained below:
[0090] A graph, also known as a network graph or relationship graph, is an abstract data type consisting of nodes and edges, used to represent the relationships between multiple objects.
[0091] Node: The main object in the diagram, usually a circular shape, representing an object that can represent anything, such as a user, a book, an account, an article, etc.
[0092] Edge: A line connecting nodes, usually a straight line, sometimes with an arrow. Edges represent the relationships between nodes.
[0093] Layout of graph data: By using certain layout algorithms, the nodes and edges in the graph are arranged in a reasonable manner, making the relationships and connections between nodes clearer and easier to understand. This can help people better understand the complex relationships and structures in the graph and improve their ability to understand and analyze graph data.
[0094] Current network graph layout methods require extensive computation throughout the entire layout process, and each step needs to acquire information from all nodes, resulting in long processing times and low layout efficiency. Furthermore, the entire layout process is completed within the browser on the terminal, consuming the browser's main process and causing significant CPU usage. When there are many nodes, the page becomes very laggy, further impacting layout efficiency. Therefore, to address these issues, this application provides a graph data processing method that redesigns the data structure, layout algorithm, and layout process. It utilizes shared memory to store the required data, enabling multi-core parallel layout operations. Simultaneously, the layout process can be completed on a server, significantly improving layout speed, reducing CPU usage in the user's browser, and enhancing the user experience.
[0095] The graph data processing method provided in this application embodiment can be applied to, for example... Figure 1 In the application environment shown, server 104 obtains graph data to be laid out from terminal 102. The graph data includes multiple nodes and edge weights between adjacent nodes. Server 104 creates a main layout thread and multiple parallel layout sub-threads. Server 104 initializes shared memory based on the graph data through the main layout thread and allocates different nodes to each layout sub-thread. The shared memory is used to record node data for each node, including node position, adjacent nodes, and edge weights between adjacent nodes. Server 104 traverses the allocated nodes through each layout sub-thread, reads the node data of the traversed nodes from the shared memory, and adjusts the node position of the traversed nodes based on the read node data. Server 104 updates the node data of the traversed nodes in the shared memory based on the adjusted node positions through the main layout thread. After each node in the shared memory is traversed, server 104 returns to the step of allocating different nodes to each layout sub-thread through the main layout thread and continues execution until the stopping condition is met, obtaining the layout position of each node. The layout position is used to visualize the graph data. Optionally, the server 104 can feed back the layout position of each node to the terminal 102, and the terminal 102 can visualize the graph data based on the layout position of each node.
[0096] The terminal 102 can be, but is not limited to, various desktop computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices can include smart TVs, smart in-vehicle devices, etc. Portable wearable devices can include smartwatches, smart bracelets, head-mounted devices, etc. The server 104 can be implemented using a standalone server or a server cluster composed of multiple servers. The graph data processing method of this embodiment can be applied to various projects and products such as data dashboards, data analysis, and knowledge graphs.
[0097] In one embodiment, such as Figure 2As shown, a graph data processing method is provided, which can be applied to... Figure 1 Taking the server in the example, the following steps are included:
[0098] Step 202: Obtain the graph data to be laid out. The graph data includes multiple nodes and the edge weights between adjacent nodes.
[0099] Graph data is used to represent the relationships between multiple nodes. Graph data includes multiple nodes and the edge weights between adjacent nodes. A node can represent an object, such as a user, a product, an account, etc. Adjacent nodes refer to two nodes that are connected by an edge. The edge weight between adjacent nodes indicates the strength of the relationship between the two nodes. Generally, the larger the edge weight, the stronger the relationship. Each node in the graph data can be represented by a corresponding node identifier.
[0100] In some embodiments, the graph is generated based on network interaction data from the Internet. This network interaction data can be, for example, payment interaction data, instant messaging interaction data, online shopping interaction data, etc., and the corresponding network graph can be, for example, a payment relationship network graph, an instant messaging relationship network graph, and an online shopping relationship network graph, etc.
[0101] In one embodiment, the graph can be a payment relationship network graph. The steps for generating the payment relationship network graph include: obtaining payment records corresponding to user identifiers; obtaining payment interaction data between user identifiers based on the payment records; and generating a payment relationship network graph based on the payment interaction data. In this graph, nodes represent user identifiers, and the edges between two nodes indicate a payment interaction event between the two user identifiers. The payment interaction event is at least one of the following transaction events: money transfer, sending red envelopes, borrowing money, and QR code payment. In this embodiment, a user is a node, and if a payment interaction event exists between two users, an edge is formed between them. For example, if user A transfers money to user B, an edge is formed between user A and user B. It can be understood that when the number of users is large, the number of edges formed between these users is extremely large, resulting in an extremely large payment network graph. For example, in the WeChat Pay scenario, the number of nodes can reach 2 billion, and the number of edges formed between these 2 billion nodes can reach hundreds of billions.
[0102] In one embodiment, the graph can be a social relationship network graph. The steps for generating the social relationship network graph include: obtaining historical session data of user identifiers; generating a social relationship network graph based on the historical session data; wherein, nodes in the social relationship network graph represent user identifiers, and an edge between two nodes in the social relationship network graph indicates that there is a historical session between the corresponding two user identifiers. In this embodiment, a user is a node. If two users have a historical session, an edge will be formed between the two users. In another embodiment, if two users have added each other as friends, an edge will be formed between the two users. Similarly, when the number of users is large, the resulting social relationship network graph is also very complex.
[0103] In one embodiment, the graph can be a knowledge graph, and the steps for generating the knowledge graph include: extracting target data from different data sources; reasoning about the target data to obtain the relationships between the target data; and building a knowledge graph based on the target data and the relationships.
[0104] In one embodiment, the server can retrieve graph data stored on the server. In other embodiments, the server can receive graph data sent by other computer devices, such as graph data sent by a terminal, to perform graph data layout on the received graph data. For example, a browser running on a terminal receives user input; after the user selects graph data, it sends a layout request based on the graph data. The server receives the layout request sent by the terminal and extracts the graph data from the layout request.
[0105] Step 204: Create the main layout thread and multiple parallel layout sub-threads.
[0106] To improve the processing efficiency of each node and thus enhance layout efficiency, this embodiment employs a multi-threaded parallel processing approach for graph data. Specifically, upon receiving the graph data to be laid out, the server creates a main layout thread and multiple parallel layout sub-threads. The main layout thread is the program on the server that controls the layout process, while the layout sub-threads are created from the main layout thread and are used for data computation during the layout process. The multiple parallel layout sub-threads operate in parallel, processing data concurrently, and each sub-thread is independent of the main layout thread, not consuming its resources.
[0107] like Figure 3 The diagram shown illustrates the various threads in one embodiment. (Refer to...) Figure 3 The main layout thread is used to create layout sub-threads, initialize graph data, and allocate nodes for the layout sub-threads. The layout sub-threads are used to update node positions, thereby enabling parallel computation of graph layout and improving computational performance.
[0108] Specifically, after the server receives the graph data to be laid out, it creates a main layout thread. During the initialization of the main layout thread, multiple parallel layout sub-threads are created.
[0109] Step 206: The layout main thread initializes the shared memory based on the graph data and allocates different nodes to each layout sub-thread. The shared memory is used to record the node data of each node, including the node position, adjacent nodes, and edge weights between adjacent nodes.
[0110] The shared memory in this embodiment is memory accessible to both the main layout thread and the sub-layout threads. This shared memory can be memory within the server's storage system used to store graph data and node data, or it can be memory within other server-accessible storage systems used to store graph data and node data. The shared memory is used to record node data for each node, including node position, neighboring nodes, and edge weights between nodes.
[0111] Server initialization of shared memory refers to the process by which the server generates initial node data for each node based on the graph data and stores this initial node data in the shared memory. The initial node data for each node includes its initial position, its neighboring nodes, and the edge weights between them. The initial position of a node can be randomly generated by the server for each node. The server can also store the node identifier and its corresponding node data in the shared memory.
[0112] After initializing the shared memory, to improve the access efficiency of node data in the shared memory, the layout main thread allocates the nodes in the graph data to multiple layout sub-threads, and each layout sub-thread accesses the allocated nodes in the shared memory. Furthermore, in this embodiment, adjusting node positions involves multiple iterations. During each iteration, the layout main thread needs to allocate different nodes to each layout sub-thread. The following mainly describes the node allocation during one iteration.
[0113] When allocating nodes, the server can use either a random allocation principle or an ordered allocation principle. An ordered allocation principle, for example, involves the main layout thread assigning nodes with identifiers 1 to 5 to layout sub-thread 1, nodes with identifiers 6 to 10 to layout sub-thread 2, and so on. In this way, nodes in the graph data will be assigned to a layout sub-thread. That is, the server divides the node identifiers into multiple parts through the main layout thread, sending each part to a layout sub-thread, which then receives the nodes needed for the current iteration.
[0114] Step 208: Traverse the allocated nodes through each layout sub-thread, read the node data of the traversed nodes from the shared memory, and adjust the node position of the traversed nodes according to the read node data.
[0115] In this embodiment, the server reads the node data of the traversed nodes from the shared memory through a layout sub-thread, which can improve the efficiency of reading node data. The node position of the traversed nodes is adjusted according to the read node data. In this way, each layout sub-thread only needs to process the allocated nodes, which takes less time. Moreover, multiple sub-threads read node data from the shared memory in parallel, which can improve the efficiency of adjusting the position of each node and greatly improve the position update speed.
[0116] The server can set up node lists for each layout child thread through the main layout thread. These node lists include the node identifiers of the nodes that the layout child thread needs to traverse during the current iteration. The node identifiers in the node lists allocated by the main layout thread to each layout child thread do not overlap. Thus, after each layout child thread obtains its node list, it traverses the node identifiers in the list and reads the corresponding node data from shared memory.
[0117] For each traversed node, the server reads the node data from shared memory using a layout sub-thread. Based on this data, the server obtains the node's position, neighboring nodes, and edge weights between them. To reduce edge crossings and clutter during rendering, and to better represent the data structure, sub-network graph, and relationships between nodes, the layout sub-thread determines the adjusted position of each traversed node based on adjustment parameters during this iteration. It then calculates the neighborhood energy of the node before and after adjustment, using both the original node position and the adjusted position. Based on this neighborhood energy, the server determines whether to retain the original node position or adjust it to the desired position. Lower neighborhood energy results in lower total energy for the entire data graph, reducing edge crossings and clutter during rendering, and better representing the data structure, sub-network graph, and relationships between nodes, leading to a more even distribution of nodes.
[0118] Following the above method, for each assigned node, the layout sub-thread can determine whether to retain the node's original position or adjust its position to the desired position, and then feed this information back to the layout main thread. Each layout sub-thread, following the same method, can determine whether to retain the original position or adjust the position of all nodes in the graph data to the desired position.
[0119] The adjustment parameter is used to adjust the node position. The adjustment parameter has an initial value, and it changes as the iteration process progresses and the number of iterations increases.
[0120] Step 210: The layout main thread updates the node data of the nodes traversed in the shared memory according to the adjusted node positions.
[0121] Specifically, the server receives adjustment results for each node from various layout sub-threads via the main layout thread. For nodes that need to retain their previous positions, the layout sub-threads can send a node identifier to the main layout thread indicating that the node will not be adjusted; in this case, the main layout thread will not update the node positions in shared memory. For nodes that need to be adjusted to their desired positions, the layout sub-threads can send a node identifier and the corresponding desired adjustment position to the main layout thread. Once every node has been traversed, the server can receive the adjustment results for all nodes via the main layout thread, allowing the server to update the shared memory and complete the iteration process.
[0122] For example, consider a graph containing nodes 1 to 10, where node 1's neighbors are nodes 5 and 6, and there are two layout sub-threads (A and B). Taking the third iteration as an example, after the third iteration begins, the server assigns nodes 1-5 to layout sub-thread A and nodes 6-10 to layout sub-thread B via the main layout thread. Layout sub-thread A traverses the assigned nodes. When it reaches node 1, it reads the positions of node 1, its neighbors 5 and 6 from shared memory, and calculates the neighborhood energy of node 1 before adjustment based on these positions. Then, layout sub-thread A uses the adjustment parameters from this iteration to calculate the position to be adjusted for node 1. Based on the position to be adjusted for node 1 and the read positions of its neighbors 5 and 6, it calculates the neighborhood energy of node 1 after adjustment. Comparing the neighborhood energy before and after adjustment determines whether to retain the node position of node 1 in shared memory or update the node position of node 1 to the position to be adjusted. Similarly, when layout sub-thread A traverses to nodes 2, 3, 4, and 5, the processing is similar. Likewise, when layout sub-thread B traverses the allocated nodes, the processing is similar. Each node in shared memory is traversed once, which is considered one iteration.
[0123] Step 212: After each node in the shared memory has been traversed, return to the step of allocating different nodes to each layout sub-thread through the layout main thread and continue execution until the stopping condition is met, and obtain the layout position of each node; the layout position is used to visualize the graph data.
[0124] In this process, each node in the shared memory is considered to have been traversed once, constituting one iteration. The stopping condition can be set based on actual needs; for example, it could be that the number of iterations meets a preset number, or that the sum of the neighborhood energies of all nodes in the network graph after iteration is less than a preset value. When the stopping condition is met, the obtained layout position is the final layout position of the network graph. For example, in a knowledge graph system, after the network graph is laid out using the layout scheme of this embodiment, the final layout of the network graph is as follows: Figure 4 The image shown is a schematic diagram illustrating the application of graph data in a knowledge graph system in one embodiment.
[0125] It should be noted that when returning to the step of assigning different nodes to each layout sub-thread, the number of nodes assigned to the same layout sub-thread may be the same or different in multiple iterations.
[0126] Specifically, after each node in the shared memory is traversed, the server returns to the step of allocating different nodes to each layout sub-thread through the layout main thread and continues to execute until the iteration stop condition is met, thus obtaining the layout position of each node. The layout position of each node is then fed back to the terminal, which displays each node in the graph data according to the layout position.
[0127] In some embodiments, the main thread and multiple parallel sub-threads mentioned above can belong to a single server, meaning the layout process can be performed on a single server using a multi-threaded parallel layout approach. The main thread and multiple parallel sub-threads mentioned in this application's embodiments can be distributed across multiple servers; that is, a multi-server, multi-threaded parallel layout approach can also be used, but the data transfer and sharing methods will differ. For example, when using a single-server, multi-threaded parallel layout approach, data is shared and transferred through shared memory; when using a multi-server, multi-threaded parallel layout approach, data is shared and transferred through data sharing and transmission. For instance, the node data corresponding to the graph data is stored in a database. A master server is determined among the multiple servers, and the remaining servers are slave servers. The layout master thread runs on the master server, reading and updating node data from the database. On the slave servers, each parallel sub-thread runs, reading node data from the database.
[0128] In the graph data processing method described above, after acquiring the graph data to be laid out, a main layout thread and multiple parallel layout sub-threads are created. The main layout thread initializes shared memory based on the graph data and allocates different nodes to each layout sub-thread. This shared memory is used to record the node data of each node, including the node position, adjacent nodes, and edge weights between adjacent nodes. Thus, each layout sub-thread can traverse the allocated nodes, read the node data of the traversed nodes from the shared memory, and adjust the node positions of the traversed nodes based on the read node data. Each layout sub-thread only needs to process the allocated nodes, resulting in short processing time. Furthermore, the parallel reading of node data from the shared memory by multiple sub-threads improves the efficiency of adjusting node positions, significantly increasing the position update speed. Then, the main layout thread updates the node data of the traversed nodes in the shared memory based on the adjusted node positions. After each node in the shared memory is traversed, the process returns to the step of allocating different nodes to each layout sub-thread by the main layout thread, continuing until the stopping condition is met, thus obtaining the layout position of each node. The entire process is extremely efficient, improving the overall layout speed.
[0129] In one embodiment, the layout process is relatively resource-intensive, especially when there are many nodes, and can consume significant computing resources. Therefore, this embodiment obtains layout data from the terminal and executes the layout process on the server. Specifically, obtaining the graph data to be laid out includes: monitoring graph data layout requests; establishing a connection with the client when a graph data layout request is detected; and receiving the graph data to be laid out from the client after the connection is established.
[0130] Here, "client" refers to the application running on the terminal. The application can be a web-based client, such as a browser.
[0131] A graph data layout request is used to instruct the server to lay out the graph data to be laid out after establishing a connection with the client. For example, a graph data layout request can be a connection establishment request initiated by the client. After receiving the connection establishment request, the server establishes a connection with the client and receives the graph data to be laid out sent by the client. In this embodiment, the server can interact with the terminal's browser via the WebSocket protocol.
[0132] like Figure 5 The diagram shown illustrates the interaction flow between the server and client during the layout process in one embodiment. (Refer to...) Figure 5 The client sends a graph data layout request to the server. When the server receives the graph data layout request, it returns a connection status. If the connection status is good, the server and the client establish a connection. The client sends the graph data to be laid out to the server, and the server receives the graph data to be laid out sent by the client.
[0133] In this embodiment, by shifting the layout process from execution in the browser to execution on the server, resource consumption during the layout process can be reduced, the client page will not lag, and the user experience can be improved; multi-threaded layout can be implemented on the server, which can improve layout performance.
[0134] In some embodiments, since the layout process is time-consuming, ranging from several seconds to hundreds of seconds, if the entire iteration process is waited for before the layout position of each node is fed back to the client for display, the user will have to wait a long time, resulting in a poor user experience. Therefore, to solve the above problem, this embodiment further includes, after each node in shared memory has been traversed, the following:
[0135] The main thread reads the node position of each node from shared memory; the node and its corresponding position are then fed back to the client so that the client can visualize the nodes in the graph data based on the node positions and the graph data.
[0136] Specifically, such as Figure 5 As shown, after receiving the graph data to be laid out, the server performs an iterative process. The main layout thread and its sub-threads traverse the node data of all nodes in shared memory, completing one iteration. The server records the current iteration count and determines if it is the last iteration. If not, the main layout thread reads the node position of each node from shared memory and sends the node and its position back to the client. Upon receiving the node and its position from the server, the client renders and displays the nodes in the graph data based on their positions. Simultaneously, it returns to the step of updating the node positions of all nodes in the graph data using the main layout thread and its sub-threads. If the current iteration is the last iteration, the entire iteration process ends.
[0137] In this embodiment, the layout process is completed on the server, which greatly improves the layout speed, reduces the CPU usage of the user's browser, and enhances the user experience. Furthermore, after each node in the shared memory is traversed, the graph data is sent to the client. After receiving the graph data, the client renders it and updates the state on the page, which can reduce the user's waiting time and improve the user experience.
[0138] In one embodiment, creating a layout main thread and multiple parallel layout sub-threads includes the following steps:
[0139] 1. Create the layout main thread. During the initialization of the layout main thread, the first parameter class, the first graph data class, and multiple calculation unit classes are created through the layout main thread. The first parameter class is used to initialize the adjustment parameters of the node position and to update the adjustment parameters of the node position. The first graph data class is used to update the node data of each node recorded in the shared memory. The multiple calculation unit classes are used to create multiple parallel layout sub-threads.
[0140] The first parameter class is a data object used by the main layout thread to control parameters during iteration. The first graph data class is a data object used by the main layout thread to manage graph data. The computation unit class is a data object used by the main layout thread to manage and schedule layout sub-threads. For example... Figure 6 The diagram shown is a schematic representation of the layout of the main thread in one embodiment.
[0141] The adjustment parameter is used to adjust the node position. It has an initial value and changes as the iteration progresses and the number of iterations increases. The initial value of the adjustment parameter is derived from experience. After each node is traversed in shared memory, the adjustment parameter used to update the node position is updated through the first parameter class of the layout main thread. The adjustment parameter can be based on the number of iterations and a fixed step value, decreasing the initial adjustment parameter for the current iteration. For example, as the number of iterations increases, the adjustment parameter decreases uniformly with each iteration. For instance, in the nth iteration, the adjustment parameter T used to update the node position is equal to the initial adjustment parameter - n × step value. For example, if the initial adjustment parameter is 2000 and the step value for each iteration is 10, then the adjustment parameter for the 10th iteration is 2000 - 10 × 10 = 1900. Alternatively, as the number of iterations increases, the rate of decrease in the adjustment parameter becomes smaller.
[0142] Specifically, the server creates the layout main thread, and during the initialization of the layout main thread, it creates the first parameter class, the first graph data class, and multiple calculation unit classes.
[0143] 2. During the initialization of each layout sub-thread, a second parameter class, a second graph data class, and a calculation class are created through each layout sub-thread. The second parameter class is used to synchronously adjust parameters from the first parameter class of the layout main thread. The second graph data class is used to read the node data of the allocated nodes from shared memory. The calculation class is used to traverse the allocated nodes, read the node data of the traversed nodes from shared memory, and adjust the node position of the traversed nodes according to the read node data.
[0144] The second parameter class is a data object used by the layout sub-thread to adjust parameters in synchronization with the main layout thread. The second graph data class is a data object used by the layout sub-thread to read node data from shared memory. The calculation class is a data object used by the layout sub-thread to adjust node positions. The structure of the layout sub-thread is as follows: Figure 6 As shown.
[0145] Specifically, during the initialization of each computing unit class by the server, a layout sub-thread is created. During the initialization of the layout sub-thread, the second parameter class, the second graph data class, and the computing class are created.
[0146] In this example, a first graph data class is created in the main layout thread, and a second graph data class is created in the layout sub-thread. The node data stored in shared memory is read through the first and second graph data classes. By sharing the data, each sub-thread does not need to obtain the node data of all nodes, thus reducing the layout time. A first parameter class is created in the main layout thread, and a second parameter class is created in the layout sub-thread. The parameters are adjusted synchronously during the iteration process through the first and second parameter classes, ensuring the timeliness and consistency of the iteration.
[0147] In one embodiment, since the graph data to be laid out obtained by the server does not contain the initial positions of the nodes, in order to store the graph data to be laid out in shared memory, this embodiment initializes the shared memory to allocate initial positions to the nodes in the graph data to be laid out, thereby generating initial node data for each node in the graph data, and storing the initial node data in shared memory. Specifically, the layout main thread initializes the shared memory according to the graph data, including the following steps:
[0148] The initial node position of each node in the graph data is randomly determined by the layout main thread; based on the initial node position, adjacent nodes, and edge weights between adjacent nodes, the node data of each node in the graph data is determined; and the node identifier of each node and the corresponding node data are stored in shared memory.
[0149] The initial node position refers to the position of each node randomly determined by the server through the layout main thread after the server obtains the graph data. The node identifier is a unique identifier for each node, used to represent its identity, such as ID or node number. Each node is assigned a node identifier, which allows the layout main thread to quickly retrieve the corresponding node data from shared memory when reading node data.
[0150] Specifically, the server randomly determines the initial node position of each node in the graph data through the layout main thread, packages the initial node position, adjacent nodes, and edge weights between adjacent nodes into node data for that node, and stores the node identifier and node data corresponding to each node in shared memory. When the node position is updated, the layout main thread updates the node position of the node in shared memory according to the node identifier.
[0151] In this embodiment, the layout main thread initializes the shared memory, allocates initial node positions to each node in the graph data, generates initial node data based on the graph data of the nodes and the initial node positions, and stores the initial node data of each node in the shared memory, so that the layout sub-thread can adjust the node positions of each node.
[0152] In one embodiment, after a layout sub-thread acquires node data in shared memory, it locks the node data. After locking, other layout sub-threads cannot process the node data. After layout sub-thread A finishes processing the node data, it releases the lock, allowing other layout sub-threads to process the node data. However, multiple layout sub-threads may simultaneously acquire the same node data and lock it simultaneously, causing multiple layout sub-threads to be unable to process the same node data, resulting in a deadlock. Therefore, to avoid deadlocks when updating or reading / writing node data in shared memory, this embodiment stores the node identifier and corresponding node data in shared memory, including:
[0153] The shared memory is divided into multiple memory locations, and each memory location is mapped to the node identifier of each node in the graph data. According to the mapping relationship, the node data of each node in the graph data is stored in the memory location corresponding to the node identifier.
[0154] In this system, a mapping relationship exists between each memory location and the node identifier of each node in the graph data. This indicates that the node data corresponding to each node in the graph data is stored in a specified memory location, i.e., an ordered storage structure is used to store the node data. For example... Figure 7 The diagram shown is a schematic representation of the data structure of node locations in shared memory in one embodiment. Figure 8 This is a schematic diagram of the storage structure of node locations in shared memory in one embodiment. (Refer to...) Figure 8This storage structure is an ordered storage structure, storing node positions in an orderly manner. For example, assuming each node occupies 10B of memory, when searching for node 5, it can be read directly from the corresponding memory location [50, 60] without traversing the data of each node in the shared memory. Since the nodes allocated to each layout sub-thread in this embodiment are different, when reading the node data of the traversed node, the node position is read directly from the specified location according to the ordered storage structure of this embodiment, without traversing the data of each node in the shared memory, thereby avoiding deadlock caused by different layout sub-threads reading the same node data at the same time. This embodiment adopts an ordered storage structure, which can make the complexity of node query O(1), facilitate the read and write operations of different threads on data, and improve the node query speed.
[0155] In this embodiment, the graph data storage method has been redesigned. The graph data is stored in shared memory to facilitate read and write operations on the data by different threads. At the same time, an ordered storage structure is used to store the node positions, which can reduce the complexity of node query to O(1), facilitate read and write operations on the data by different threads, improve the node query speed, and ensure that no lock occurs when each layout sub-thread updates the node data.
[0156] In one embodiment, the node data of the traversed nodes is read from shared memory by traversing the allocated nodes through each layout sub-thread, including:
[0157] Each layout sub-thread obtains the allocated node list from the layout main thread; iterates through the node identifiers in the node list; and reads the node data of the traversed node from the memory location corresponding to the traversed node identifier in shared memory.
[0158] The server can set a node list for each layout sub-thread through the layout main thread. The node list includes the node identifiers of the nodes that the layout sub-thread needs to traverse in this iteration process. The node identifiers in the node list allocated by the layout main thread for each layout sub-thread do not overlap.
[0159] Specifically, the server allocates a node list to each layout sub-thread through the layout main thread. The node list includes the node identifiers of the nodes that the layout sub-thread needs to traverse. Based on the mapping relationship between the node identifiers in the node list and memory locations, the node data of the traversed node is read from the shared memory at the memory location corresponding to the traversed node identifier.
[0160] For example, the node list obtained by the layout sub-thread A includes node 1. According to the mapping relationship of the nodes stored in the shared memory, the node position of node 1 is stored in memory location [50, 60]. Then, the layout sub-thread reads the node data of node 1 at the memory location [50, 60] in the shared memory.
[0161] In this embodiment, the main layout thread allocates a node list to each layout sub-thread, and reads node data from the memory location corresponding to the node identifier in the shared memory according to the node identifier in the node list, which can improve the query speed of node data.
[0162] In one embodiment, adjusting the node position of the traversed nodes based on the read node data includes the following steps:
[0163] 1. Calculate the current neighborhood energy of the traversed nodes based on the read node data.
[0164] Here, the current neighborhood energy of the traversed node refers to the sum of the attractive and repulsive forces corresponding to the traversed node; attractive force is the force that brings nodes closer together, and repulsive force is the force that makes nodes move away from each other.
[0165] Specifically, the server calculates the attraction and repulsion forces corresponding to the traversed nodes based on the node data read, namely the neighboring nodes of the traversed node, the edge weights between the traversed nodes and the node positions, and uses the sum of the attraction and repulsion forces corresponding to the traversed nodes as the current neighborhood energy of the traversed node.
[0166] 1. Read the adjustment parameters used to update the node positions from the layout main thread.
[0167] In this process, after each node in shared memory is traversed, the adjustment parameters used to update the node's position are updated through the first parameter class of the layout main thread. The adjustment parameters are based on the number of iterations and a fixed step value, decreasing from the initial adjustment parameters. For example, in the nth iteration, the adjustment parameter T used to update the node's position is equal to the initial adjustment parameter - n × the step value. For instance, if the initial adjustment parameter is 2000 and the step value for each iteration is 10, then the adjustment parameter for the 10th iteration is 2000 - 10 × 10 = 1900.
[0168] Specifically, the server reads the adjustment parameters used to update the node position through the first parameter class of the layout main thread.
[0169] 3. Based on the node positions and adjustment parameters of the traversed nodes in the read node data, determine the position to be adjusted for the traversed nodes.
[0170] The coordinates of the position to be adjusted are calculated based on the following formula:
[0171] X = x + (0.5 - Rand) * T;
[0172] Y = y + (0.5 - Rand) * T.
[0173] Where X and Y are the x and y coordinates of the position to be adjusted of the traversed node; x and y are the x and y coordinates of the node position of the traversed node; Rand is a random number; and T is the adjustment parameter.
[0174] Specifically, the server reads the adjustment parameters used to update the node position through the layout main thread, and calculates the position to be adjusted of the traversed node based on the formula for calculating the position to be adjusted of the traversed node and the node position of the traversed node.
[0175] 4. Based on the neighboring nodes of the traversed nodes in the read node data, the edge weights between the traversed nodes and the position to be adjusted, calculate the adjusted neighborhood energy of the traversed nodes.
[0176] The method for calculating the adjusted neighborhood energy of the traversed node is the same as the method for calculating the current neighborhood energy of the traversed node.
[0177] Specifically, the server calculates the attraction and repulsion forces corresponding to the adjusted position of the traversed node based on the node data read, namely the neighboring nodes of the traversed node, the edge weights between the traversed node and the position to be adjusted, and uses the sum of the attraction and repulsion forces corresponding to the adjusted position of the traversed node as the adjusted neighborhood energy of the traversed node.
[0178] 5. Based on the current neighborhood energy and the adjusted neighborhood energy, determine whether to adjust the node position of the traversed nodes.
[0179] The layout sub-thread determines the position to be adjusted for the traversed nodes based on the adjustment parameters, and calculates the neighborhood energy of the traversed nodes before and after adjustment based on the node position before adjustment and the position to be adjusted. Based on the neighborhood energy before and after adjustment, it determines whether to retain the node position before adjustment or adjust the node position to the position to be adjusted mentioned above.
[0180] In this embodiment, when determining whether to adjust the position of a traversed node based on its current and adjusted neighborhood energies, the method can be as follows: First, it can be based on the sum of the current and adjusted neighborhood energies of the traversed nodes. Second, it can be based on the sum of the current and adjusted neighborhood energies of the traversed nodes. For example, if the layout sub-thread traverses nodes 1, 3, and 5, determining whether to adjust their positions can be done by first using the current and adjusted neighborhood energies of node 1, then the same method can be used for node 3, and so on, until the current node is the last traversed node. Alternatively, the method can be based on the sum of the current and adjusted neighborhood energies of nodes 1, 3, and 5.
[0181] In some embodiments, if the current neighborhood energy is less than or equal to the adjusted neighborhood energy, the node position of the traversed node is not adjusted; if the current neighborhood energy is greater than the adjusted neighborhood energy, the node position of the traversed node is adjusted to the position to be adjusted.
[0182] Specifically, the server updates node positions through a layout sub-thread. When determining whether a node needs to be updated, the layout sub-thread calculates the current neighborhood energy before the node position adjustment and the adjusted neighborhood energy after the node position adjustment. It compares the current neighborhood energy with the adjusted neighborhood energy to determine whether the node position needs to be adjusted in this iteration. That is, if the current neighborhood energy is less than or equal to the adjusted neighborhood energy, the node position of the traversed node is not adjusted; if the current neighborhood energy is greater than the adjusted neighborhood energy, the node position of the traversed node is adjusted to the position to be adjusted.
[0183] In this embodiment, based on the current neighborhood energy of the traversed node and the adjusted neighborhood energy of the traversed node, it is determined whether to adjust the node position of the traversed node. This can bring connected nodes closer together and unconnected nodes further apart, making the relationships and connections between nodes clearer and easier to understand the complex relationships and structures in the graph.
[0184] In one embodiment, calculating the current neighborhood energy of the traversed nodes based on the read node data includes:
[0185] Based on the read node data, the current neighborhood gravity and current surrounding density of the traversed nodes are statistically analyzed; based on the current neighborhood gravity and current surrounding density, the current neighborhood energy of the traversed nodes is calculated.
[0186] In this embodiment, the current surrounding density is used as the current repulsive force of the traversed node's neighborhood. The current surrounding density represents the ratio between the number of nodes in the surrounding region centered on the traversed node and the area of the surrounding region. The sum of the current neighborhood attraction and the current surrounding density is used as the current neighborhood energy of the traversed node.
[0187] In this embodiment, the formula for calculating the neighborhood energy corresponding to the traversed node xi is as follows:
[0188]
[0189] Where, x i Representing node i; x j d(x) represents the node j connected to node i. i ,x j ) 2 This represents the distance between the respective node positions of nodes i and j being read; w ij This represents the weight of the edge between nodes i and j; This represents the density near node i.
[0190] Specifically, based on the node data read by the layout sub-thread, the server calculates the current neighborhood attraction and current surrounding density of the traversed node, and determines the sum of the current neighborhood attraction and current surrounding density as the current neighborhood energy of the traversed node.
[0191] In this embodiment, the ratio between the number of nodes in the surrounding area of the traversed node as the center of the region and the area of the surrounding region is determined as the current neighborhood repulsion force of the traversed node. When calculating the current neighborhood repulsion force of the traversed node, it is not necessary to calculate the repulsion force between all nodes. Only the current surrounding density of the surrounding area of the traversed node needs to be calculated, which can reduce the amount of calculation and improve the layout efficiency.
[0192] In one embodiment, the current neighborhood attraction of the traversed nodes is calculated based on the read node data, including the following steps:
[0193] 1. Based on the neighboring nodes of the traversed nodes in the read node data, read the node positions of the neighboring nodes from the shared memory.
[0194] Specifically, the server reads the node data of the traversed nodes from the shared memory through the layout sub-thread. Based on the node identifiers of the adjacent nodes in the node data, it reads the node data of the adjacent nodes from the memory location corresponding to the node identifiers of the adjacent nodes in the shared memory. The server then parses the node data of the adjacent nodes to obtain the node positions of the adjacent nodes in the node data of the adjacent nodes.
[0195] 2. Calculate the distance between the position of the traversed node and the positions of its adjacent nodes.
[0196] Specifically, after obtaining the coordinates of the node position of the traversed node and the corresponding coordinates of the node positions of adjacent nodes, the server calculates the distance between the node position of the traversed node and the node positions of adjacent nodes according to the distance formula between two points.
[0197] Third, based on the edge weights between the read node data and adjacent nodes, the corresponding distances are weighted and summed to obtain the neighborhood attraction of the traversed nodes.
[0198] The edge weights between traversed nodes and their adjacent nodes are stored in the node data. Therefore, after obtaining the node data, the edge weights can be obtained by parsing the node data. According to the formula... The neighborhood attraction of the traversed node is obtained by weighting the edge weight of the node and the distance between the node and its neighboring nodes.
[0199] Specifically, the server parses and reads the node data, obtains the edge weights between the traversed node and its neighboring nodes, and performs a weighted sum of the edge weights between the node data and its neighboring nodes with the corresponding distances to obtain the neighborhood attraction of the traversed node.
[0200] In this embodiment, by packaging node positions, adjacent nodes, and edge weights into node data, when calculating neighborhood attraction, nodes with strong correlations are placed in close proximity through edge weights, making the relationships and connections between nodes clearer.
[0201] In one embodiment, based on the read node data, the current surrounding density of the traversed nodes is calculated, including the following steps:
[0202] 1. Based on the node positions of the traversed nodes in the read node data, determine the surrounding area centered on the traversed node.
[0203] The surrounding area refers to the region centered on the traversed node and having a defined geographical range. The shape and size of the surrounding area can be set based on the specific scenario.
[0204] Specifically, after the server reads the node data through the layout sub-thread, it parses the node data to obtain the node position, and determines the position range of the surrounding area based on the node position and the preset area range.
[0205] 2. Based on the location range of the surrounding area, traverse the total number of nodes in the shared memory whose locations fall within the location range.
[0206] The location range of the surrounding area is set based on the coordinates of the traversed nodes and the actual requirements. For example, if the coordinates of the traversed node are (x, y), the location range of the surrounding area is set to the region with the horizontal coordinate (xw, x+w) and the vertical coordinate (yw, y+w), where w represents the distance.
[0207] It should be noted that nodes falling within the surrounding area can be adjacent nodes of the traversed nodes or non-adjacent nodes; the determination can be made simply based on the node's position.
[0208] Specifically, the server iterates through the node positions of each node in the shared memory, determines the target nodes whose positions fall within the location range defined by the surrounding area, and counts the total number of target nodes.
[0209] 3. The ratio of the total number to the surrounding area is used as the current surrounding density of the traversed node.
[0210] Specifically, the server determines the area of the surrounding region based on the location range of the surrounding area, and determines the current surrounding density of the traversed nodes by the ratio between the total number of nodes falling into the surrounding region and the area of the surrounding region.
[0211] In this example, the current surrounding density of the traversed node is determined based on the surrounding area of the traversed node as the center of the region and the total number of nodes whose positions fall into the surrounding area. This provides a data foundation for subsequent calculations of the current neighborhood energy and the adjusted neighborhood energy.
[0212] In one embodiment, the adjusted neighborhood energy of the traversed node is calculated based on the neighboring nodes of the traversed node in the read node data, the edge weights between the traversed node and the neighboring nodes, and the position to be adjusted. This includes the following steps:
[0213] Based on the neighboring nodes, edge weights between the traversed nodes, and the position to be adjusted in the read node data, the adjusted neighborhood attraction and adjusted surrounding density of the traversed nodes are calculated; based on the adjusted neighborhood attraction and adjusted surrounding density, the adjusted neighborhood energy of the traversed nodes is calculated.
[0214] In one embodiment, the current surrounding density corresponding to the adjusted node position can be used as the adjusted neighborhood attraction of the traversed node. The current surrounding density represents the ratio between the number of nodes in the surrounding region centered on the traversed node and the area of the surrounding region. The sum of the adjusted neighborhood attraction and the adjusted surrounding density is used as the adjusted neighborhood energy of the traversed node.
[0215] The formula for calculating the adjusted neighborhood energy is shown below:
[0216]
[0217] Where, x i Represents node i; x j d(x) represents the node j connected to node i. i ,x j ) 2 This represents the distance between the position to be adjusted corresponding to node i and the position of the read node j; w ij This represents the weight of the edge between nodes i and j; This represents the density near node i.
[0218] Specifically, based on the node data read by the layout sub-thread, namely the neighboring nodes of the traversed node, the edge weights between the traversed node and the position to be adjusted, the server calculates the current neighborhood attraction and the current surrounding density of the traversed node, and determines the current neighborhood energy of the traversed node by summing the current neighborhood attraction and the current surrounding density.
[0219] In this embodiment, the ratio between the number of nodes in the surrounding area of the traversed node as the center of the region and the area of the surrounding region is determined as the adjusted neighborhood repulsion force of the traversed node. When calculating the adjusted neighborhood repulsion force of the traversed node, it is not necessary to calculate the repulsion force between all nodes. It is only necessary to calculate the current surrounding density of the surrounding area of the traversed node, which can reduce the amount of calculation and improve the layout efficiency.
[0220] In some embodiments, based on the neighboring nodes of the traversed nodes in the read node data, the edge weights between the traversed nodes and the position to be adjusted, the adjusted neighborhood attraction of the traversed nodes is calculated, including the following steps:
[0221] 1. Based on the neighboring nodes of the traversed nodes in the read node data, read the node positions of the neighboring nodes from the shared memory.
[0222] Specifically, the server reads the node data of the traversed nodes from the shared memory through the layout sub-thread. Based on the node identifiers of the adjacent nodes in the node data, it reads the node data of the adjacent nodes from the memory location corresponding to the node identifiers of the adjacent nodes in the shared memory. The server then parses the node data of the adjacent nodes to obtain the node positions of the adjacent nodes in the node data of the adjacent nodes.
[0223] 2. Calculate the distance between the position to be adjusted of the traversed node and the position of the adjacent node.
[0224] Specifically, after obtaining the coordinates of the position to be adjusted of the traversed node and the corresponding coordinates of the adjacent node positions, the server calculates the distance between the position to be adjusted of the traversed node and the adjacent node positions according to the distance formula between the two points.
[0225] Third, based on the edge weights between the read node data and adjacent nodes, the corresponding distances are weighted and summed to obtain the adjusted neighborhood attraction of the traversed nodes.
[0226] The edge weights between traversed nodes and their adjacent nodes are stored in the node data. Therefore, after obtaining the node data, the edge weights can be obtained by parsing the node data. According to the formula... The adjusted neighborhood attraction of the traversed nodes is obtained by weighting and summing the edge weights of the nodes and the distances between the nodes and their neighboring nodes after position adjustment.
[0227] Specifically, the server parses and reads the node data, obtains the edge weights between the traversed node and its neighboring nodes, and performs a weighted summation of the edge weights between the node data and its neighboring nodes with the corresponding distances to obtain the adjusted neighborhood attraction of the traversed node.
[0228] In this embodiment, by packaging node positions, neighboring node identifiers, and edge weights into node data, when calculating neighborhood attraction, nodes with strong correlations are placed in close proximity through edge weights, making the relationships and connections between nodes clearer.
[0229] In one embodiment, based on the neighboring nodes of the traversed nodes in the read node data, the edge weights between the traversed nodes and the position to be adjusted, the adjusted surrounding density of the traversed nodes is calculated, including the following steps:
[0230] 1. Based on the adjusted positions of the traversed nodes in the read node data, determine the surrounding area centered on the adjusted positions of the traversed nodes.
[0231] The surrounding area refers to the region centered on the position to be adjusted of the traversed node, and has a defined location range. The shape and size of the surrounding area can be set based on the specific scenario.
[0232] Specifically, after the server reads the node data through the layout sub-thread, it parses the node data to obtain the node position, adjusts the node position to the position to be adjusted, and determines the surrounding area with the node to be adjusted as the center, according to the area range of the preset area.
[0233] 2. Based on the location range of the surrounding area, traverse the total number of nodes in the shared memory whose locations fall within the location range.
[0234] The location range of the surrounding area is set based on the coordinates of the node to be adjusted and the actual requirements. For example, if the coordinates of the node to be adjusted are (x, y), the location range of the surrounding area is set to the region with the horizontal coordinate (xw, x+w) and the vertical coordinate (yw, y+w), where w represents the distance.
[0235] It should be noted that nodes falling within the surrounding area can be adjacent nodes of the traversed nodes or non-adjacent nodes; the determination can be made simply by considering the node's position.
[0236] Specifically, the server iterates through the node positions of each node in the shared memory, determines the target nodes whose positions fall within the location range defined by the surrounding area, and counts the total number of target nodes.
[0237] Third, the ratio of the total number to the surrounding area is used as the adjusted surrounding density of the traversed nodes.
[0238] Specifically, the server determines the area of the surrounding region based on the location range of the surrounding area, and determines the current surrounding density of the traversed nodes by the ratio between the total number of nodes falling into the surrounding region and the area of the surrounding region.
[0239] In this example, the adjusted neighborhood density of the traversed nodes is determined based on the surrounding area of the region center where the traversed nodes are to be adjusted and the total number of nodes whose positions fall into the surrounding area. This provides a data basis for subsequent calculation of the adjusted neighborhood energy.
[0240] In one embodiment, this embodiment provides a graph data processing method, which specifically includes the following steps:
[0241] I. Monitoring map data layout request;
[0242] 2. Upon detecting a graph data layout request sent by the client, establish a connection with the client;
[0243] 3. After establishing a connection, receive the graph data to be laid out sent by the client; the graph data includes multiple nodes and the edge weights between adjacent nodes.
[0244] 4. Create the layout main thread. During the initialization of the layout main thread, the first parameter class, the first graph data class, and multiple calculation unit classes are created through the layout main thread. The first parameter class is used to initialize the adjustment parameters of the node positions and to update the adjustment parameters of the node positions. The first graph data class is used to update the node data of each node recorded in the shared memory. The multiple calculation unit classes are used to create multiple parallel layout sub-threads. The shared memory is used to record the node data of each node, which includes the node position, adjacent nodes, and edge weights between adjacent nodes.
[0245] 5. During the initialization of each layout sub-thread, a second parameter class, a second graph data class, and a calculation class are created through each layout sub-thread. The second parameter class is used to synchronously adjust parameters from the first parameter class of the layout main thread. The second graph data class is used to read the node data of the allocated nodes from shared memory. The calculation class is used to traverse the allocated nodes, read the node data of the traversed nodes from shared memory, and adjust the node position of the traversed nodes according to the read node data.
[0246] 6. The initial node position of each node in the graph data is randomly determined by the layout main thread.
[0247] 7. Based on the initial node position, adjacent nodes, and edge weights between adjacent nodes, determine the node data of each node in the graph data.
[0248] 8. Divide the shared memory into multiple memory locations, and there is a mapping relationship between each memory location and the node identifier of each node in the graph data.
[0249] 9. According to the mapping relationship, store the node data of each node in the graph data into the memory location corresponding to the node identifier.
[0250] 10. Assign different nodes to each layout child thread through the layout main thread.
[0251] 11. Obtain the list of allocated nodes from the main layout thread through each layout sub-thread.
[0252] 12. Traverse the node identifiers in the node list.
[0253] 13. Read the node data of the traversed node from the memory location corresponding to the node identifier in the shared memory.
[0254] 14. Based on the neighboring nodes of the traversed nodes in the read node data, read the node positions of the neighboring nodes from the shared memory.
[0255] 15. Calculate the distance between the position of the traversed node and the positions of its adjacent nodes.
[0256] 16. Based on the edge weights between the read node data and adjacent nodes, perform a weighted summation of the corresponding distances to obtain the neighborhood attraction of the traversed nodes.
[0257] 17. Based on the node positions of the traversed nodes in the read node data, determine the surrounding area centered on the traversed node.
[0258] 18. Based on the location range of the surrounding area, traverse the total number of nodes in the shared memory whose locations fall within the location range.
[0259] 19. The ratio of the total quantity to the surrounding area is used as the current surrounding density of the traversed node.
[0260] 20. Calculate the current neighborhood energy of the traversed nodes based on the current neighborhood gravity and the current surrounding density.
[0261] 21. Read the adjustment parameters used to update the node positions from the layout main thread;
[0262] 22. Based on the node positions and adjustment parameters of the traversed nodes in the read node data, determine the position to be adjusted of the traversed nodes.
[0263] 23. Based on the neighboring nodes, edge weights between the traversed nodes and the positions to be adjusted in the read node data, calculate the adjusted neighborhood attraction and adjusted surrounding density of the traversed nodes.
[0264] 24. Calculate the adjusted neighborhood energy of the traversed nodes based on the adjusted neighborhood gravity and the adjusted surrounding density.
[0265] 25. If the current neighborhood energy is less than or equal to the adjusted neighborhood energy, the node position of the traversed node is not adjusted; if the current neighborhood energy is greater than the adjusted neighborhood energy, the node position of the traversed node is adjusted to the position to be adjusted.
[0266] 26. The layout main thread updates the node data of the nodes traversed in shared memory according to the adjusted node positions.
[0267] 27. After the node data of each node in the shared memory is updated, the main layout thread reads the node position of each node from the shared memory; the node and its corresponding position are fed back to the client so that the client can visualize the nodes in the graph data according to the node position and the graph data, and return to the step of assigning different nodes to each layout sub-thread through the main layout thread to continue execution until the stopping condition is met, and the layout position of each node is obtained; the layout position is used to visualize the graph data.
[0268] In this embodiment, the data structure, layout algorithm, and layout process were redesigned. The required data was stored using shared memory, enabling multi-core parallel layout operations. At the same time, the layout process can be completed on the server, which greatly improves the layout speed, reduces the CPU usage of the user's browser, and enhances the user experience.
[0269] In one embodiment, this embodiment provides a specific application of a graph data processing method, such as... Figure 9The diagram shown illustrates the application flow of a graph data processing method in one embodiment. When the client renders the graph data, it sends a layout request to the server. Upon receiving the request, the server initializes the first parameter class and the first graph data class in the main layout thread, and creates multiple computational unit classes. Multiple parallel layout sub-threads are then created through these computational unit classes. Each layout sub-thread is initialized. After the computational units of all sub-threads are initialized, the layout main thread begins the iteration process. Each layout sub-thread is assigned a set of nodes. Upon receiving the nodes, the sub-thread traverses them sequentially. The sub-thread calculates the current neighborhood attraction and repulsion for each node, and determines the current neighborhood energy based on these forces. After adjusting the node's position to the desired position, the sub-thread calculates the adjusted neighborhood attraction and repulsion for each traversed node, and determines the adjusted neighborhood energy based on these forces. If the current neighborhood energy is less than or equal to the adjusted neighborhood energy, the node's position is not adjusted; if the current neighborhood energy is greater than the adjusted neighborhood energy, the node's position is adjusted to the desired position. Once the layout sub-thread completes the above calculations, it notifies the layout main thread. Once all layout sub-threads have completed their computational tasks, the main layout thread updates the node data of all nodes in shared memory and sends the node data to the client. The client then updates the graph upon receiving the data. Simultaneously, the main layout thread begins the next iteration. The entire layout process is complete once the preset number of iterations has been reached.
[0270] The layout scheme in this embodiment significantly improves the layout performance of network graphs. A diagram illustrating layout time with different thread counts is shown below. Figure 10 As shown in the diagram, the layout time consumption is illustrated when different numbers of threads are enabled. Figure 11 As shown in the test data, this embodiment uses multi-threaded layout calculation. The more threads there are, the shorter the layout time and the better the layout performance.
[0271] A diagram comparing the layout time of this embodiment with that of the traditional layout is shown below. Figure 12 As shown, D3, Tvision, Echarts, G6, and Graspologic are some graph visualization libraries currently on the market. Figure 12 As can be seen above, the layout performance of this embodiment is far superior to that of the current traditional solution, and the difference in performance increases with the number of nodes. For example, for graph data with 40,000 nodes and 100,000 edges, the best solution in the industry takes 121 seconds, while this embodiment only takes 32 seconds, which is 4 times faster than the traditional solution.
[0272] A diagram illustrating the CPU usage of data layout in related technologies is shown below. Figure 13As shown in the diagram, this embodiment illustrates the CPU usage during data layout. Figure 14 As shown, from Figure 13 Figure 14 As can be seen, in terms of CPU usage during layout, the traditional solution uses 100% CPU for a prolonged period of up to 16 seconds, causing the terminal to lag and become unusable. In contrast, this embodiment uses an average of around 40% CPU, which does not affect other terminal operations and results in no lag, providing a superior user experience.
[0273] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0274] Based on the same inventive concept, this embodiment also provides a graph data processing apparatus for implementing the graph data processing method described above. The solution provided by this apparatus is similar to the implementation scheme described in the above method; therefore, the specific limitations in one or more graph data processing apparatus embodiments provided below can be found in the limitations of the graph data processing method described above, and will not be repeated here.
[0275] In one embodiment, such as Figure 15 As shown, a graph data processing apparatus is provided, comprising:
[0276] The acquisition module 100 is used to acquire the graph data to be laid out. The graph data includes multiple nodes and the edge weights between adjacent nodes.
[0277] Multi-threaded creation module 200 is used to create the main layout thread and multiple parallel layout sub-threads;
[0278] The node allocation module 300 is used to initialize shared memory based on graph data through the layout main thread, and to allocate different nodes to each layout sub-thread; the shared memory is used to record the node data of each node, including the node position, adjacent nodes, and edge weights between adjacent nodes;
[0279] The node position update module 400 is used to traverse the allocated nodes through each layout sub-thread, read the node data of the traversed nodes from the shared memory, and adjust the node position of the traversed nodes according to the read node data.
[0280] The shared memory update module 500 is used to update the node data of the nodes traversed in the shared memory according to the adjusted node positions through the layout main thread.
[0281] The iteration loop module 600 is used to return to the step of allocating different nodes to each layout sub-thread through the layout main thread after each node in the shared memory has been traversed, and continue execution until the stopping condition is met, so as to obtain the layout position of each node; the layout position is used to visualize the graph data.
[0282] In one embodiment, the acquisition module 100 is further configured to: monitor graph data layout requests;
[0283] Upon detecting a graph data layout request sent by a client, establish a connection with the client;
[0284] After establishing a connection, it receives the graph data to be laid out from the client.
[0285] In one embodiment, the multi-threaded creation module 200 is further configured to: create a layout main thread, and during the initialization of the layout main thread, create a first parameter class, a first graph data class, and multiple computing unit classes through the layout main thread; the first parameter class is used to initialize the adjustment parameters of the node positions and to update the adjustment parameters of the node positions, the first graph data class is used to update the node data of each node recorded in the shared memory, and the multiple computing unit classes are used to create multiple parallel layout sub-threads;
[0286] During the initialization of each layout sub-thread, a second parameter class, a second graph data class, and a calculation class are created through each layout sub-thread. The second parameter class is used to synchronously adjust parameters from the first parameter class of the layout main thread. The second graph data class is used to read the node data of the allocated nodes from shared memory. The calculation class is used to traverse the allocated nodes, read the node data of the traversed nodes from shared memory, and adjust the node position of the traversed nodes according to the read node data.
[0287] In one embodiment, the node allocation module 300 is further configured to: randomly determine the initial node position of each node in the graph data through the layout main thread;
[0288] Based on the initial node position, adjacent nodes, and edge weights between adjacent nodes, the node data of each node in the graph data is determined;
[0289] The node identifier of each node and the corresponding node data are stored in shared memory.
[0290] In one embodiment, the node allocation module 300 is further configured to:
[0291] The shared memory is divided into multiple memory locations, and there is a mapping relationship between each memory location and the node identifier of each node in the graph data;
[0292] According to the mapping relationship, the node data of each node in the graph data is stored in the memory location corresponding to the node identifier.
[0293] In one embodiment, the node position update module 400 is further configured to: obtain the allocated node list from the layout main thread through each layout sub-thread;
[0294] Iterate through the node identifiers in the node list;
[0295] Read the node data of the traversed node from the memory location corresponding to the node identifier in the shared memory.
[0296] In one embodiment, the node position update module 400 is further configured to: calculate the current neighborhood energy of the traversed node based on the read node data;
[0297] Read the adjustment parameters used to update the node positions from the layout main thread;
[0298] Based on the node positions and adjustment parameters of the traversed nodes in the read node data, determine the position to be adjusted of the traversed nodes.
[0299] Based on the neighboring nodes, edge weights between the traversed nodes and the position to be adjusted in the read node data, calculate the adjusted neighborhood energy of the traversed node.
[0300] Based on the current neighborhood energy and the adjusted neighborhood energy, determine whether to adjust the node position of the traversed nodes.
[0301] In one embodiment, the node position update module 400 is further configured to: calculate the current neighborhood attraction and current surrounding density of the traversed nodes based on the read node data;
[0302] Calculate the current neighborhood energy of the traversed nodes based on the current neighborhood gravity and the current surrounding density.
[0303] In one embodiment, the node position update module 400 is further configured to: read the node position of the adjacent node from the shared memory based on the adjacent nodes of the traversed node in the read node data;
[0304] Calculate the distance between the position of the traversed node and the positions of its neighboring nodes;
[0305] The neighborhood attraction of the traversed nodes is obtained by weighting and summing the corresponding distances based on the edge weights between the nodes and their neighboring nodes in the read node data.
[0306] In one embodiment, the node position update module 400 is further configured to: determine the surrounding area centered on the traversed node based on the node position of the traversed node in the read node data.
[0307] Based on the location range of the surrounding area, iterate through the total number of nodes in the shared memory whose node positions fall within the location range;
[0308] The ratio of the total number to the surrounding area is used as the current surrounding density of the traversed node.
[0309] In one embodiment, the node position update module 400 is further configured to: calculate the adjusted neighborhood attraction and adjusted surrounding density of the traversed node based on the neighboring nodes of the traversed node in the read node data, the edge weights between the traversed node and the position to be adjusted.
[0310] The adjusted neighborhood energy of the traversed nodes is calculated based on the adjusted neighborhood gravity and the adjusted surrounding density.
[0311] In one embodiment, the node position update module 400 is further configured to: if the current neighborhood energy is less than or equal to the adjusted neighborhood energy, then not adjust the node position of the traversed node;
[0312] If the current neighborhood energy is greater than the adjusted neighborhood energy, then the position of the traversed node is adjusted to the position to be adjusted.
[0313] In one embodiment, the iteration loop module 600 is further configured to: read the node position of each node from shared memory via the layout main thread;
[0314] The nodes and their corresponding locations are fed back to the client, enabling the client to visualize the nodes in the graph data based on their locations and the graph data.
[0315] Each module in the aforementioned data processing device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the operations corresponding to each module.
[0316] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 16As shown, this computer device includes a processor, memory, input / output interfaces (I / O), and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores node data. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements a graph data processing method.
[0317] Those skilled in the art in this field can understand. Figure 16 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0318] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above-described method embodiments.
[0319] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps in the above method embodiments.
[0320] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0321] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data shall comply with the relevant laws, regulations and standards of the relevant countries and regions.
[0322] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0323] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0324] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A graph data processing method, characterized in that, The method includes: Obtain graph data to be laid out, the graph data including multiple nodes and edge weights between adjacent nodes; Create a main layout thread and multiple parallel layout sub-threads; The layout main thread initializes shared memory based on the graph data and allocates different nodes to each layout sub-thread; the shared memory is used to record node data of each node, including node position, adjacent nodes, and edge weights between adjacent nodes; Each of the layout sub-threads traverses the allocated nodes, reads the node data of the traversed nodes from the shared memory, and adjusts the node position of the traversed nodes according to the read node data. The layout main thread updates the node data of the traversed nodes in the shared memory according to the adjusted node positions; After each node in the shared memory is traversed, the step of allocating different nodes to each of the layout sub-threads through the layout main thread is returned to continue execution until the stopping condition is met, and the layout position of each node is obtained; the layout position is used to visualize the graph data.
2. The method according to claim 1, characterized in that, The process of obtaining the graph data to be laid out includes: Monitoring chart data layout request; Upon detecting a graph data layout request sent by a client, establish a connection with the client; After establishing a connection, the system receives the graph data to be laid out from the client.
3. The method according to claim 1, characterized in that, The main thread for creating the layout and multiple parallel layout sub-threads include: A layout main thread is created. During the initialization of the layout main thread, a first parameter class, a first graph data class, and multiple calculation unit classes are created through the layout main thread. The first parameter class is used to initialize the adjustment parameters of the node positions and to update the adjustment parameters of the node positions. The first graph data class is used to update the node data of each node recorded in the shared memory. The multiple calculation unit classes are used to create multiple parallel layout sub-threads. During the initialization of each layout sub-thread, a second parameter class, a second graph data class, and a calculation class are created through each layout sub-thread. The second parameter class is used to synchronize the adjustment parameters from the first parameter class of the layout main thread. The second graph data class is used to read the node data of the allocated nodes from the shared memory. The calculation class is used to traverse the allocated nodes, read the node data of the traversed nodes from the shared memory, and adjust the node position of the traversed nodes according to the read node data.
4. The method according to claim 1, characterized in that, The initialization of shared memory based on the graph data by the layout main thread includes: The initial node position of each node in the graph data is randomly determined by the layout main thread; Based on the initial node position, adjacent nodes, and edge weights between adjacent nodes, the node data of each node in the graph data is determined; The node identifier of each node and the corresponding node data are stored in the shared memory.
5. The method according to claim 4, characterized in that, The step of storing the node identifiers and corresponding node data of each node in the shared memory includes: The shared memory is divided into multiple memory locations, and there is a mapping relationship between each memory location and the node identifier of each node in the graph data; According to the mapping relationship, the node data of each node in the graph data is stored in the memory location corresponding to the node identifier.
6. The method according to claim 1, characterized in that, The step of traversing the allocated nodes through each of the layout sub-threads and reading the node data of the traversed nodes from the shared memory includes: Each of the layout sub-threads obtains the allocated node list from the layout main thread; Iterate through the node identifiers in the node list; Read the node data of the traversed node from the memory location corresponding to the node identifier in the shared memory.
7. The method according to claim 1, characterized in that, The step of adjusting the node position of the traversed nodes based on the read node data includes: Based on the read node data, calculate the current neighborhood energy of the traversed nodes; Read the adjustment parameters used to update the node positions from the main thread of the layout; Based on the node positions of the traversed nodes in the read node data and the adjustment parameters, determine the position to be adjusted for the traversed nodes. Based on the neighboring nodes of the traversed node, the edge weights between the traversed nodes, and the position to be adjusted in the read node data, calculate the adjusted neighborhood energy of the traversed node. Based on the current neighborhood energy and the adjusted neighborhood energy, determine whether to adjust the node position of the traversed node.
8. The method according to claim 7, characterized in that, The step of calculating the current neighborhood energy of the traversed nodes based on the read node data includes: Based on the read node data, the current neighborhood attraction and current surrounding density of the traversed nodes are calculated. The current neighborhood energy of the traversed node is calculated based on the current neighborhood gravity and the current surrounding density.
9. The method according to claim 8, characterized in that, The step of calculating the current neighborhood attraction of the traversed nodes based on the read node data includes: Based on the neighboring nodes of the traversed nodes in the read node data, read the node positions of the neighboring nodes from the shared memory; Calculate the distance between the node position of the traversed node and the node positions of the adjacent nodes; The neighborhood attraction of the traversed nodes is obtained by weighting and summing the corresponding distances based on the edge weights between the nodes and their neighboring nodes in the read node data.
10. The method according to claim 8, characterized in that, Based on the read node data, calculate the current surrounding density of the traversed nodes, including: Based on the node positions of the traversed nodes in the read node data, determine the surrounding area with the traversed nodes as the center of the region. Based on the location range of the surrounding area, iterate through the total number of nodes in the shared memory whose node positions fall within the location range; The ratio of the total quantity to the surrounding area is used as the current surrounding density of the traversed node.
11. The method according to claim 7, characterized in that, The step of calculating the adjusted neighborhood energy of the traversed node based on the neighboring nodes of the traversed node in the read node data, the edge weights between the traversed node and the neighboring nodes, and the position to be adjusted, includes: Based on the neighboring nodes of the traversed node, the edge weights between the traversed nodes, and the position to be adjusted in the read node data, the adjusted neighborhood attraction and the adjusted surrounding density of the traversed node are calculated. The adjusted neighborhood energy of the traversed nodes is calculated based on the adjusted neighborhood attraction and the adjusted surrounding density.
12. The method according to claim 7, characterized in that, The step of determining whether to adjust the node position of the traversed nodes based on the current neighborhood energy and the adjusted neighborhood energy includes: If the current neighborhood energy is less than or equal to the adjusted neighborhood energy, then the node position of the traversed node is not adjusted. If the current neighborhood energy is greater than the adjusted neighborhood energy, then the node position of the traversed node is adjusted to the position to be adjusted.
13. The method according to any one of claims 1 to 12, characterized in that, After each node in the shared memory has been traversed, the method further includes: The layout main thread reads the node position of each node from the shared memory; The nodes and their corresponding positions are fed back to the client, so that the client can visualize the nodes in the graph data based on the node positions and the graph data.
14. A graph data processing apparatus, characterized in that, The device includes: The acquisition module is used to acquire graph data to be laid out, the graph data including multiple nodes and edge weights between adjacent nodes among the multiple nodes; A multi-threaded creation module is used to create the main layout thread and multiple parallel layout sub-threads; The node allocation module is used to initialize shared memory based on the graph data through the layout main thread, and to allocate different nodes to each of the layout sub-threads; the shared memory is used to record the node data of each node, and the node data includes the node position, adjacent nodes, and edge weights between adjacent nodes; The node position update module is used to traverse the allocated nodes through each of the layout sub-threads, read the node data of the traversed nodes from the shared memory, and adjust the node position of the traversed nodes according to the read node data. The shared memory update module is used to update the node data of the traversed nodes in the shared memory according to the adjusted node positions through the layout main thread; The iterative loop module is used to return to the step of allocating different nodes to each of the layout sub-threads through the layout main thread after each node in the shared memory has been traversed, and continue execution until the stopping condition is met, so as to obtain the layout position of each node; the layout position is used to visualize the graph data.
15. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 13.
16. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 13.
17. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 13.