PDA

View Full Version : HyperVM 2.1.0 dev(beta) - how i made it to use vswap, fqdn hostnames + whmcs fix



Fli
04-16-2017, 08:56 PM
In case of HyperVM 2.1.0 dev(beta) vswap (https://openvz.org/VSwap) may be according to my opinion complicated.
HyperVM is probably outdated and not perfect.

My aim was that hypervm create openvz VPS's the way that they do not use privvmpages and instead use physpages (https://openvz.org/UBC_auxiliary_parameters#physpages) as a limit. As i seen less memory problems insside containers/VPSes when vswap/physpages was used.

So i modified the HyperVM beta php script that is responsible for sending OpenVZ commands to the server so it do not use openvz parameter "privvmpages" (i have set it to unlimited) and instead set "physpages" openvz parameter which will cause vswap be enabled.

I am attaching my modified file /usr/local/lxlabs/hypervm/httpdocs/lib/vps/driver/vps__openvzlib.phps :
340

I think these are parts of the file that i modified -->

commented out line setting privvmpages, and adding physpages that match the number of RAM megabytes set in HyperVM/Resource/Resource Plans/plan name/Burstable Memory (MB) (openvz Only)

// lxshell_return("/usr/sbin/vzctl", "set", $this->main->vpsid, "--save", "--privvmpages", $memory);
lxshell_return("/usr/sbin/vzctl", "set", $this->main->vpsid, "--save", "--privvmpages", "unlimited");
lxshell_return("/usr/sbin/vzctl", "set", $this->main->vpsid, "--save", "--physpages", "0:" . $this->main->priv->memory_usage . "M");
lxshell_return("/usr/sbin/vzctl", "set", $this->main->vpsid, "--save", "--meminfo", "pages:$memory");

so "{$this->main->priv->memory_usage}" will print number of megabytes that you set inside HyperVM/Resource/Resource Plans/plan name/Burstable Memory (MB) (openvz Only)

there commented out one line and instead added new line with proper value for physpages

lxshell_return("/usr/sbin/vzctl", "set", $this->main->vpsid, "--save", "--vmguarpages", "{$memory}M:". PHP_INT_MAX);
lxshell_return("/usr/sbin/vzctl", "set", $this->main->vpsid, "--save", "--oomguarpages", "{$memory}M:".PHP_INT_MAX);
lxshell_return("/usr/sbin/vzctl", "set", $this->main->vpsid, "--save", "--shmpages", "{$memory}M:{$memory}M");
// lxshell_return("/usr/sbin/vzctl", "set", $this->main->vpsid, "--save", "--physpages", "0:".PHP_INT_MAX);
lxshell_return("/usr/sbin/vzctl", "set", $this->main->vpsid, "--save", "--physpages", "0:{$this->main->priv->memory_usage}M");

i commented out 4 lines and added new to always use vswap (physpages), following code may not work on outdated vzkernel. i got 2.6.32-042stab093.5 and it works, all *042stab+ should work:

// Added by Semir @ 2011 march 14 function setSwapUsage()
{
if (is_unlimited($this->main->priv->swap_usage)) {
$memory = 2048;
} else {
$memory = $this->main->priv->swap_usage;
}


$memory = "0:" . $memory . "M";


lxshell_return("/usr/sbin/vzctl", "set", $this->main->vpsid, "--save", "--swappages", $memory);


// If vswap is enabled we change physpages to privvmpages
if($this->main->priv->isOn('vswap_flag'))
// multiply it with the block size
// lxshell_return("/usr/sbin/vzctl", "set", $this->main->vpsid, "--save", "--physpages", $this->main->priv->memory_usage * 256);
lxshell_return("/usr/sbin/vzctl", "set", $this->main->vpsid, "--save", "--physpages", "0:{$this->main->priv->memory_usage}M");
else
// lxshell_return("/usr/sbin/vzctl", "set", $this->main->vpsid, "--save", "--physpages", 'unlimited');
lxshell_return("/usr/sbin/vzctl", "set", $this->main->vpsid, "--save", "--physpages", "0:{$this->main->priv->memory_usage}M");
// lxshell_return("/usr/sbin/vzctl", "set", $this->main->vpsid, "--save", "--privvmpages", $memory);
// lxshell_return("/usr/sbin/vzctl", "set", $this->main->vpsid, "--save", "--privvmpages", "{$this->main->priv->memory_usage}M");

i "hardcoded" hostname with two dots as some control panels require it and i found hypervm is injecting hostname that is just a single word - vps username:

// lxshell_return("/usr/sbin/vzctl", "set", $this->main->vpsid, "--hostname", $this->main->hostname, "--save");
lxshell_return("/usr/sbin/vzctl", "set", $this->main->vpsid, "--hostname", "{$this->main->hostname}.host.name", "--save");

removed/commented out restart confirmation a it seems that this function is not compatible with WHMCS/HyperVM beta and VPS restart from WHMCS module does not work when this function is in place/not commented out like i did it:

/*if (!$this->main->isOn('reboot_confirm_f')) { throw new lxException("need_confirm_reboot", 'reboot_confirm_f');
}*/

---------
So in short, above mentioned file with above mentioned modifications making sure that when i create an OpenVZ VPS from within HyperVM 2.1.0 dev (beta), the VPS will be vSWAP (https://openvz.org/VSwap) enabled meaning it will not use privvmpages, but instead use physpages.

To set physpages (https://openvz.org/UBC_auxiliary_parameters#physpages), edit appropriate Resource Plan in HyperVM, update variable "Burstable Memory (MB)(openvz Only)". Do not set it to unlimited or zero!!!! as maybe you would assign unlimited ram to a VPS and that probably will cause instability (according to my amateur oppinion).

Beside "Burstable Memory (MB)(openvz Only)"/physpages there is also other variable in HyperVM Rersource plans, it is "Guaranteed Memory (MB)(openvz Only)". Guaranteed Memory variable will set the OpenVZ parameter "shmpages", for simplicity i set both parameters same in HyperVM.

NOTE: When you edit some parameter in HyperVM's Resource Plan, then it will modify existing, running VPS's.

You can verify that by command: vzubc CTID

Example output:

# vzubc 3620----------------------------------------------------------------
CT 3620 | HELD Bar% Lim%| MAXH Bar% Lim%| BAR | LIM | FAIL
-------------+---------------+---------------+-----+-----+------
kmemsize| 21M 1% 1%|62.6M 3% 3%| 2G| 2G| -
lockedpages| - - - |1.99M 10% 10%|19.5M|19.5M| -
shmpages| 604K 0.1% 0.1%| 512M 65% 65%| 788M| 788M| -
numproc| 212 4% 4%| 324 6% 6%|4.88K|4.88K| -
physpages| 277M - 34%| 768M - 96%| - | 798M| -
vmguarpages| - - - | - - - | 788M| - | -
oomguarpages| 146M 18% - | 262M 33% - | 788M| - | -
numtcpsock| 23 0.1% 0.1%| 53 0.1% 0.1%|39.1K|39.1K| -
numflock| 25 0.5% 0.5%| 62 1% 1%|4.88K|4.88K| -
numpty| - - - | 2 0.1% 0.1%|2.44K|2.44K| -
numsiginfo| 1 - - | 84 2% 2%|4.88K|4.88K| -
tcpsndbuf| 391K 0.2% 0.1%|1.27M 0.8% 0.4%| 157M| 313M| -
tcprcvbuf| 368K 0.2% 0.1%|16.4M 10% 5%| 157M| 313M| -
othersockbuf| 101K 0.1% - | 224K 0.1% 0.1%| 157M| 313M| -
dgramrcvbuf| - - - | 238K 0.1% 0.1%| 157M| 313M| -
numothersock| 77 0.2% 0.2%| 92 0.2% 0.2%|39.1K|39.1K| -
dcachesize| 6.5M 14% 14%|43.9M 100% 100%|43.9M|43.9M| -
numfile|1.48K 1% 1%|2.41K 2% 2%| 117K| 117K| -
numiptent| 27 0.5% 0.5%| 27 0.5% 0.5%|4.88K|4.88K| -
swappages| 14M - 5%| 187M - 73%| - | 256M| -
----------------------------------------------------------------

i set in HyperVM Resource plan this:
Burstable Memory (MB): 798
Guaranteed Memory (MB): 788