Garbage collection method and device in game, readable storage medium and electronic equipment
By receiving load balancer tasks in the game and setting a maximum load value to stagger the timing of game tasks and garbage collection, the game lag problem caused by garbage collection was solved, achieving efficient garbage collection and improved user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUANGZHOU BOGUAN TELECOMM TECH LTD
- Filing Date
- 2022-06-06
- Publication Date
- 2026-07-31
AI Technical Summary
In games with high real-time requirements, garbage collection can cause game lag. Current technologies that disable garbage collection in scripting languages increase maintenance difficulty, while garbage collection in child processes requires modification of the script source code, which is highly complex.
By receiving game tasks assigned by the load balancer, setting the maximum load value and sending it to the load balancer, the game task process is prevented from being assigned game tasks. Garbage collection is performed after the task is completed. The timing of game tasks and garbage collection in the task process is staggered by preset rules and time intervals.
It successfully reclaims garbage objects with circular references without modifying the script source code, avoiding game lag and memory leaks, and improving the user's gaming experience.
Smart Images

Figure CN115048217B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and more specifically, to a garbage collection method in a game, a garbage collection device in a game, a computer-readable storage medium, and an electronic device. Background Technology
[0002] Garbage collection is an automatic memory management mechanism. Currently, the implementation methods of garbage collection have high performance. However, in games with high real-time requirements, the execution of garbage collection during game runtime can cause game lag and reduce the user's gaming experience.
[0003] In related technologies, garbage collection-related stuttering in games can be avoided by disabling garbage collection in the game's scripting language or by having the game's child processes perform garbage collection. However, when disabling garbage collection in the game's scripting language, circular references cannot exist in the game program. If circular references exist, it will not only cause memory overflow but also increase the maintenance difficulty. When having the game's child processes perform garbage collection, a large amount of script source code needs to be modified, which increases the implementation complexity.
[0004] Therefore, a new method for garbage collection in games is needed.
[0005] It should be noted that the information in the background section above is only used to enhance the understanding of the background of the present invention, and therefore may include information that does not constitute prior art known to those skilled in the art. Summary of the Invention
[0006] The purpose of this disclosure is to provide a method for garbage collection in games, a garbage collection device for games, a computer-readable storage medium, and an electronic device, thereby overcoming, at least to some extent, the problem of the complexity of garbage collection implementation in games due to the limitations and defects of related technologies.
[0007] According to one aspect of this disclosure, a method for garbage collection in a game is provided, comprising:
[0008] Receive game tasks assigned by the load balancer;
[0009] According to preset rules, the load value is set to the maximum load value, and the maximum load value is sent to the load balancer so that the load balancer does not assign the game task to the task process that sent the maximum load value;
[0010] After the game tasks assigned by the load balancer have been completed, garbage collection is performed.
[0011] In one exemplary embodiment of this disclosure, the garbage collection method includes, before receiving game tasks assigned by a load balancer:
[0012] Obtain the real-time load value and send the real-time load value to the load balancer so that the load balancer can allocate the game task to the task process based on the real-time load value.
[0013] In one exemplary embodiment of this disclosure, setting the load value to a maximum load value according to a preset rule and sending the maximum load value to the load balancer includes:
[0014] Obtain the preset interval time threshold;
[0015] Obtain the time of the last garbage collection execution relative to the current execution of the game task, and obtain the execution time difference based on the current execution time of the game task and the time of the last garbage collection execution;
[0016] When it is determined that the execution time difference is greater than the preset interval time threshold, the load value is set to the maximum load value and the maximum load value is sent to the load balancer.
[0017] In one exemplary embodiment of this disclosure, setting the load value to a maximum load value according to a preset rule and sending the maximum load value to the load balancer includes:
[0018] When the task process can only carry one game task, and the task process is assigned to a game task, the load value is set to the maximum load value, and the maximum load value is sent to the load balancer.
[0019] In one exemplary embodiment of this disclosure, setting the load value to a maximum load value according to a preset rule and sending the maximum load value to the load balancer includes:
[0020] When the task process carries multiple game tasks, obtain the first task process;
[0021] A preset first time interval is obtained. Based on the preset first time interval, the load value of the first task process is set to the maximum load value, and the maximum load value of the first task process is sent to the load balancer.
[0022] In one exemplary embodiment of this disclosure, after performing garbage collection, the garbage collection method further includes:
[0023] Obtain the progress of the second task;
[0024] After the first task process performs garbage collection, based on the preset first time interval, the load value of the second task process is set to the maximum load value, and the maximum load value is sent to the load balancer.
[0025] In one exemplary embodiment of this disclosure, after the game task assigned by the load balancer has been completed, garbage collection is performed, including:
[0026] Monitor the number of game missions;
[0027] When the number of game tasks is zero, garbage collection is performed using the garbage collection implementation method corresponding to the target game's scripting language.
[0028] In one exemplary embodiment of this disclosure, after the game task assigned by the load balancer has been completed, garbage collection is performed, including:
[0029] Monitor the execution time of the game tasks;
[0030] A preset execution time threshold is obtained. When the execution time of the game task exceeds the preset execution time threshold, garbage collection is performed using the garbage collection implementation method corresponding to the scripting language of the target game.
[0031] According to one aspect of this disclosure, a game-based garbage collection device is provided, comprising:
[0032] The game task receiving module is used to receive game tasks assigned by the load balancer.
[0033] The process load adjustment module is used to set the load value to the maximum load value according to preset rules, and send the maximum load value to the load balancer so that the load balancer does not assign the game task to the task process that sends the maximum load value.
[0034] The garbage collection module is used to perform garbage collection after the game tasks assigned by the load balancer have been completed.
[0035] According to one aspect of this disclosure, a computer storage medium is provided that stores a computer program thereon, which, when executed by a processor, implements the garbage collection method in a game as described in any of the exemplary embodiments above.
[0036] According to one aspect of this disclosure, an electronic device is provided, comprising:
[0037] Processor; and
[0038] Memory for storing the executable instructions of the processor;
[0039] The processor is configured to execute the garbage collection method in the game according to any of the above exemplary embodiments by executing the executable instructions.
[0040] This disclosure provides a garbage collection method in a game, which involves receiving game tasks assigned by a load balancer; setting the load value to a maximum load value according to preset rules and sending the maximum load value to the load balancer so that the load balancer does not assign the game task to the task process that sent the maximum load value; and performing garbage collection after the game task assigned by the load balancer is completed. On one hand, after the load balancer assigns a game task to a target game process, the task process sets its load value to the maximum load value according to preset rules and reports the maximum load value to the load balancer. After the task process completes the game task, garbage collection is performed, thus staggering the timing of game task execution and garbage collection. Compared with related technologies that use methods that disable game scripts or have game subprocesses perform garbage collection, this method is simpler to implement and does not require avoiding circular references or modifying the script source code during development. On the other hand, performing garbage collection only after the task process completes the game task successfully reclaims garbage objects with circular references, avoids game lag caused by automatic garbage collection, and prevents memory leaks.
[0041] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit the invention. Attached Figure Description
[0042] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention. It is obvious that the drawings described below are merely some embodiments of the invention, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort.
[0043] Figure 1 The flowchart illustrates a garbage collection method in a game according to an exemplary embodiment of the present invention.
[0044] Figure 2 The diagram illustrates a block diagram of a garbage collection system in a game according to an exemplary embodiment of the present invention.
[0045] Figure 3 The flowchart illustrates a method according to an example embodiment of the present invention for setting a load value to a maximum load value according to a preset rule and sending the maximum load value to a load balancer.
[0046] Figure 4 The flowchart illustrates a method according to an exemplary embodiment of the present invention, in which a load value is set to a maximum load value and the maximum load value is sent to a load balancer when a task process carries multiple game tasks.
[0047] Figure 5 The flowchart illustrates a garbage collection method according to an example embodiment of the present invention, after a first task process performs garbage collection.
[0048] Figure 6 The flowchart illustrates a method for performing garbage collection after a game task assigned by a load balancer has been completed, according to an exemplary embodiment of the present invention.
[0049] Figure 7 The flowchart illustrates another method for performing garbage collection after the game tasks assigned by the load balancer have been completed, according to an exemplary embodiment of the present invention.
[0050] Figure 8 The diagram schematically illustrates a waste disposal device in a game according to an exemplary embodiment of the present invention.
[0051] Figure 9 An electronic device for implementing the waste disposal method in the above-described game is illustrated according to an exemplary embodiment of the present invention. Detailed Implementation
[0052] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided to make the invention more comprehensive and complete, and to fully convey the concept of the exemplary embodiments to those skilled in the art. The described features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a full understanding of embodiments of the invention. However, those skilled in the art will recognize that the technical solutions of the invention may be practiced with one or more of these specific details omitted, or other methods, components, apparatus, steps, etc., may be employed. In other instances, well-known technical solutions are not shown or described in detail to avoid obscuring various aspects of the invention.
[0053] Furthermore, the accompanying drawings are merely illustrative of the invention and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and therefore repeated descriptions of them will be omitted. Some block diagrams shown in the drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.
[0054] To address the issue of game lag caused by garbage collection, two methods have emerged: one that disables scripts for garbage collection, and the other that uses subprocesses to execute scripts for garbage collection.
[0055] In a game project using related technologies, the scripting language is Python, and Python employs reference counting as its garbage collection mechanism. To address circular references, mark-and-sweep and generational garbage collection are used. However, generational garbage collection triggers a third generation garbage collection (full garbage collection) when the second generation reaches a threshold. This full garbage collection iterates through all objects, causing game lag. Therefore, when disabling script-based garbage collection, circular references must be avoided in the code. In a production environment, the number of circular references must be checked first, and then their location and elimination must be addressed, requiring a high level of skill from the programmer. When using a subprocess to execute script-based garbage collection, garbage collection scanning in the main process is disabled, and time-consuming operations during garbage collection are moved to the subprocess. This solution can resolve the main thread lag caused by garbage collection, but it requires significant modifications to the script source code, resulting in high implementation complexity.
[0056] Based on one or more of the above-mentioned problems, this exemplary embodiment first provides a garbage collection method in games, which can run on servers, server clusters, or cloud servers, etc. Of course, those skilled in the art can also run the method of the present invention on other platforms as needed, and this exemplary embodiment does not make any special limitations on this.
[0057] refer to Figure 1 As shown, the garbage collection method in this game may include steps S110-S130:
[0058] Step S110. Receive game tasks assigned by the load balancer;
[0059] Step S120. According to the preset rules, set the load value to the maximum load value and send the maximum load value to the load balancer so that the load balancer does not assign the game task to the task process that sent the maximum load value;
[0060] Step S130. After the game tasks assigned by the load balancer have been completed, garbage collection is performed.
[0061] The garbage collection method in the aforementioned game involves receiving game tasks assigned by a load balancer; setting the load value to the maximum load value according to preset rules and sending the maximum load value to the load balancer so that the load balancer does not assign the game task to the task process that sent the maximum load value; and performing garbage collection after the game task assigned by the load balancer is completed. On one hand, after the load balancer assigns a game task to the target game's task process, the task process sets its load value to the maximum load value according to preset rules and reports this maximum load value to the load balancer. After the task process completes the game task, garbage collection is performed, thus staggering the timing of game task execution and garbage collection. Compared with related technologies that use methods that disable game scripts or have game child processes perform garbage collection, this method is simpler to implement and does not require avoiding circular references or modifying the script source code during development. On the other hand, performing garbage collection only after the task process completes the game task successfully reclaims garbage objects with circular references, avoids game lag caused by automatic garbage collection, and prevents memory leaks.
[0062] The following provides a detailed explanation and description of each step involved in the garbage collection method in the game according to the example embodiments of this disclosure.
[0063] First, the application scenarios and inventive objectives of the exemplary embodiments of this disclosure will be explained and described. Specifically, the exemplary embodiments of this disclosure can be applied to battle games with high real-time requirements, mainly studying how to avoid game lag caused by garbage collection in battle games.
[0064] In this disclosure, after the game starts, each task process receives game tasks assigned by the load balancer. After receiving the game task, the task process sets its own load value to the maximum load value according to preset rules and sends the maximum load value to the load balancer. After the load balancer receives the maximum load value sent by the task process, it no longer assigns game tasks to the task process that sent the maximum load value. The task process that sent the maximum load value then executes the game task. After the task process finishes executing the game task assigned by the load balancer, it performs garbage collection, which avoids the problem of lag caused by garbage collection during the game and improves the user's gaming experience.
[0065] Secondly, the garbage collection system in the game involved in the embodiments of this disclosure will be explained and described. (Reference) Figure 2As shown, the garbage collection system in this game may include: user 210, load balancer 220, and task process 230. User 210 initiates battle requests in the game. After user 210 initiates a battle request, task process 230 sends its real-time load value to load balancer 220. Upon receiving the load value from task process 230, load balancer 220 assigns game tasks to task process 230. After receiving the assigned game tasks from load balancer 220, task process 230 sets its load value to the maximum load value according to preset rules and sends this maximum load value to load balancer 220. Load balancer 220 then stops assigning game tasks to task process 230 that sent the maximum load value. After task process 230 finishes executing the game tasks assigned by load balancer 220, it performs garbage collection. After garbage collection, task process 230 sends its real-time load value to load balancer 220 again.
[0066] The following will combine Figure 2 Steps S110-S130 are explained and described in detail.
[0067] In step S110, the game task assigned by the load balancer is received.
[0068] When the target game's garbage collection mechanism is the scripting language's automatic garbage collection mechanism, if one or more game tasks are being executed on any process, and the target game's scripting language's automatic garbage collection mechanism performs garbage collection at this time, it will cause game lag. Therefore, in this example embodiment, when the target game starts, the target game's scripting language is obtained, and the target game's scripting language's automatic garbage collection process is closed.
[0069] In this example embodiment, the garbage collection method may include the following before receiving game tasks assigned by the load balancer:
[0070] Obtain the real-time load value and send the real-time load value to the load balancer so that the load balancer can allocate the game task to the task process based on the real-time load value.
[0071] Specifically, when a user initiates a target game battle request through the game terminal, the task process obtains its real-time load value and sends it to the load balancer. The load balancer assigns game tasks to each task process based on the real-time load value reported by each task process, and each task process receives and executes the game tasks assigned by the load balancer.
[0072] In step S120, according to preset rules, the load value is set to the maximum load value, and the maximum load value is sent to the load balancer so that the load balancer does not assign the game task to the task process that sent the maximum load value.
[0073] In this example embodiment, when the garbage collection mechanism of the target game's scripting language is disabled, as the task process continuously executes game tasks, more and more garbage objects will be generated. If these garbage objects are not cleaned up, it will lead to memory overflow. Therefore, after the load balancer assigns game tasks to the task process, the task process sets its load value to the maximum load value according to preset rules, sends the maximum load value to the load balancer, and executes the assigned game task. After the game task is completed, garbage collection is performed.
[0074] refer to Figure 3 As shown, according to preset rules, setting the load value to the maximum load value and sending the maximum load value to the load balancer may include steps S310-S330:
[0075] Step S310. Obtain the preset interval time threshold;
[0076] Step S320. Obtain the time of the last garbage collection execution relative to the current execution of the game task, and obtain the execution time difference based on the current execution time of the game task and the last execution time of the garbage collection execution;
[0077] Step S330. When it is determined that the execution time difference is greater than the preset interval time threshold, the load value is set to the maximum load value, and the maximum load value is sent to the load balancer.
[0078] The following will further explain and illustrate steps S310-S330. Specifically, firstly, a preset interval time threshold is obtained; then, the execution time difference is calculated by taking the current execution time of the game task and the time of the last garbage collection execution of the task process relative to the current execution time of the game task. When the execution time difference is greater than the preset interval time threshold, the task process sets its load value to the maximum load value and sends the maximum load value to the load balancer, so that the load balancer will no longer assign game tasks to the task process that sent the maximum load value. The preset interval time threshold can be 3 minutes or 5 minutes; in this example embodiment, the preset time interval is not specifically limited.
[0079] In this example embodiment, the load value of a task process can be measured by the number of game tasks included in the task process, or by the CPU time percentage of the task process; no specific limitation is made in this example embodiment. Furthermore, a task process in the target game can carry one game task or multiple game tasks; no specific limitation is made in this example embodiment regarding the number of game tasks carried by a task process.
[0080] In this example embodiment, setting the load value to the maximum load value according to a preset rule and sending the maximum load value to the load balancer may include:
[0081] When the task process can only carry one game task, and the task process is assigned to a game task, the load value is set to the maximum load value, and the maximum load value is sent to the load balancer.
[0082] Specifically, when a task process can only handle one game task, and the load balancer assigns a task process to it, the task process sets its load value to the maximum load value and sends the maximum load value to the load balancer. After the task process finishes executing the game task assigned by the load balancer, it performs garbage collection. After garbage collection is completed, the task process sends the real-time load value to the load balancer again.
[0083] In this example embodiment, reference Figure 4 As shown, according to preset rules, setting the load value to the maximum load value and sending the maximum load value to the load balancer may include steps S410 and S420:
[0084] Step S410. When the task process carries multiple game tasks, obtain the first task process;
[0085] Step S420. Obtain a preset first time interval, and based on the preset first time interval, set the load value of the first task process to the maximum load value, and send the maximum load value of the first task process to the load balancer.
[0086] The following will further explain and illustrate steps S410 and S420. Specifically, when a task process can handle multiple game tasks, the first task process in the target game's task process is obtained; then, a preset first time interval is obtained, and based on the obtained preset first time interval, the first task process sets its load value to the maximum load value, and sends the maximum load value to the load balancer. The task process can be divided into multiple batches, i.e., the first task process, the second task process, etc. In this example embodiment, the number of batches of the divided task process is not specifically limited, nor is the number of processes included in each batch. The preset first time interval can be 1 minute or 3 minutes; there is no specific limitation on the preset first time interval here, and those skilled in the art can set the first time interval according to the specific game scenario. When the task process is executing a game task for the first time after the target game starts, the load value can be set to the maximum load value based on the target game start time and the first time interval. When the task process has already performed garbage collection, the load value can be set to the maximum load value based on the garbage collection time and the preset first time interval.
[0087] For example, when the target game starts, after a preset first time interval after the start of the target game, the first batch of task processes in the task process can set their load value to the maximum load value. That is, the first task process sets its load value to the maximum load value and sends the maximum load value to the load balancer. When the task process has already performed garbage collection and then executes the game task assigned by the load balancer again, the first task process can set its load value to the maximum load value after the preset first time interval after the last garbage collection is completed, and send the maximum load value to the load balancer.
[0088] In step S130, after the game tasks assigned by the load balancer have been completed, garbage collection is performed.
[0089] In this example embodiment, after a task process reports its maximum load value to the load balancer, the load balancer does not assign game tasks to the task process that reported the maximum load value. Instead, the task process that reported the maximum load value executes the game tasks assigned by the load balancer. After the game tasks assigned by the load balancer are completed, garbage collection is performed.
[0090] In this example embodiment, reference Figure 5 As shown, after the first task process performs garbage collection, the garbage collection method may further include steps S510 and S520:
[0091] Step S510. Obtain the second task progress;
[0092] Step S520. After the first task process performs garbage collection, based on the preset first time interval, the load value of the second task process is set to the maximum load value, and the maximum load value is sent to the load balancer.
[0093] The following will further explain and illustrate steps S510 and S520. Specifically, after the first task process completes garbage collection, a second task process is obtained. After a preset first time interval following the garbage collection performed by the first task process, the second task process sets its load value to the maximum load value and sends this maximum load value to the load balancer. That is, in this example embodiment, after the first task process sets its load value to the maximum load value and sends it to the load balancer, the first task process executes the assigned game task. After the first task process completes the game task, garbage collection is performed. After a preset first time interval following the garbage collection performed by the first task process, the second task process sets its load value to the maximum load value and sends this maximum load value to the load balancer.
[0094] In this example embodiment, by dividing the target game's task process into a first task process and a second task process, and after the first task process completes the preset first time interval for garbage collection, the second task process sets its load value to the maximum load value, so that the second task process can execute the assigned game task, the garbage collection is executed in a rolling and alternating manner. This staggers the timing of the task process executing the game task and executing the garbage collection, thereby realizing the collection of garbage objects on the one hand, and avoiding game lag caused by garbage collection on the other hand, thus improving the user's gaming experience.
[0095] It should be noted that after the first task process in the task process completes garbage collection, it sends the real-time load value to the load balancer so that the load balancer can allocate game tasks to the first task process based on the real-time load value of the first task process.
[0096] In this example embodiment, reference Figure 6 As shown, after the game task assigned by the load balancer is completed, garbage collection is performed, which may include steps S610 and S620:
[0097] Step S610. Monitor the number of game tasks;
[0098] Step S620. When the number of game tasks is zero, determine and execute garbage collection using the garbage collection implementation method corresponding to the scripting language.
[0099] The following will further explain and illustrate steps S610 and S620. Specifically, after each task process reports its maximum load value to the load balancer, the number of game tasks can be monitored when each task process executes a game task. When the number of game tasks in a task process is detected to be zero, garbage collection is performed using the garbage collection method corresponding to the target game's scripting language. Common garbage collection implementation methods include reference counting, mark-and-sweep, and generational garbage collection. Since different scripting languages have different garbage collection methods, the corresponding garbage collection method can be determined based on the target game's scripting language and then executed.
[0100] In this example embodiment, reference Figure 7 As shown, after the game task assigned by the load balancer is completed, garbage collection is performed, which may include steps S710 and S720:
[0101] Step S710. Monitor the execution time of the game task;
[0102] Step S720. Obtain a preset execution time threshold. When the execution time of the game task exceeds the preset execution time threshold, determine and execute garbage collection using the garbage collection implementation method corresponding to the scripting language.
[0103] The following will provide further explanation and description of steps S710 and S720. Specifically, after each task process reports its maximum load value to the load balancer, the execution time of the game task is monitored during the execution of the game task. When the execution time of the game task exceeds a preset execution time threshold, garbage collection is performed using the garbage collection method corresponding to the scripting language of the target game.
[0104] In this disclosure, when the number of players is small, that is, when the number of battle requests initiated by users is small, some task processes will be idle. When some task processes are idle, garbage collection can be performed on the idle task processes according to a preset second time interval. That is, garbage collection is performed on the idle task processes every preset second time interval. Here, an idle task process is one on which no game tasks are assigned by the load balancer. The preset second time interval can be 10 minutes or 15 minutes. In this example embodiment, the preset second time interval is not specifically limited.
[0105] The garbage collection method in the game provided in this exemplary embodiment has at least the following advantages: On the one hand, when the task process of the target game receives the game task assigned by the load balancer, according to preset rules, the task process sets its load value to the maximum load value, sends the maximum load value to the load balancer, and executes the game task. After the game task is completed, garbage collection is performed. The implementation is simple, and there is no need to avoid circular references or modify the script source code during development. On the other hand, after the target game starts, the load value of the first task process is set to the maximum load value according to a preset first time interval, the maximum load value is sent to the load balancer, and the game task assigned by the load balancer is executed. After the game task is completed, garbage collection is performed. After the first task process completes the first preset time interval of garbage collection, the load value of the second task process is set to the maximum load value and sent to the load balancer. This realizes the rolling and alternating execution of garbage collection, staggering the timing of the task process executing the game task and the execution of garbage collection. This not only realizes the collection of garbage objects, but also avoids game lag caused by garbage collection, thus improving the user's gaming experience.
[0106] This disclosure also provides an example embodiment of a game-related waste recycling device, referenced to... Figure 8 As shown, it may include: a game task receiving module 810, a process load adjustment module 820, and a garbage collection module 830. Among them:
[0107] The game task receiving module 810 is used to receive game tasks assigned by the load balancer.
[0108] The process load adjustment module 820 is used to set the load value to the maximum load value according to a preset rule, and send the maximum load value to the load balancer so that the load balancer does not assign the game task to the task process that sends the maximum load value.
[0109] The garbage collection module 830 is used to perform garbage collection after the game tasks assigned by the load balancer have been completed.
[0110] The specific details of each module in the waste disposal device in the aforementioned game have been described in detail in the corresponding game's waste disposal method, so they will not be repeated here.
[0111] In one exemplary embodiment of this disclosure, the garbage collection method includes, before receiving game tasks assigned by a load balancer:
[0112] Obtain the real-time load value and send the real-time load value to the load balancer so that the load balancer can allocate the game task to the task process based on the real-time load value.
[0113] In one exemplary embodiment of this disclosure, setting the load value to a maximum load value according to a preset rule and sending the maximum load value to the load balancer includes:
[0114] Obtain the preset interval time threshold;
[0115] Obtain the time of the last garbage collection execution relative to the current execution of the game task, and obtain the execution time difference based on the current execution time of the game task and the time of the last garbage collection execution;
[0116] When it is determined that the execution time difference is greater than the preset interval time threshold, the load value is set to the maximum load value and the maximum load value is sent to the load balancer.
[0117] In one exemplary embodiment of this disclosure, setting the load value to a maximum load value according to a preset rule and sending the maximum load value to the load balancer includes:
[0118] When the task process can only carry one game task, and the task process is assigned to a game task, the load value is set to the maximum load value, and the maximum load value is sent to the load balancer.
[0119] In one exemplary embodiment of this disclosure, setting the load value to a maximum load value according to a preset rule and sending the maximum load value to the load balancer includes:
[0120] When the task process carries multiple game tasks, obtain the first task process;
[0121] A preset first time interval is obtained. Based on the preset first time interval, the load value of the first task process is set to the maximum load value, and the maximum load value of the first task process is sent to the load balancer.
[0122] In one exemplary embodiment of this disclosure, after performing garbage collection, the garbage collection method further includes:
[0123] Obtain the progress of the second task;
[0124] After the first task process performs garbage collection, based on the preset first time interval, the load value of the second task process is set to the maximum load value, and the maximum load value is sent to the load balancer.
[0125] In one exemplary embodiment of this disclosure, after the game task assigned by the load balancer has been completed, garbage collection is performed, including:
[0126] Monitor the number of game missions;
[0127] When the number of game tasks is zero, garbage collection is performed using the garbage collection implementation method corresponding to the target game's scripting language.
[0128] In one exemplary embodiment of this disclosure, after the game task assigned by the load balancer has been completed, garbage collection is performed, including:
[0129] Monitor the execution time of the game tasks;
[0130] A preset execution time threshold is obtained. When the execution time of the game task exceeds the preset execution time threshold, garbage collection is performed using the garbage collection implementation method corresponding to the scripting language of the target game.
[0131] It should be noted that although several modules or units of the device for performing actions have been mentioned in the detailed description above, this division is not mandatory. In fact, according to embodiments of the present invention, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.
[0132] Furthermore, although the steps of the method in this invention are described in a specific order in the accompanying drawings, this does not require or imply that the steps must be performed in that specific order, or that all the steps shown must be performed to achieve the desired result. Additional or alternative steps may be omitted, multiple steps may be combined into one step, and / or a step may be broken down into multiple steps.
[0133] In an exemplary embodiment of the present invention, an electronic device capable of implementing the above-described method is also provided.
[0134] Those skilled in the art will understand that various aspects of the present invention can be implemented as systems, methods, or program products. Therefore, various aspects of the present invention can be specifically implemented in the following forms: entirely hardware implementations, entirely software implementations (including firmware, microcode, etc.), or implementations combining hardware and software aspects, collectively referred to herein as “circuits,” “modules,” or “systems.”
[0135] The following reference Figure 9 To describe an electronic device 900 according to this embodiment of the present invention. Figure 9 The electronic device 900 shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.
[0136] like Figure 9 As shown, the electronic device 900 is manifested in the form of a general-purpose computing device. The components of the electronic device 900 may include, but are not limited to: at least one processing unit 910, at least one storage unit 920, a bus 930 connecting different system components (including storage unit 920 and processing unit 910), and a display unit 940.
[0137] The storage unit stores program code that can be executed by the processing unit 910, causing the processing unit 910 to perform the steps described in the "Exemplary Methods" section of this specification according to various exemplary embodiments of the present invention. For example, the processing unit 910 can perform actions such as... Figure 1 The steps shown are as follows: S110: Receive game tasks assigned by the load balancer; S120: Set the load value to the maximum load value according to the preset rules, and send the maximum load value to the load balancer so that the load balancer does not assign the game task to the task process that sent the maximum load value; S130: After the game task assigned by the load balancer is completed, perform garbage collection.
[0138] Storage unit 920 may include readable media in the form of volatile storage units, such as random access memory (RAM) 9201 and / or cache memory 9202, and may further include read-only memory (ROM) 9203.
[0139] Storage unit 920 may also include a program / utility 9204 having a set (at least one) program module 9205, such program module 9205 including but not limited to: operating system, one or more application programs, other program modules and program data, each or some combination of these examples may include an implementation of a network environment.
[0140] Bus 930 can represent one or more of several types of bus structures, including a memory cell bus or memory cell controller, a peripheral bus, a graphics acceleration port, a processing unit, or a local bus using any of the various bus structures.
[0141] Electronic device 900 can also communicate with one or more external devices 1000 (e.g., keyboard, pointing device, Bluetooth device, etc.), and with one or more devices that enable a user to interact with electronic device 900, and / or with any device that enables electronic device 900 to communicate with one or more other computing devices (e.g., router, modem, etc.). This communication can be performed via input / output (I / O) interface 950. Furthermore, electronic device 900 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 960. As shown, network adapter 1160 communicates with other modules of electronic device 900 via bus 930. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with electronic device 900, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0142] Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of the present invention can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, portable hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, terminal device, or network device, etc.) to execute the method according to the embodiments of the present invention.
[0143] In exemplary embodiments of the present invention, a computer-readable storage medium is also provided, on which a program product capable of implementing the methods described above is stored. In some possible embodiments, various aspects of the present invention may also be implemented as a program product comprising program code that, when the program product is run on a terminal device, causes the terminal device to perform the steps of the various exemplary embodiments of the present invention described in the "Exemplary Methods" section above.
[0144] According to embodiments of the present invention, a program product for implementing the above-described method may employ a portable compact disc read-only memory (CD-ROM) and include program code, and may run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited thereto. In this document, a readable storage medium may be any tangible medium containing or storing a program that may be used by or in conjunction with an instruction execution system, apparatus, or device.
[0145] The program product may employ any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection having one or more wires, a portable disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0146] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, carrying readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable signal medium may also be any readable medium other than a readable storage medium, capable of sending, propagating, or transmitting programs for use by or in conjunction with an instruction execution system, apparatus, or device.
[0147] The program code contained on the readable medium may be transmitted using any suitable medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination thereof.
[0148] Program code for performing the operations of this invention can be written in any combination of one or more programming languages, including object-oriented programming languages such as Java and C++, and conventional procedural programming languages such as C or similar languages. The program code can execute entirely on the user's computing device, partially on the user's device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0149] Furthermore, the above figures are merely illustrative of the processes included in the method according to exemplary embodiments of the present invention, and are not intended to be limiting. It is readily understood that the processes shown in the above figures do not indicate or limit the temporal order of these processes. Additionally, it is readily understood that these processes may be executed synchronously or asynchronously, for example, in multiple modules.
[0150] Other embodiments of the invention will readily occur to those skilled in the art upon consideration of the specification and practice of the invention described herein. This application is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not invented herein. The specification and embodiments are to be considered exemplary only, and the true scope and spirit of the invention are indicated by the claims.
Claims
1. A method for garbage collection in games, characterized in that, include: Receive game tasks assigned by the load balancer; According to preset rules, the load value is set to the maximum load value, and the maximum load value is sent to the load balancer so that the load balancer does not assign new game tasks to the task process that sent the maximum load value; wherein, the step of setting the load value to the maximum load value according to preset rules and sending the maximum load value to the load balancer includes: when the task process is carrying multiple game tasks, obtaining a first task process; obtaining a preset first time interval; based on the preset first time interval, setting the load value of the first task process to the maximum load value, and sending the maximum load value of the first task process to the load balancer; After the game tasks assigned by the load balancer before uploading the maximum load value have been completed, garbage collection is performed. Obtain the second task process; after the first task process performs garbage collection, based on the preset first time interval, set the load value of the second task process to the maximum load value, and send the maximum load value to the load balancer.
2. The waste recycling method according to claim 1, characterized in that, The garbage collection method includes the following steps before receiving game tasks assigned by the load balancer: Obtain the real-time load value and send the real-time load value to the load balancer so that the load balancer can allocate the game task to the task process based on the real-time load value.
3. The waste recycling method according to claim 1, characterized in that, According to preset rules, the load value is set to the maximum load value, and the maximum load value is sent to the load balancer, including: Obtain the preset interval time threshold; Obtain the time of the last garbage collection execution relative to the current execution of the game task, and obtain the execution time difference based on the current execution time of the game task and the last execution time of the garbage collection execution; When it is determined that the execution time difference is greater than the preset interval time threshold, the load value is set to the maximum load value and the maximum load value is sent to the load balancer.
4. The waste recycling method according to claim 1, characterized in that, According to preset rules, the load value is set to the maximum load value, and the maximum load value is sent to the load balancer, including: When the task process can only carry one game task, and the task process is assigned to a game task, the load value is set to the maximum load value, and the maximum load value is sent to the load balancer.
5. The waste recycling method according to claim 1, characterized in that, After the game tasks assigned by the load balancer are completed, garbage collection is performed, including: Monitor the number of game missions; When the number of game tasks is zero, garbage collection is performed using the garbage collection implementation method corresponding to the target game's scripting language.
6. The waste recycling method according to claim 1, characterized in that, After the game tasks assigned by the load balancer are completed, garbage collection is performed, including: Monitor the execution time of the game tasks; A preset execution time threshold is obtained. When the execution time of the game task exceeds the preset execution time threshold, garbage collection is performed using the garbage collection implementation method corresponding to the scripting language of the target game.
7. A garbage recycling device for games, characterized in that, include: The game task receiving module is used to receive game tasks assigned by the load balancer. A process load adjustment module is used to set a load value to a maximum load value according to a preset rule, and send the maximum load value to the load balancer, so that the load balancer does not assign new game tasks to the task process that sent the maximum load value; wherein, setting the load value to the maximum load value according to the preset rule and sending the maximum load value to the load balancer includes: when the task process is carrying multiple game tasks, obtaining a first task process; obtaining a preset first time interval; setting the load value of the first task process to the maximum load value based on the preset first time interval; and sending the maximum load value of the first task process to the load balancer; The garbage collection module is used to perform garbage collection after the game tasks assigned by the load balancer before the maximum load value is uploaded have been completed; Obtain the second task process; after the first task process performs garbage collection, based on the preset first time interval, set the load value of the second task process to the maximum load value, and send the maximum load value to the load balancer.
8. A computer storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the garbage collection method in the game as described in any one of claims 1-6.
9. An electronic device, characterized in that, include: processor; as well as Memory for storing the executable instructions of the processor; The processor is configured to execute the garbage collection method in the game according to any one of claims 1-6 by executing the executable instructions.