Re: Question regaring correct usage of CPU shares

2023-05-26 Thread Martin Kletzander

On Fri, May 12, 2023 at 11:36:36AM +, mailing-libv...@posteo.de wrote:

Hi there,



Hi, sorry for the late answer.


I have a question regarding the shares option of the cputune section. I
want to illustrate my question with the following example. Let's assume
I have two virtual machines like the following on four dedicated core
with two threads each:

VM1:

 512
 
 


VM2:
cputune>
 512
 
 
 
 
 
 


Those two virtual machines I just mentioned won't interfere with one
another since they are pinned to different cores. However I introduce
another, third virtual machine, like this:

VM3:

 512
 
 
 
 
 
 
 
 


What I want is that VM1, VM2 and VM3 all receive half of the cores CPU
time if congestion appears. My question is how the shares are


That is what should, theoretically, happen, yes.  And it does not matter
if the value is 512, 7 or 2.


calculated. Are they calculated on a per core basis? Meaning VM1 and


No, they are set per-VM.


VM3 use the first core so each will get half of the cores capacity when
congestion appears, or are the shares calculated over all cores a
virtual machine uses and I need to scale the amount of shares with
increasing number of cores. What is the correct setting here so that
all virtual machines in this example are guaranteed half of the
capacity of each of their respective cores if congestion appears?



The above is okay from this point of view.  But it depends on the rest
of your system.  What scheduler you have, what are the other processes
running, etc.  You can have a look at the settings in cgroups (in v1
this is cpu.shares, in v2 I think that's cpu.weight) and see how they
are set.

Hope that helps,
Martin


signature.asc
Description: PGP signature


Re: Cron jobs not working with virsh commands

2023-05-26 Thread Daniel P . Berrangé
On Fri, May 26, 2023 at 12:30:18PM +0200, Jeff Brown wrote:
> Recently, while testing backup scripts, I happened to notice that 'virsh
> snaphot-create-as . . .' has been failing with 'error: failed to get domain
> '$DOMAIN'' when run through crontab. So I've been unwittingly backing up the
> live, running, QCOW2 images for quite some time because scripts which run
> fine when testing from CLI, fail to work as expected when run as a cron job.
> 
> After much searching, I stumbled upon a related issue with the (obvious?)
> simple solution almost hidden in the answers. You have to explicitly connect
> to the local server with, e.g.:
> 
> virsh -c qemu:///system snapshot-create-as . . .
> 
> Humble apologies if I missed something I should have been aware of, but I
> just thought it worthwhile mentioning here for anyone else searching for an
> answer in the archives.

If you don't specify a URI, then libvirt attempts to guess one based
on what's installed, what's running and what user you're running the
command as.

Assuming libvirt qemu driver is installed & running, the latter point
will be where you hit the problem

Running as 'root' libvirt defaults to qemu:///system.

Running as any non-root account, it defaults to qemu:///session

Some more info here:

  https://libvirt.org/uri.html#default-uri-choice
  https://libvirt.org/drvqemu.html#connections-to-qemu-driver

With regards,
Daniel
-- 
|: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-https://fstop138.berrange.com :|
|: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|



Cron jobs not working with virsh commands

2023-05-26 Thread Jeff Brown
Recently, while testing backup scripts, I happened to notice that 'virsh 
snaphot-create-as . . .' has been failing with 'error: failed to get 
domain '$DOMAIN'' when run through crontab. So I've been unwittingly 
backing up the live, running, QCOW2 images for quite some time because 
scripts which run fine when testing from CLI, fail to work as expected 
when run as a cron job.


After much searching, I stumbled upon a related issue with the 
(obvious?) simple solution almost hidden in the answers. You have to 
explicitly connect to the local server with, e.g.:


virsh -c qemu:///system snapshot-create-as . . .

Humble apologies if I missed something I should have been aware of, but 
I just thought it worthwhile mentioning here for anyone else searching 
for an answer in the archives.


Best regards,

Jeff