A game data processing method and device, a server, and a storage medium
By configuring different hash values for the linked list cache space of MMORPG games and using hash algorithms to store game data in shards, the locking problem during multi-threaded access is solved, and the high-concurrency processing capability is improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- TENCENT TECH (CHENGDU) CO LTD
- Filing Date
- 2020-06-28
- Publication Date
- 2026-04-28
AI Technical Summary
In existing technologies, MMORPG games, due to their large number of players, have high requirements for high concurrency processing capabilities. When multiple threads access the LRU cache, locking and unlocking significantly reduces the concurrency processing capability, which cannot meet the game's needs.
By configuring different hash values for multiple linked list cache spaces in memory, the target linked list cache space for game data is determined using a preset hash algorithm, and the game data is stored in different linked list cache spaces in segments, reducing the probability of different threads accessing the same cache space and enabling multi-threaded concurrent execution.
It improves the high-concurrency processing capabilities of the game server, meets the requirements of MMORPG games for concurrency processing capabilities, and enhances the processing efficiency of the game server.
Smart Images

Figure CN111930740B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of game data processing technology, and in particular to a method, apparatus, server, and storage medium for processing game data. Background Technology
[0002] Online games, also known as network games, generally refer to video games where multiple players interact and enjoy entertainment through a computer internet. Massive Multiplayer Online Role-Playing Games (MMORPGs) are a type of online game categorized by the number of players. In all MMORPGs, players can assume the role of one or more virtual characters and control those characters to perform activities and actions within the game's virtual world.
[0003] In MMORPGs, due to the vast amount of gameplay data, the game server, with its limited memory space, cannot load all the game data into memory. Therefore, game data is typically stored in a remote storage component (a remote game database). The relevant game data is only read into memory when the game server needs to access it. However, accessing the remote storage component by the game server can cause significant latency. Therefore, the game server typically uses a memory cache to store the game data returned by the remote storage component. This way, the game server can directly read the memory cache the next time it accesses the game data, without having to access the remote storage component.
[0004] Related technologies often employ the Least Recently Used (LRU) caching mechanism to store game data returned from remote servers in the game server's memory cache. However, in multi-threaded cache access scenarios, the LRU cache's data structure needs to be adjusted with each access, making concurrent access by different threads impossible. Locking the LRU cache is necessary for each read / write operation, followed by unlocking to ensure thread safety. However, for MMORPGs with a large player base and high concurrency requirements, locking and unlocking the LRU cache significantly reduces concurrency, failing to meet the demands of MMORPGs. Summary of the Invention
[0005] To address the problems of existing technologies, embodiments of the present invention provide a method, apparatus, server, and storage medium for processing game data. The technical solution is as follows:
[0006] On the one hand, a method for processing game data is provided, the method comprising:
[0007] Determine multiple linked list cache spaces in memory, the multiple linked list cache spaces being used to store game data in the form of linked lists;
[0008] Each of the plurality of linked list cache spaces is configured with a different first hash value, wherein the first hash value is the output of a preset hash algorithm;
[0009] When at least one piece of game data is obtained from the game database, the second hash value of each piece of game data in the at least one piece of game data is determined using the preset hash algorithm;
[0010] Based on the matching between the second hash value and the first hash value, determine the first target linked list cache space corresponding to each game data;
[0011] Write the at least one game data into the corresponding first target linked list cache space.
[0012] On the other hand, a game data processing apparatus is provided, the apparatus comprising:
[0013] The first determining module is used to determine multiple linked list cache spaces in memory, wherein the multiple linked list cache spaces are used to store game data in the form of linked lists;
[0014] The configuration module is used to configure a different first hash value for each of the multiple linked list cache spaces, wherein the first hash value is the output of a preset hash algorithm;
[0015] The second determining module is used to determine the second hash value of each game data in the at least one game data when the game database returns at least one game data;
[0016] The third determining module is used to determine the first target linked list cache space corresponding to each game data based on the matching situation between the second hash value and the first hash value;
[0017] The writing module is used to write the at least one game data into the corresponding first target linked list cache space.
[0018] Optionally, the second determining module includes:
[0019] The fourth determining module is used to determine the data identifier of each piece of game data in the at least one piece of game data;
[0020] The calculation module is used to take the remainder of the data identifier of each game data with respect to the total number of linked list cache spaces to obtain the remainder corresponding to each game data.
[0021] The fifth determining module is used to determine the remainder as the second hash value of the corresponding game data, thereby obtaining the second hash value of each game data in the at least one game data.
[0022] Optionally, the device further includes:
[0023] The sixth determining module is used to determine the third hash value of the target game data using the preset hash algorithm when an access request for the target game data is received.
[0024] The seventh determining module is used to determine the second target linked list cache space for storing the target game data based on the matching situation between the third hash value and the first hash value;
[0025] The reading module is used to read the target game data from the second target linked list cache space.
[0026] Optionally, the reading module includes:
[0027] The eighth determining module is used to determine the target memory address pointer of the target game data in the second target linked list cache space;
[0028] The first acquisition module is used to acquire the target memory address corresponding to the target memory address pointer based on the address fetch operation;
[0029] The address translation module is used to convert the target memory address into a target physical address and read the target game data according to the target physical address.
[0030] Optionally, the device further includes:
[0031] The first update module is used to perform a first update operation on the reference count of the target game data in the second target linked list cache space, the first update operation including incrementing the reference count by 1;
[0032] The second update module is used to perform a second update operation on the reference count of the target game data in the second target linked list cache space when it is determined that the use of the target game data will end. The second update operation includes decrementing the reference count by 1.
[0033] The first deletion module is used to delete the target game data from the second target linked list cache space when the reference count of the target game data is zero.
[0034] Optionally, each of the multiple linked list cache spaces includes a hot zone space at the head and a cold zone space at the tail. The hot zone space is used to store game data whose access frequency exceeds a preset frequency threshold, and the cold zone space is used to store game data whose access frequency does not exceed the preset frequency threshold.
[0035] Accordingly, the device also includes:
[0036] The access frequency update module is used to increment the access frequency of the target game data in the second target linked list cache space by 1 to obtain the updated access frequency;
[0037] The judgment module is used to determine whether the update access frequency exceeds the preset frequency threshold;
[0038] The storage module is used to store the target game data in the hot zone space of the second target linked list cache space when the result of the judgment module is yes.
[0039] Optionally, the device further includes:
[0040] The ninth determining module is used to determine the first access frequency of each game data stored in the cold zone space in each of the multiple linked list cache spaces;
[0041] The tenth determining module is used to determine at least one game data to be eliminated where the first access frequency is less than or equal to the preset elimination frequency;
[0042] The second deletion module is used to delete the at least one game data to be eliminated from the linked list cache space.
[0043] On the other hand, a game server is provided, including a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded and executed by the processor to implement the above-mentioned game data processing method.
[0044] On the other hand, a computer-readable storage medium is provided, wherein at least one instruction or at least one program is stored therein, the at least one instruction or the at least one program being loaded and executed by a processor to implement the game data processing method described above.
[0045] This invention, through its embodiments, determines multiple linked list cache spaces in memory, configures different first hash values for each of these linked list cache spaces, and, upon obtaining at least one piece of game data returned by the game database, uses a preset hash algorithm that outputs the first hash value to determine a second hash value for each piece of game data. Then, based on the matching between the second hash value and the first hash value, it determines the first target linked list cache space corresponding to each piece of game data, and writes the at least one piece of game data into the corresponding first target linked list cache space. This fragmented storage of game data in different linked list cache spaces reduces the probability of different threads accessing the same linked list cache space. Different threads reading different linked list cache spaces do not require locking, enabling multi-threaded concurrent execution and improving the high-concurrency processing capability of the game server, thereby meeting the high-concurrency processing requirements of MMORPG games. Attached Figure Description
[0046] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0047] Figure 1 This is a schematic diagram of an implementation environment provided by an embodiment of the present invention;
[0048] Figure 2 This is a flowchart illustrating a game data processing method provided in an embodiment of the present invention;
[0049] Figure 3 This is an optional schematic diagram provided by an embodiment of the present invention, in which multiple game data are written into multiple LRU caches respectively;
[0050] Figure 4 This is a flowchart illustrating another method for processing game data provided in an embodiment of the present invention;
[0051] Figure 5 This is a schematic diagram of the process of reading target game data from the second target linked list cache space provided in an embodiment of the present invention;
[0052] Figure 6 This is a flowchart illustrating another method for processing game data provided in an embodiment of the present invention;
[0053] Figure 7 This is an optional schematic diagram of one of the multiple LRU caches provided in this embodiment of the invention, which uses reference counting to eliminate game data;
[0054] Figure 8 This is a flowchart illustrating another method for processing game data provided in an embodiment of the present invention;
[0055] Figure 9 This is a schematic diagram of the storage structure of one LRU cache among multiple LRU caches provided in an embodiment of the present invention;
[0056] Figure 10 This is a flowchart illustrating another method for processing game data provided in an embodiment of the present invention;
[0057] Figure 11 This is a schematic diagram of the structure of a game data processing device provided in an embodiment of the present invention;
[0058] Figure 12 This is a hardware structure block diagram of a server provided in an embodiment of the present invention. Detailed Implementation
[0059] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0060] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or server that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.
[0061] Please see Figure 1 The diagram shown is a schematic diagram of an implementation environment provided by an embodiment of the present invention. The implementation environment may include a terminal 110, a game server 120, and a game database 130.
[0062] The terminal 110 can be a smartphone, tablet, laptop, desktop computer, smart speaker, smartwatch, etc., but is not limited to these. A game application runs on the terminal 110. This game application can provide a virtual environment for users to immerse themselves in and control virtual characters within that virtual environment. Typically, this game application is a massively multiplayer online role-playing game (MMORPG). The game application has an account login function, allowing users to register and log in to their user accounts within the game application. Optionally, this user account can include one or more player characters.
[0063] Game server 120 is a server that provides background services for the game application running on terminal 110. Game server 120 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. Terminal 110 and game server 120 can be directly or indirectly connected via wired or wireless communication, which is not limited herein.
[0064] The game database 130 serves as a remote storage component of the game server 120, used to store all game data related to the game applications. The game server 120 can retrieve requested game data from the game database 130 based on access requests from various game applications. The game database 130 and the game server 120 can be directly or indirectly connected via wired or wireless communication, which is not limited herein.
[0065] This invention provides a method for processing game data based on cloud storage technology. Cloud storage is a new concept that is extended and developed from the concept of cloud computing. A distributed cloud storage system (hereinafter referred to as a storage system) refers to a storage system that uses cluster applications, grid technology and distributed storage file systems to bring together a large number of storage devices of various types in the network (storage devices are also called storage nodes) to work together through application software or application interfaces to jointly provide data storage and business access functions to the outside world.
[0066] Currently, the storage method of a storage system is as follows: Logical volumes are created. During the creation of a logical volume, physical storage space is allocated to each logical volume. This physical storage space may consist of disks from one or more storage devices. Clients store data on a logical volume, which means storing the data on the file system. The file system divides the data into many parts, each part being an object. Each object contains not only the data but also additional information such as a data identifier (ID). The file system writes each object to the physical storage space of the logical volume and records the storage location information of each object. Therefore, when a client requests access to data, the file system can allow the client to access the data based on the storage location information of each object. The process of allocating physical storage space to a logical volume is as follows: Based on the capacity estimate of the objects stored in the logical volume (this estimate often has a large margin relative to the actual capacity of the objects to be stored) and the grouping of Redundant Array of Independent Disks (RAID), the physical storage space is pre-divided into strips. A logical volume can be understood as a strip, thus allocating physical storage space to the logical volume.
[0067] Please see Figure 2 The diagram shown is a flowchart illustrating a game data processing method provided by an embodiment of the present invention. This method can be applied to... Figure 1 The game server in the example. It should be noted that this specification provides the operational steps of the methods described in the embodiments or flowcharts, but based on conventional or non-inventive labor, more or fewer operational steps may be included. The order of steps listed in the embodiments is merely one possible execution order among many, and does not represent the only execution order. In actual system or product execution, the methods shown in the embodiments or drawings can be executed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment). Specifically, as shown... Figure 2 As shown, the method may include:
[0068] S201, determine multiple linked list cache spaces in memory, the multiple linked list cache spaces are used to store game data in the form of linked lists.
[0069] Specifically, the game server can determine the number N (N>1) of multiple linked list cache spaces allocated from memory based on the memory usage of the linked list cache space and the total memory size of the machine. A larger N is more advantageous for this solution; that is, the number of linked list cache spaces should be increased as much as possible. Each linked list cache space is used to store game data in the form of a linked list. A linked list is a storage structure that connects a group of scattered memory blocks through memory address pointers. The memory blocks are called nodes in the linked list. Each node can store game data and memory address pointers to adjacent nodes, which can be the previous node and / or the next node of the current node.
[0070] In one possible implementation, the linked list cache space can be an LRU cache space, that is, the game server can divide the memory into N LRU cache spaces. The cache structure of each LRU cache space can be a key-value mapping structure, where the key is the primary key value and the value is the game data corresponding to the primary key value. All the values in a linked list cache space form a linked list, which can be a singly linked list, a doubly linked list, a circular linked list, or a doubly circular linked list, etc.
[0071] S203, configure a different first hash value for each of the multiple linked list cache spaces, wherein the first hash value is the output of a preset hash algorithm.
[0072] The preset hash algorithm is a function that compresses a message of arbitrary length into a message digest of a fixed length. In other words, the output of the preset hash algorithm is a fixed length and is a finite set of values, while the first hash value is a value taken from this finite set.
[0073] In one possible implementation, the number of linked list cache spaces can be the same as the length of the finite set output by the preset hash algorithm, that is, the linked list cache space corresponds one-to-one with the values in the finite set corresponding to the preset hash algorithm. Assuming there are 5 LRU caches and the finite set output by the preset hash algorithm is {1,2,3,4,5}, then the values in this finite set can be assigned to the 6 LRU caches as the first hash value of each LRU cache, resulting in {LRU1,1}, {LRU2,2}, {LRU3,3}, {LRU4,4}, and {LRU5,5}.
[0074] In another possible implementation, considering the limited total machine memory, the number of multiple linked list cache spaces can be less than the length of the finite set output by the preset hash algorithm. In this case, each linked list cache space can correspond to multiple first hash values, but each first hash value can only correspond to one linked list cache space. The first hash values of each linked list cache space are different, and the total number of first hash values corresponding to all linked list cache spaces is consistent with the length of the finite set output by the preset hash algorithm. This ensures that subsequent game data can be uniquely stored in a certain linked list cache space. In a specific implementation, a cyclical processing method can be used to allocate the values in the finite set output by the preset hash algorithm to multiple linked list cache spaces as their first hash values. For example, assuming there are 5 LRU caches and the length of the finite set output by the preset hash algorithm is 10, then 1 to 5 in the finite set can be assigned to the 5 LRU caches as the first hash value, and 6 to 10 in the finite set can be assigned to the 5 LRU caches as the first hash value, that is, we get {LRU1,[1,6]}, {LRU2,[2,7]}, {LRU3,[3,8]}, {LRU4,[4,9]}, {LRU5,[5,10]}.
[0075] S205, when at least one game data returned by the game database is obtained, the second hash value of each game data in the at least one game data is determined by the preset hash algorithm.
[0076] Specifically, the game server can request relevant game data from a remote game database. The game database responds to this request by returning game data to the game server. The game server then obtains at least one piece of game data returned by the game database and uses a preset hash algorithm to determine a second hash value for each piece of game data. This game data can be gameplay data from an MMORPG, such as player combat power data.
[0077] In practical applications, each piece of game data corresponds to a unique data identifier. This data identifier can uniquely identify a piece of game data. The data identifier of game data can be assigned by the game server. The data identifier generation algorithm can be, but is not limited to, the snowflake algorithm and the leaf algorithm.
[0078] Based on this, in one possible implementation, the game server determining the second hash value of each piece of game data in at least one game data using a preset hash algorithm may include the following steps:
[0079] (1) Determine the data identifier of each game data in the at least one game data.
[0080] (2) Take the remainder of the data identifier of each game data with respect to the total number of linked list cache spaces to obtain the remainder corresponding to each game data.
[0081] (3) The remainder is determined as the second hash value of the corresponding game data, and the second hash value of each game data in the at least one game data is obtained.
[0082] For example, if game data A has a data identifier of 36, and the total cache space of multiple linked lists is 7, then 36 divided by 7 leaves a remainder of 1. This remainder of 1 is the second hash value of game data A. Similarly, if game data B has a data identifier of 25, then 25 divided by 7 leaves a remainder of 4. This remainder of 4 is the second hash value of game data B. And so on, the second hash value of each game data in at least one game can be obtained.
[0083] S207, Based on the matching between the second hash value and the first hash value, determine the first target linked list cache space corresponding to each game data.
[0084] Since the second hash value and the aforementioned first hash value are both outputs of the same preset hash algorithm, the first target linked list cache space corresponding to each game data can be determined based on the matching situation between the second hash value and the first hash value. In other words, the linked list cache space corresponding to the first hash value that is the same as the second hash value is used as the first target linked list cache space for the game data corresponding to the second hash value.
[0085] For example, if the second hash value of game data A is 1 and the second hash value of game data B is 4, then the LRU cache with the first hash value of 1 can be used as the first target linked list cache space for game data A; and the LRU cache with the first hash value of 4 can be used as the first target linked list cache space for game data B.
[0086] S209, write the at least one game data into the corresponding first target linked list cache space.
[0087] As in the examples above, please refer to Figure 3 As shown, game data A is written to the LRU cache with a first hash value of 1, and game data B is written to the LRU cache with a first hash value of 4. This allows at least one piece of game data to be stored in different LRU caches, reducing the probability of different threads accessing the same linked list cache space simultaneously. Since different threads can access different linked list cache spaces simultaneously without locking, the granularity of locking is reduced, enabling concurrent access by multiple threads. This improves the high-concurrency processing capability of the game server and thus meets the requirements of MMORPG games for concurrent processing capabilities.
[0088] Taking an LRU cache with a key-value mapping structure as an example, when writing game data into the corresponding LRU cache, the game data can be identified as the primary key, the game data can be used as the value corresponding to the primary key, and the value can be added to an empty node in the LRU cache.
[0089] Please see Figure 4 A flowchart illustrating another method for processing game data is provided, which may further include:
[0090] S401, upon receiving an access request for target game data, the third hash value of the target game data is determined using the preset hash algorithm.
[0091] The target game data is the game data requested by the client. The aforementioned at least one type of game data includes the target game data, which means that the target game data is stored in multiple linked list cache spaces.
[0092] In one possible implementation, the client can send an access request to the game server, which may carry a data identifier of the target game data. When the game server receives the access request, it can extract the data identifier of the target game data, take the remainder of the data identifier of the target game data modulo the total number of linked list cache spaces, obtain the remainder corresponding to the target game data, and use the remainder as the third hash value of the target game data.
[0093] S403, based on the matching of the third hash value and the first hash value, determine the second target linked list cache space for storing the target game data.
[0094] That is, find the linked list cache space corresponding to the first hash value that is the same as the third hash value. This linked list cache space is the second target linked list cache space for storing the target game data.
[0095] S405, Read the target game data from the second target linked list cache space.
[0096] For example, in a game server, two threads are running concurrently, namely thread X and thread Y. Thread X executes access requests for game data A, and thread Y executes access requests for game data B. For thread X, game data A has a data identifier of 36, and the LRU cache size is 7. The remainder of 36 divided by 7 is 1, which is the third hash value corresponding to game data A. Therefore, game data A is stored in the LRU cache with a first hash value of 1. For thread Y, game data B has a data identifier of 25, and the LRU cache size is 7. The remainder of 25 divided by 7 is 4, which is the third hash value corresponding to game data B. Therefore, game data B is stored in the LRU cache with a first hash value of 4. Thread X reads game data A from the LRU cache with a first hash value of 1, and thread Y reads game data B from the LRU cache with a first hash value of 4. For data in different LRU caches, multiple threads accessing different LRU caches simultaneously do not require locking, enabling concurrent execution of threads X and Y, improving the game server's concurrent processing capabilities and request processing efficiency.
[0097] In practical applications, when a game server reads cached data from a linked list cache space, it needs to copy the data from the linked list cache space to the business module. However, due to the complexity of game data (such as gameplay data), some gameplay data occupies a large amount of memory, and copying the cached data incurs significant system overhead. In high-concurrency scenarios, the game server's Central Processing Unit (CPU) will spend a considerable amount of time copying cached data, directly impacting the processing speed of other gameplay logic. Therefore, in one possible implementation, when the game server reads target game data from the second target linked list cache space, it may include... Figure 5 The following steps are shown:
[0098] S501, determine the target memory address pointer of the target game data in the second target linked list cache space.
[0099] Specifically, each node in the linked list cache space stores game data and memory address pointers to adjacent nodes. If the adjacent node is the next node, the game server can first determine the node containing the target game data in the second target linked list cache space, and then determine the previous node of that node. The memory address pointer in that previous node is the target memory address pointer of the target game data. If the adjacent node is the previous node, the game server can first determine the node containing the target game data in the second target linked list cache space, and then determine the next node of that node. The memory address pointer in that next node is the target memory address pointer of the target game data. If the adjacent node includes both the next node and the previous node, i.e., the linked list is a doubly linked list, the game server can first determine the node containing the target game data in the second target linked list cache space, and then determine the target memory address pointer of the target game data based on the memory address pointers in the previous or next node of that node.
[0100] S503, obtain the target memory address corresponding to the target memory address pointer based on the address fetch operation.
[0101] The address-of operation can be performed using the address-of operator "&", which is supported by both C and C++ languages. When the CPU of the game server reads game data from the linked list cache space, it can obtain the target memory address corresponding to the target memory address pointer by using the address-of operator "&".
[0102] S505, convert the target memory address into a target physical address, and read the target game data according to the target physical address.
[0103] Specifically, after the CPU of the game server obtains the target memory address, it can convert the target memory address into the corresponding physical address through the operating system's Memory Management Unit (MMU), and then read the memory stick according to the corresponding physical address to obtain the target game data.
[0104] In this embodiment of the invention, by exposing the memory address pointer of the game data in the linked list cache space to the CPU of the cache accessor, i.e. the game server, through the above steps S501 to S505, the copying of complex data is simplified to simple pointer access, thereby realizing zero copying when reading cached data, avoiding system consumption caused by copying cached data, and improving the processing speed of various gameplay logics in high-concurrency scenarios of MMORPG games.
[0105] Considering that after reading game data based on memory address pointers, if the game data is deleted from the linked list cache space during the CPU's use of the game data, the corresponding memory address pointer will become invalid, and accessing an invalid memory address pointer will cause the game server to crash.
[0106] To prevent game server processes from crashing due to the deletion of game data in the linked list cache space during its use, in one possible implementation, each node in the linked list cache space also stores a reference count of the corresponding game data, which represents the number of processes currently using the corresponding game data.
[0107] like Figure 6 The flowchart illustrates another method for processing game data. After the game server reads the target game data based on the target physical address, the method may further include:
[0108] S601, perform a first update operation on the reference count of the target game data in the second target linked list cache space, the first update operation including incrementing the reference count by 1.
[0109] Specifically, when the game server's CPU reads the target game data based on the target memory address pointer, the game server can increment the reference count of the node containing the target game data in the second target linked list cache space by 1, thereby performing the first update operation on the reference count.
[0110] S603, when it is determined that the use of the target game data is to be terminated, a second update operation is performed on the reference count of the target game data in the second target linked list cache space, the second update operation including decrementing the reference count by 1.
[0111] Specifically, since only the user of the game data, i.e. the relevant process, knows when to release the game data it accesses, when the game server process determines to end its use of the target game data, the CPU can issue a notification to reduce the reference count of the corresponding game data. After receiving the notification, the game server can determine to end its use of the target game data, and then decrement the reference count of the node where the target game data is located in the second target linked list cache space by 1, thereby performing a second update operation on the reference count.
[0112] Taking player combat power data as an example, the game server's combat process obtains the memory address pointer of the player's combat power data from the corresponding linked list cache space. After reading the corresponding player's combat power data based on the memory address pointer (at this time, the reference count of the player's combat power data in the corresponding linked list cache space is incremented by 1), the combat process can execute logic such as combat power matching and damage calculation. When the combat process is finished, it can actively notify the corresponding linked list cache space to decrement the reference count of the player's combat power data by 1.
[0113] S605, when the reference count of the target game data is zero, the target game data is deleted from the second target linked list cache space.
[0114] Specifically, after each second update operation, the game server can check whether the reference count of the target game data is zero. When the reference count of the target game data is zero, it means that the target game data is not currently being used by any user or process, that is, the target game data is not currently in use. At this time, deleting the target game data from the linked list cache space will not lead to access to the invalid memory address pointer, and thus will not cause the game server process to crash.
[0115] For example, a linked list cache is an LRU cache with a key-value mapping structure, such as... Figure 7 The diagram shows the structure of one of several LRU caches. Each node stores a value (i.e., game data), a reference count, and a memory address pointer. Each node corresponds to a primary key value, which can be a data identifier for the game data stored in that node. The memory address pointer of each node includes a pointer to the subsequent memory address of the next node and a pointer to the predecessor memory address of the previous node. Figure 7 The linked list shown is a doubly linked list structure. Each time the game server's CPU reads game data based on a memory address pointer, the reference count for that game data is incremented by 1. When the CPU finishes using the game data, the reference count is decremented by 1. When the reference count of a game data item reaches 0, such as... Figure 7 If value3 is found in the cache, then the game data value3 is removed from the LRU cache and evicted.
[0116] In practical applications, the cache flushing problem often occurs due to occasional batch access to game data. Batch game data will flush the original game data in the linked list cache space, resulting in a significant decrease in the original cache hit rate. Since the game data accessed in occasional batches is used less frequently, the cost-effectiveness of storing it in the linked list cache space is extremely low. However, the original cached game data may be frequently accessed data, and the decrease in cache hit rate will seriously reduce the speed at which the business reads game data.
[0117] To avoid cache flushing issues caused by occasional batch accesses to game data, in one possible implementation, each node in the linked list cache space also stores the access frequency of the corresponding game data. This access frequency represents the total number of times the corresponding game data has been accessed; that is, whenever the game data is accessed, its corresponding access frequency increases by 1, and the access frequency only increases, never decreases. Each of the multiple linked list cache spaces includes a hot zone space at the head of the linked list and a cold zone space at the tail of the linked list. The hot zone space is used to store game data whose access frequency exceeds a preset frequency threshold, and the cold zone space is used to store game data whose access frequency does not exceed the preset frequency threshold. The preset frequency threshold can be set according to actual conditions.
[0118] Based on this, such as Figure 8 A flowchart illustrating another method for processing game data is provided. After the game server reads the target game data from the second target linked list cache space, the method may further include:
[0119] S801, increment the access frequency of the target game data in the second target linked list cache space by 1 to obtain the update access frequency.
[0120] S803, determine whether the update access frequency exceeds the preset frequency threshold.
[0121] Specifically, if the frequency of updates to the target game data exceeds the preset frequency threshold, it indicates that the target game data is not accessed sporadically, and step S805 can be executed; conversely, if the frequency of updates to the target game data does not exceed the preset frequency threshold, it indicates that the target game data is accessed sporadically, and the target game data can be stored in the cold space of the second target linked list cache space.
[0122] S805, the target game data is stored in the hot zone space of the second target linked list cache space.
[0123] Specifically, when storing the target game data in the hot zone space of the second target linked list cache space, the specific location node of the target game data in the hot zone space can be determined according to the descending order of the access frequency of the game data in the hot zone space.
[0124] Taking the linked list cache space as an LRU cache as an example, such as Figure 9The diagram illustrates the structure of one LRU cache within a larger LRU cache hierarchy. Each node stores a value (game data), access frequency, and a memory address pointer. Each node corresponds to a primary key, which can be the data identifier of the game data stored in that node. The area to the left of the dashed line represents the head of the LRU cache, belonging to the hot zone, while the area to the right represents the tail, belonging to the cooldown zone. The dashed lines represent preset frequency thresholds (e.g., 10, 5, etc.). Game data is stored in the hot zone of the LRU cache in descending order of access frequency. Similarly, game data is stored in the cold zone in descending order of access frequency, with less frequently accessed game data residing there. Because the LRU cache will evict the least recently used data when its cache space reaches a preset limit, meaning the LRU cache generally evicts data starting from the tail, and since frequently accessed game data is stored at the head of the LRU cache, occasional batch accesses will not flush out the original frequently accessed game data in the LRU cache. This ensures the cache hit rate of the original high-frequency game data in the LRU cache, thereby ensuring the speed at which the business reads game data.
[0125] In practical applications, LRU caches typically only evict one piece of data at a time during updates, leading to frequent updates to the cache structure. To avoid frequent updates to the linked list cache space structure, another possible implementation is as follows: Figure 10 A flowchart illustrating another method for processing game data is provided, which may further include:
[0126] S1001, for each of the multiple linked list cache spaces, determine the first access frequency of each game data stored in the cold zone space in the linked list cache space.
[0127] S1003, determine at least one game data to be eliminated whose first access frequency is less than or equal to the preset elimination frequency.
[0128] The preset elimination frequency is less than the preset access frequency. This preset elimination frequency can be set according to actual needs, for example, the preset elimination frequency can be set to 1, 3, etc. When the access frequency of game data in the cold zone is less than or equal to the preset elimination frequency, it indicates that the corresponding game data has a very low access frequency and can be identified as game data to be eliminated.
[0129] S1005, delete the at least one game data to be eliminated from the linked list cache space.
[0130] In specific implementation, each linked list cache space can execute the above steps S1001 to S1005 when its available cache space reaches the preset cache space threshold. Thus, when there are multiple game data to be eliminated in the cold space, the multiple game data to be eliminated can be deleted at once, thereby avoiding frequent updates to the cache structure of the linked list cache space.
[0131] Corresponding to the game data processing methods provided in the above embodiments, this embodiment of the invention also provides a game data processing device. Since the game data processing device provided in this embodiment of the invention corresponds to the game data processing methods provided in the above embodiments, the implementation methods of the aforementioned game data processing methods are also applicable to the game data processing device provided in this embodiment, and will not be described in detail in this embodiment.
[0132] Please see Figure 11 The diagram shows a structural schematic of a game data processing device provided in an embodiment of the present invention. This device has the function of implementing the game data processing method described in the above-described method embodiment. This function can be implemented by hardware or by hardware executing corresponding software. Figure 11 As shown, the device may include:
[0133] The first determining module 1110 is used to determine multiple linked list cache spaces in memory, the multiple linked list cache spaces being used to store game data in the form of linked lists;
[0134] Configuration module 1120 is used to configure a different first hash value for each of the plurality of linked list cache spaces, wherein the first hash value is the output of a preset hash algorithm;
[0135] The second determining module 1130 is used to determine the second hash value of each game data in the at least one game data when the game database returns at least one game data;
[0136] The third determining module 1140 is used to determine the first target linked list cache space corresponding to each game data based on the matching situation between the second hash value and the first hash value;
[0137] The writing module 1150 is used to write the at least one game data into the corresponding first target linked list cache space.
[0138] In one possible implementation, the second determining module 1130 may include:
[0139] The fourth determining module is used to determine the data identifier of each piece of game data in the at least one piece of game data;
[0140] The calculation module is used to take the remainder of the data identifier of each game data with respect to the total number of linked list cache spaces to obtain the remainder corresponding to each game data.
[0141] The fifth determining module is used to determine the remainder as the second hash value of the corresponding game data, thereby obtaining the second hash value of each game data in the at least one game data.
[0142] In one possible implementation, the device may further include:
[0143] The sixth determining module is used to determine the third hash value of the target game data using the preset hash algorithm when an access request for the target game data is received.
[0144] The seventh determining module is used to determine the second target linked list cache space for storing the target game data based on the matching situation between the third hash value and the first hash value;
[0145] The reading module is used to read the target game data from the second target linked list cache space.
[0146] In one possible implementation, the reading module may include:
[0147] The eighth determining module is used to determine the target memory address pointer of the target game data in the second target linked list cache space;
[0148] The first acquisition module is used to acquire the target memory address corresponding to the target memory address pointer based on the address fetch operation;
[0149] The address translation module is used to convert the target memory address into a target physical address and read the target game data according to the target physical address.
[0150] In one possible implementation, the device may further include:
[0151] The first update module is used to perform a first update operation on the reference count of the target game data in the second target linked list cache space, the first update operation including incrementing the reference count by 1;
[0152] The second update module is used to perform a second update operation on the reference count of the target game data in the second target linked list cache space when it is determined that the use of the target game data will end. The second update operation includes decrementing the reference count by 1.
[0153] The first deletion module is used to delete the target game data from the second target linked list cache space when the reference count of the target game data is zero.
[0154] In one possible implementation, each of the plurality of linked list cache spaces includes a hot zone space at the head and a cold zone space at the tail. The hot zone space is used to store game data whose access frequency exceeds a preset frequency threshold, and the cold zone space is used to store game data whose access frequency does not exceed the preset frequency threshold.
[0155] Accordingly, the device may also include:
[0156] The access frequency update module is used to increment the access frequency of the target game data in the second target linked list cache space by 1 to obtain the updated access frequency;
[0157] The judgment module is used to determine whether the update access frequency exceeds the preset frequency threshold;
[0158] The storage module is used to store the target game data in the hot zone space of the second target linked list cache space when the result of the judgment module is yes.
[0159] In one possible implementation, the device may further include:
[0160] The ninth determining module is used to determine the first access frequency of each game data stored in the cold zone space in each of the multiple linked list cache spaces;
[0161] The tenth determining module is used to determine at least one game data to be eliminated where the first access frequency is less than or equal to the preset elimination frequency;
[0162] The second deletion module is used to delete the at least one game data to be eliminated from the linked list cache space.
[0163] It should be noted that the apparatus provided in the above embodiments is only illustrated by the division of the above functional modules when implementing its functions. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus and method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.
[0164] The game data processing device of this invention determines multiple linked list cache spaces in memory, configures different first hash values for each of these linked list cache spaces, and when at least one piece of game data is obtained from the game database, uses a preset hash algorithm that outputs the first hash value to determine the second hash value of each piece of game data. Then, based on the matching of the second hash value and the first hash value, it determines the first target linked list cache space corresponding to each piece of game data, and writes the at least one piece of game data into the corresponding first target linked list cache space. This fragmented storage of game data in different linked list cache spaces reduces the probability of different threads accessing the same linked list cache space. Different threads achieve concurrent execution by accessing different linked list cache spaces, improving the high-concurrency processing capability of the game server and thus meeting the requirements of MMORPG games for concurrent processing capabilities.
[0165] Furthermore, the game data processing device in this embodiment of the invention simplifies the copying of complex data into simple pointer access by exposing the memory address pointer of the game data in the linked list cache space to the CPU of the game server, which is the cache accessor. This achieves zero copying when reading cached data, avoids system overhead caused by copying cached data, and improves the processing speed of various gameplay logics in high-concurrency scenarios of MMORPG games. It also avoids game server crashes caused by the deletion of game data in the linked list cache space during its use. At the same time, it avoids cache flushing problems caused by occasional batch access to game data, ensuring the speed of business reading of game data.
[0166] This invention provides a game server, which includes a processor and a memory. The memory stores at least one instruction or at least one program, which is loaded and executed by the processor to implement the game data processing method provided in the above method embodiments.
[0167] The memory can be used to store software programs and modules. The processor executes various functional applications and processes game data by running the software programs and modules stored in the memory. The memory can mainly include a program storage area and a data storage area. The program storage area can store the operating system, applications required for functions, etc.; the data storage area can store data created according to the use of the device, etc. In addition, the memory can include high-speed random access memory, and can also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory can also include a memory controller to provide the processor with access to the memory.
[0168] The methods and embodiments provided in this invention can be executed on a computer terminal, server, or similar computing device. Taking running on a server as an example... Figure 12 This is a hardware structure block diagram of a server running a method provided in an embodiment of the present invention, such as... Figure 12 As shown, the server 1200 can vary significantly due to different configurations or performance. It may include one or more central processing units (CPUs) 1210 (CPUs 1210 may include, but are not limited to, microprocessors (MCUs) or programmable logic devices (FPGAs), a memory 1230 for storing data, and one or more storage media 1220 (e.g., one or more mass storage devices) for storing application programs 1223 or data 1222. The memory 1230 and storage media 1220 may be temporary or persistent storage. The program stored in the storage media 1220 may include one or more modules, each module including a series of instruction operations on the server. Furthermore, the CPU 1210 may be configured to communicate with the storage media 1220 and execute the series of instruction operations stored in the storage media 1220 on the server 1200. Server 1200 may also include one or more power supplies 1260, one or more wired or wireless network interfaces 1250, one or more input / output interfaces 1240, and / or one or more operating systems 1221, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.
[0169] The input / output interface 1240 can be used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of server 1200. In one example, the input / output interface 1240 includes a network interface controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the input / output interface 1240 may be a radio frequency (RF) module for wireless communication with the Internet.
[0170] Those skilled in the art will understand that Figure 12 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, server 1200 may also include... Figure 12 The more or fewer components shown, or having the same Figure 12 The different configurations shown.
[0171] Embodiments of the present invention also provide a computer-readable storage medium that can be disposed in a game server to store at least one instruction or at least one program related to implementing a game data processing method. The at least one instruction or the at least one program is loaded and executed by the processor to implement the game data processing method provided in the above-described method embodiments.
[0172] Optionally, in this embodiment, the storage medium may include, but is not limited to, various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0173] It should be noted that the order of the above embodiments of the present invention is merely for descriptive purposes and does not represent the superiority or inferiority of the embodiments. Furthermore, specific embodiments have been described above. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims can be performed in a different order than that shown in the embodiments and still achieve the desired result. Additionally, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired result. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0174] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the device embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0175] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0176] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for processing game data, characterized in that, The method includes: Determine multiple linked list cache spaces in memory, the multiple linked list cache spaces are used to store game data in the form of linked lists, and the linked list cache spaces are LRU cache spaces; Each of the plurality of linked list cache spaces is configured with a different first hash value, wherein the first hash value is the output of a preset hash algorithm; When at least one piece of game data is obtained from the game database, the second hash value of each piece of game data in the at least one piece of game data is determined using the preset hash algorithm; Based on the matching between the second hash value and the first hash value, determine the first target linked list cache space corresponding to each game data; Write the at least one game data into the corresponding first target linked list cache space.
2. The game data processing method according to claim 1, characterized in that, The step of determining the second hash value of each game data in the at least one game data using the preset hash algorithm includes: Determine the data identifier for each piece of game data in the at least one piece of game data; Take the remainder of each game data data by dividing the data identifier of each game data data by the total number of linked list cache spaces, and obtain the remainder corresponding to each game data data. The remainder is determined as the second hash value of the corresponding game data, thus obtaining the second hash value of each game data in the at least one game data.
3. The method for processing game data according to claim 1, characterized in that, The method further includes: Upon receiving an access request for target game data, the third hash value of the target game data is determined using the preset hash algorithm; Based on the matching between the third hash value and the first hash value, a second target linked list cache space for storing the target game data is determined; Read the target game data from the second target linked list cache space.
4. The game data processing method according to claim 3, characterized in that, The step of reading the target game data from the second target linked list cache space includes: Determine the target memory address pointer of the target game data in the second target linked list cache space; The target memory address corresponding to the target memory address pointer is obtained based on the address-of operation; The target memory address is converted to a target physical address, and the target game data is read based on the target physical address.
5. The game data processing method according to claim 4, characterized in that, After reading the target game data based on the target physical address, the method further includes: A first update operation is performed on the reference count of the target game data in the second target linked list cache space, the first update operation including incrementing the reference count by 1; When it is determined that the use of the target game data is to be terminated, a second update operation is performed on the reference count of the target game data in the second target linked list cache space. The second update operation includes decrementing the reference count by 1. When the reference count of the target game data is zero, the target game data is deleted from the second target linked list cache space.
6. The method for processing game data according to claim 3, characterized in that, Each of the multiple linked list cache spaces includes a hot zone space at the head and a cold zone space at the tail. The hot zone space is used to store game data whose access frequency exceeds a preset frequency threshold, and the cold zone space is used to store game data whose access frequency does not exceed the preset frequency threshold. Accordingly, after reading the target game data from the second target linked list cache space, the method further includes: Increment the access frequency of the target game data in the second target linked list cache space by 1 to obtain the update access frequency; Determine whether the update access frequency exceeds the preset frequency threshold; If the determination result is yes, the target game data is stored in the hot zone space of the second target linked list cache space.
7. The game data processing method according to claim 6, characterized in that, The method further includes: For each of the multiple linked list cache spaces, determine the first access frequency of each game data stored in the cold zone space in the linked list cache space; Identify at least one game data to be eliminated whose first access frequency is less than or equal to a preset elimination frequency; Remove at least one game data to be eliminated from the linked list cache space.
8. A device for processing game data, characterized in that, The device includes: The first determining module is used to determine multiple linked list cache spaces in memory, the multiple linked list cache spaces are used to store game data in the form of linked lists, and the linked list cache spaces are LRU cache spaces; The configuration module is used to configure a different first hash value for each of the multiple linked list cache spaces, wherein the first hash value is the output of a preset hash algorithm; The second determining module is used to determine the second hash value of each game data in the at least one game data when the game database returns at least one game data; The third determining module is used to determine the first target linked list cache space corresponding to each game data based on the matching situation between the second hash value and the first hash value; The writing module is used to write the at least one game data into the corresponding first target linked list cache space.
9. The game data processing apparatus according to claim 8, characterized in that, The second determining module includes: The fourth determining module is used to determine the data identifier of each piece of game data in the at least one piece of game data; The calculation module is used to take the remainder of the data identifier of each game data with respect to the total number of linked list cache spaces to obtain the remainder corresponding to each game data. The fifth determining module is used to determine the remainder as the second hash value of the corresponding game data, thereby obtaining the second hash value of each game data in the at least one game data.
10. The game data processing apparatus according to claim 8, characterized in that, The device further includes: The sixth determining module is used to determine the third hash value of the target game data using the preset hash algorithm when an access request for the target game data is received. The seventh determining module is used to determine the second target linked list cache space for storing the target game data based on the matching situation between the third hash value and the first hash value; The reading module is used to read the target game data from the second target linked list cache space.
11. The game data processing apparatus according to claim 10, characterized in that, The reading module includes: The eighth determining module is used to determine the target memory address pointer of the target game data in the second target linked list cache space; The first acquisition module is used to acquire the target memory address corresponding to the target memory address pointer based on the address fetch operation; The address translation module is used to convert the target memory address into a target physical address and read the target game data according to the target physical address.
12. The game data processing apparatus according to claim 11, characterized in that, The device further includes: The first update module is used to perform a first update operation on the reference count of the target game data in the second target linked list cache space, wherein the first update operation includes incrementing the reference count by 1; The second update module is used to perform a second update operation on the reference count of the target game data in the second target linked list cache space when it is determined that the use of the target game data will end. The second update operation includes decrementing the reference count by 1. The first deletion module is used to delete the target game data from the second target linked list cache space when the reference count of the target game data is zero.
13. The game data processing apparatus according to claim 10, characterized in that, Each of the multiple linked list cache spaces includes a hot zone space at the head and a cold zone space at the tail. The hot zone space is used to store game data whose access frequency exceeds a preset frequency threshold, and the cold zone space is used to store game data whose access frequency does not exceed the preset frequency threshold. Accordingly, the device also includes: The access frequency update module is used to increment the access frequency of the target game data in the second target linked list cache space by 1 to obtain the updated access frequency; The judgment module is used to determine whether the update access frequency exceeds the preset frequency threshold; The storage module is used to store the target game data in the hot zone space of the second target linked list cache space when the judgment result is yes.
14. The game data processing apparatus according to claim 13, characterized in that, The device further includes: The ninth determining module is used to determine the first access frequency of each game data stored in the cold zone space in each of the multiple linked list cache spaces; The tenth determining module is used to determine at least one game data to be eliminated where the first access frequency is less than or equal to the preset elimination frequency; The second deletion module is used to delete the at least one game data to be eliminated from the linked list cache space.
15. A game server, characterized in that, The system includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, the at least one instruction or the at least one program being loaded and executed by the processor to implement the method for processing game data as described in any one of claims 1 to 7.
16. A computer-readable storage medium storing at least one instruction or at least one program, said at least one instruction or said at least one program being loaded and executed by a processor to implement the game data processing method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
A data reading method and device
CN108984128A