Difference between revisions of "Limit Service CPU and Memory Usage"

(Created page with "<span style="color:red;">'''If you updated your Windows server to TCAdmin 2.0.142 you must reboot before you can apply memory and CPU limits.'''</span> ==Windows== ===Limitin...")
 
(10 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
===Limiting a service's CPU usage===
 
===Limiting a service's CPU usage===
 
The maximum value for CPU limit is 100%. CPU limit is affected by the number of cores assigned to the service or virtual server. For example if the service has 1 core assigned and limit is set to 50% the actual limit is 50% of 1 core.
 
The maximum value for CPU limit is 100%. CPU limit is affected by the number of cores assigned to the service or virtual server. For example if the service has 1 core assigned and limit is set to 50% the actual limit is 50% of 1 core.
 +
  
 
To set the CPU limit go to the game server's service settings, set the value of CPU limit and save. The CPU limit is applied immediately. The service does not need to be restarted.
 
To set the CPU limit go to the game server's service settings, set the value of CPU limit and save. The CPU limit is applied immediately. The service does not need to be restarted.
Line 12: Line 13:
 
* If you set the virtual memory limit too low the service might crash while starting up or it might crash later if it requires more memory than allowed.
 
* If you set the virtual memory limit too low the service might crash while starting up or it might crash later if it requires more memory than allowed.
 
* If you set the virtual memory limit and the service is currently using more than allowed you will have to restart it to apply the limit.
 
* If you set the virtual memory limit and the service is currently using more than allowed you will have to restart it to apply the limit.
 +
* Memory usage might go slightly over 100%, specially if the game server is started with a .bat because it will add memory usage from cmd.exe and from the main exe.
 +
  
 
To set the memory or virtual memory limit go to the game server's service settings, set the values and save. The memory and virtual memory limit is applied immediately. The service does not need to be restarted.
 
To set the memory or virtual memory limit go to the game server's service settings, set the values and save. The memory and virtual memory limit is applied immediately. The service does not need to be restarted.
 +
 +
=== Virtual Servers ===
 +
Important notes:
 +
* When a service belongs to a virtual server the memory limit in service settings can't be set higher than the memory assigned to the virtual server.
 +
* A single process can't use more memory than what is assigned in the virtual server's settings even if there is no limit assigned in service settings.
 +
* CPU limit of a service is affected by the number of cores assigned to the service or virtual server. For example if the parent server has 16 cores, the virtual server has 4 cores and CPU limit of a service is set to 50% it will use up to 2 cores. In this case if you change the virtual server's cores the service needs to be restarted for the change to take effect.
  
 
==Linux==
 
==Linux==
Line 20: Line 29:
  
 
Each core is 100%. The maximum value is 100 multiplied by the number of cores. For example 200% means 2 full cores.
 
Each core is 100%. The maximum value is 100 multiplied by the number of cores. For example 200% means 2 full cores.
 +
  
 
To set the CPU limit go to the game server's service settings, set the value of CPU limit and save. The CPU limit is applied after the service is restarted.
 
To set the CPU limit go to the game server's service settings, set the value of CPU limit and save. The CPU limit is applied after the service is restarted.
Line 26: Line 36:
 
This feature is currently not supported on Linux.
 
This feature is currently not supported on Linux.
  
== Setting CPU/memory values from the billing API ==
+
== Billing API ==
To limit CPU configure your module to send a value for game_cpu
+
To limit the service's CPU configure your module to send a value for game_cpu
 +
 
 +
To limit the service's memory configure your module to send a value for game_memory or game_virtual_memory (Windows only)
  
To limit memory configure your module to send a value for game_memory or game_virtual_memory (Windows only)
+
The billing api supports setting these values when creating a new service and when updating the settings.
  
The billing api supports setting these values when creating a new game server and when updating a game server's settings.
+
== Scripting ==
 +
This script sets the memory limit to 2GB and CPU limit to 75%.
 +
ThisService.MemoryLimitMB = 2048
 +
ThisService.CpuLimit = 75
 +
ThisService.Save()
 +
ThisService.Configure()

Revision as of 15:51, 6 March 2020

If you updated your Windows server to TCAdmin 2.0.142 you must reboot before you can apply memory and CPU limits.

Windows

Limiting a service's CPU usage

The maximum value for CPU limit is 100%. CPU limit is affected by the number of cores assigned to the service or virtual server. For example if the service has 1 core assigned and limit is set to 50% the actual limit is 50% of 1 core.


To set the CPU limit go to the game server's service settings, set the value of CPU limit and save. The CPU limit is applied immediately. The service does not need to be restarted.

Limiting a service's memory and virtual memory

Important notes:

  • If you limit a service's memory it will use more virtual memory. This can increase your server's disk activity.
  • If you set the virtual memory limit too low the service might crash while starting up or it might crash later if it requires more memory than allowed.
  • If you set the virtual memory limit and the service is currently using more than allowed you will have to restart it to apply the limit.
  • Memory usage might go slightly over 100%, specially if the game server is started with a .bat because it will add memory usage from cmd.exe and from the main exe.


To set the memory or virtual memory limit go to the game server's service settings, set the values and save. The memory and virtual memory limit is applied immediately. The service does not need to be restarted.

Virtual Servers

Important notes:

  • When a service belongs to a virtual server the memory limit in service settings can't be set higher than the memory assigned to the virtual server.
  • A single process can't use more memory than what is assigned in the virtual server's settings even if there is no limit assigned in service settings.
  • CPU limit of a service is affected by the number of cores assigned to the service or virtual server. For example if the parent server has 16 cores, the virtual server has 4 cores and CPU limit of a service is set to 50% it will use up to 2 cores. In this case if you change the virtual server's cores the service needs to be restarted for the change to take effect.

Linux

Limiting a service's CPU usage

This feature requires cpulimit: https://github.com/opsengine/cpulimit

Each core is 100%. The maximum value is 100 multiplied by the number of cores. For example 200% means 2 full cores.


To set the CPU limit go to the game server's service settings, set the value of CPU limit and save. The CPU limit is applied after the service is restarted.

Limiting a service's memory usage

This feature is currently not supported on Linux.

Billing API

To limit the service's CPU configure your module to send a value for game_cpu

To limit the service's memory configure your module to send a value for game_memory or game_virtual_memory (Windows only)

The billing api supports setting these values when creating a new service and when updating the settings.

Scripting

This script sets the memory limit to 2GB and CPU limit to 75%.

ThisService.MemoryLimitMB = 2048
ThisService.CpuLimit = 75
ThisService.Save()
ThisService.Configure()
Retrieved from "https://help.tcadmin.com/index.php?title=Limit_Service_CPU_and_Memory_Usage&oldid=2018"