How to limit the number of processors used by Denodo
You can translate the document:
Overview
In order to limit the number of processors we have to take into account the operating system where the Denodo Platform is running.
Windows Systems
There are two ways to set the process affinity in Windows, via the graphical user interface (GUI), or via the command line.
Windows 10, 11
In Windows 10, 11, in order to set the process affinity you could perform the following steps:
- Open the Task Manager.
- Click on the Details tab to view the list of processes.
- Right-click on the process and choose the “Set Affinity” option.
- The “Processor affinity” dialog will open up where you can check the cells corresponding to different CPUs.
To launch the process you have to run that program from a command line (or from a .bat file):
start /affinity [n] [process name]
The binary values are not to be used in Windows, but they are useful for calculating which CPU cores are expected when the affinity is set. When you set the affinity, a binary value (1111), which matches Decimal (15), and Hexadecimal (F) can be read from right to left to understand the processor cores expected to be used by the process, on which the affinity was set:
|
1111 = cores 3,2,1,0 |
0011 = cores 1,0 |
0100 = core 2 |
01000010 = cores 6,1 |
The 'n' parameter is the affinity mask in hexadecimal or the decimal representation. This value specifies which of the available CPU cores will be used to run the program.
|
n (Decimal) |
n (Hexadecimal) |
Processor(s) used |
|
1 |
0x1 |
Core #0 |
|
2 |
0x2 |
Core #1 |
|
3 |
0x3 |
Cores #0 & #1 |
|
4 |
0x4 |
Core #2 |
|
8 |
0x8 |
Core #3 |
|
15 |
0xF |
Cores #0,#1, #2 & #3 |
For instance, you could create a script with the following contents to limit the cores used by the Denodo Platform to the first 4 cores:
start "" /affinity F "%%DENODO_HOME%%/bin/denodo_platform.bat"
If you want to start the Denodo Windows services with an affinity restriction, edit the file <DENODO_HOME>/conf/<product>/service.conf and set the wrapper.affinity property to the appropriate mask value. in decimal, e.g. to limit the cores used by the Denodo Platform to the first 4 cores:
wrapper.affinity=15
Linux Systems
There are two ways of limiting the CPU in Linux systems:
- Setting the CPU affinity, to indicate which CPU cores Denodo is allowed to use.
- Setting the CPU quota, to indicate the percentage of CPU that Denodo is allowed to use, that is converted to an equivalent number of CPU cores.
Setting CPU affinity
The taskset command is used to set or retrieve the CPU affinity of a running process given its PID or to launch a new command with a given CPU affinity.
The default behavior is to run a new command with a given affinity mask:
taskset [mask] [command [arguments]]
The masks are typically given in hexadecimal. For example, 0×00000001 is core #0, 0×00000003 is cores #0 and #1.
For example, if we want to launch Denodo VDP Server in CPU#0 we have to execute the following command in a terminal:
taskset 0x00000001 ./vqlserver_startup.sh &
An alternative syntax for the taskset command will be to use the “-c” option to specify a numerical list of processors. The list may contain multiple items, separated by comma, and ranges. For instance:
taskset -c 0 ./vqlserver_startup.sh &
will run the VDP server in CPU #0 and
taskset -c 0-3 ./vqlserver_startup.sh &
will run the VDP server in 4 CPUs (#0 to #3).
Setting CPU quota
The cgroups (abbreviated from control groups) are a Linux kernel feature that limits, accounts for, and isolates the resource usage (CPU, memory, disk I/O, network, etc.) of a collection of processes.
You can use cgroups to limit the number of processors available to the Denodo Platform.
To get started, you need to create a group with a subsystem and a name.
A subsystem is a computer resource that we want to control. To limit CPU the relevant subsystems are:
- cpu: Determine the proportion of CPU to use.
- cpuset: Allows you to assign memory cores and nodes to control groups.
The cpuset option is used to set the CPU affinity, and we have already covered that method in the previous section, so we will focus on the cpu subsystem, as it allows us to set a quota.
Use cgcreate to create the control group, indicating the cpu subsystem and a cpulimit name (or whatever you decide to use) for the control group with the parameter -g cpu:/cpulimit:
cgcreate -g cpu:/cpulimit
To configure the number and usage of the cores, there are two parameters:
- cpu.cfs_quota_us: the total available run-time within a period (in microseconds)
- cpu.cfs_period_us: the length of a period (in microseconds), set by default to 100ms.
So to limit the number of cores we will have to play with these two parameters.
If we want Java to report that 4 cores are available for the process, we should have a quota value that divided by the period value results in a value (value = quota/period) that is between 3 and 4 as the number of processors will be rounded to the next integer.
Example:
Limit a group to 2 CPUs worth of runtime (quota = 1000ms and period = 500ms):
cgset -r cpu.cfs_quota_us=1000000 cpulimit
cgset -r cpu.cfs_period_us=500000 cpulimit
Finally to start the VQL Server with the CPU limits that we have defined we execute the startup script with the control group created:
cgexec -g cpu:cpulimit ./vqlserver_startup.sh
Tip: The CFS period allows us to set the maximum burst time. By using a small period here we are ensuring a consistent latency response at the expense of burst capacity.
Solaris OS
Steps to modify the subset or cores associated to a process:
- Get root access to the machine
- run `mpstat` to see the processor IDs
- Use `psrset` command to create a set of processors. The command will return a set ID
- Use `psrset` command to bind the CPU set to the process
- Use `psrset` command to delete the CPU set.
Example:
$ mpstat
CPU minf mjf xcal intr ithr csw icsw migr smtx srw syscl usr sys wt idl
0 25 0 41 113 101 151 12 9 11 0 50 4 1 1 93
1 26 0 136 182 207 107 11 9 11 0 57 5 1 1 93
2 26 0 38 171 161 131 12 9 11 0 39 4 1 1 93
3 26 0 46 160 149 134 12 10 11 0 51 5 1 1 93
$ psrset -C 0 1 // to create a set, where CPU IDs came from mpstat command above
$ psrset -b 1 2325 // where 1 is the process-set ID, and 2325 is the process (e.g partition) ID.
$ psrset -d 1 // will remove the processor set
Checking affinity in Java
Using Java, it is possible to check the number of cores on which a program runs:
Runtime runtime = Runtime.getRuntime();
int num_cores = runtime.availableProcessors();
This is the functionality that the Denodo Platform uses to get the number of processors when there is a limitation on the number of processors in the installed license. The behavior of this operation is different between Windows and UNIX systems:
- On Windows the availableProcessors method returns the affinity cores assigned to the process (not total machine cores).
- On UNIX like systems the availableProcessors method will return the affinity cores assigned to the process when using a JRE version 1.8.0_121 or newer. JRE versions older than 1.8.0_121 (including the JRE 7 embedded with the Denodo Platform 6.0) will always return the total number of cores in the machine, even if they are not actually being used by any Denodo process. This means that, in order to use a Denodo License with a restriction on the maximum number of processors in Denodo 6 or previous versions using taskset, the default JRE should be changed to a JRE version 1.8.0_121 or newer.
- On Linux systems the availableProcessors method will return the equivalent number of cores assigned based on available cpu quota to the process when using a JRE version 1.8.0_191 or newer. JRE versions older than 1.8.0_191 (including the JRE8 embedded with the Denodo Platform 7.0 or the JRE 7 embedded with the Denodo Platform 6.0) will always return the total number of cores in the machine, even if they are not actually being used by any Denodo process. This means that, in order to use a Denodo License with a restriction on the maximum number of processors in older versions using cgroups, the default JRE should be changed to a JRE version 1.8.0_191 or newer.
The information provided in the Denodo Knowledge Base is intended to assist our users in advanced uses of Denodo. Please note that the results from the application of processes and configurations detailed in these documents may vary depending on your specific environment. Use them at your own discretion.
For an official guide of supported features, please refer to the User Manuals. For questions on critical systems or complex environments we recommend you to contact your Denodo Customer Success Manager.
