dhiltgen / docker-machine-kvm

KVM driver for docker-machine
Apache License 2.0
376 stars 111 forks source link

Default domain settings lead to >25% CPU usage, fix proposed #31

Closed caiobegotti closed 7 years ago

caiobegotti commented 7 years ago

Hello! The current domain XML you are using for the KVM driver does not specify a CPU mode, which makes things very slow and usually lead to a constant >25% CPU usage for people using your driver with Kubernetes and Minikube. The proposed fix below solves this as it simply tells KVM to use everything the host supports and emulate whatever else is needed, so now your driver is at 0.0% of CPU usage and instead of being the 1st process in top it is now the 721st :-)

See http://wiki.qemu.org/Features/CPUModels#-cpu_host_and_feature_probing for more info. CPU host mode is usually safe and recommended for scenarios like the ones your driver is used for. The only limitation (which I suspect is not a big deal here) is that if you do KVM migrations between hosts of different CPUs models all the time.

diff --git a/kvm.go b/kvm.go
index f843ad0..7a1a9e2 100644
--- a/kvm.go
+++ b/kvm.go
@@ -35,6 +35,7 @@ const (
   <name>{{.MachineName}}</name> <memory unit='M'>{{.Memory}}</memory>
   <vcpu>{{.CPU}}</vcpu>
   <features><acpi/><apic/><pae/></features>
+  <cpu mode='host-passthrough'></cpu>
   <os>
     <type>hvm</type>
     <boot dev='cdrom'/>

If you are still suspicious about the fix, accepting a CPU mode via an option/parameter would solve it for people having performance issues with your driver, I think.

dhiltgen commented 7 years ago

Seems like a good improvement. Do you mind submitting a PR for this?

caiobegotti commented 7 years ago

Not at all, I filed a bug instead to leave the discussion open about it. Will submit it in a moment :-)