Of Spice and KVM 1

Posted by JD 01/12/2013 at 20:00

Whatever we ain’t got, that’s what you want.

- Steinbeck

About a year ago, I learned of Spice. No, not spices, but Spice, the remote desktop protocol with tools for Windows and Linux desktops. It was promising. The goal of the project is near-native video streaming performance with perfect audio. They intend to make virtual desktops viable for large enterprise customers. Since then, I’ve dreamed about it working. Last week, this dream took a step towards reality.

Spice is a relatively new extremely high-performance remote desktop tool. In my first few attempts, it never worked, so I gave up. Other priorities, you know.

Last night, I gave a Presentation on VirtualBox Performance at the local LUG. During the talk, we discussed virtualization performance. Desktop integration always comes up since most of the folks in my arm of the LUG are interested in desktops (though we do have some purely enterprise guys too). Between KVM and VirtualBox, the desktop integration has always worked great on VBox, provided you didn’t want remote desktops and were not running on a server. Basically It is hard to get video streaming working over a network when more than just the video is being streamed. For many years, KVM’s integration was only through VNC, which is fine if you must have a GUI, but not something to use for gaming or videos or audio. None of those work well. Spice is a step forward.

Spice

The virt-manager tool running on Ubuntu 12.04 has settings for each VM to allow the remote console with a GUI. For servers, I usually just use ssh – actually for desktops too, but sometimes we all screw up our VM networking or accidentally create a little too aggressive firewall rule that blocks internal LAN traffic and a console is necessary. Spice wants to be that answer.

Spice Setup

I’m not positive what the total setup for spice is, since the KVM server (hostOS) is months old and I can’t remember everything that I installed during prior attempts, however, these packages are currently installed according to dpkg.

$ dpkg \-l | grep ‘spice|qxl’
ii libspice-server1 0.10.0-1 Implements the server side of the SPICE protocol
ii qemu-kvm-spice 1.0.50-2012.03-0ubuntu2.1 Full virtualization on amd64 hardware
ii spice-vdagent 0.8.1-1 Spice agent for Linux
ii xserver-xorg-video-qxl 0.0.16-2 X.Org X server — QXL display driver

Again, those are on the KVM host. Nothing was installed inside any KVM clientOS (the virtual machine) at all.
On the client PC … in my case it is running Win7 x64 Home, I just downloaded the remote-viewer binary installer from spice-space.org/download.html, Nothing else. There are clients for Linux too, but I didn’t try them or any of the other client side libraries.

Lastly, the virtual machine settings inside KVM needed to be tweaked to support Spice and audio. Steps where:

  1. shutdown the VM – modifying running VMs is a hassle and we need to reboot for new settings anyway.
  2. remove the VNC server from the VM settings (do not know if this is mandatory or not)
  3. add HW – Graphics – Spice server;
    • check listen on all public network xfaces
    • force the ports to something I know that is unused (this is a hostOS port)
    • set a trivial password – the hostOS is not accessible from outside the LAN – both a hardware firewall and local firewall prevent that.
  4. add HW – Sound – ac97
  5. add HW – Video – qxl

Start up the VM and look for any errors. There shouldn’t be any errors or warnings shown. We cannot connect to the desktop through virt-manager, at least not through my setup. Now I went back to Windows and run the virt viewer program. On my machine it is here:
D:\Users\john\AppData\Local\virt-viewer\bin\remote-viewer.exe

The simple GUI only asked for a URL. Huh? I wonder what it could want. I tried: spice://kvm-server:port/ and it worked. I was soon staring at a Ubuntu login. Since I normally use LXDE, that was the login screen and my default DE. It came up quickly. Mouse and keyboard integration seemed fine.

The 1024×768 resolution was not impressing me on the 24" monitor where this was running. xrandr —screen 0 -s 1680×1050 fixed that. Be certain that you check which modes are available for your specific VM first.

Sure, remote desktops are great, but they’ve all lacked good audio and video support. How does Spice compare in these areas?

Audio and Video

On to the real testing.

  • Audio
  • Vidio

The KVM HostOS is running on a Core2Xtreme with 8GB of RAM and a Raptor HDD. There are 8 VMs running on this same box.
The KVM ClientOS (VM) was given 1GB of RAM, 1 vCPU, and uses virtIO for network and disk access. These are faster than 1000base-tx and sata controllers.
The Client machine is a Core i5 with lots-o-RAM and a wired GigE network connection. File transfers routinely see 650Mbps throughput.
The network is all CAT6 connected through a GigE un-managed switch. The network will not be the bottle neck, if there is one at all.

$ mplayer /path/to/some/audio.mp3
This worked perfectly, just as expected.
$ audacious /path/to/some/audio.mp3
This worked perfectly, just as expected.

Ok, so audio works. Next try some video testing.

  • local video
  • full screen video
  • HiDef video
  • Web/Flash video

Using mplayer is simple and to the point. (VLC* is another option and for the web browsing, I’ll use Firefox with the Adobe (yuck) Flash plugin enabled for youtube.

mplayer with a local file on the same VM – it streamed the video and audio fairly nicely, but without the mouse moving inside the window, the video stopped updating. The same happened when the same video was played full-screen. Not a viable option. for watching movies or TV, IMHO.

Because this VM is a small desktop just meant for checking email and surfing when I’m traveling, it doesn’t have much storage allocated or connected. I had to edit a HiDef 1080p mpeg2 video file down in order to move it local for playback. The results were less than … ok, the result were just bad. Initially, the playback filled the entire screen – 1080p in a 1050 screen – that makes perfect sense, but the video couldn’t keep up with the screen. mplayer to the rescue. Added the framedrop option, that should help, right? It helped a little, but not enough. The frames were probably being displayed about 10fps, but the audio was automatically slowed to keep up. Perhaps if I transcode the mpeg2 video into h.264? That would make it a CPU issue, not I/O, right? Nope. Test with about 10 different mplayer video output filters – all still needed the mouse to move, but some of those only updated 20% of the screen. Interesting.

VLC – I tested the same video files with VLC while waiting for the transcode to happen. Just loading the 1080p file appeared to lock up the entire VM. Switching back to the terminal that VLC was started in, pulse audio output error was seen. Loading up the non-HiDef video got further, but it had some strange results. Vertically, the video was split into 5 zones by VLC. Whichever zone the mouse was in got updated, but the other 4 zones were not. For the evening news show with a guy behind a desk talking, that would be fine, but not for any other purpose. It was odd. I’d never seen anything like that before. The part of the playback that was working was perfectly synched with the audio.

The transcode completed. It also scaled the resolution down to 720p (my default). In VLC, the video never changed. Not 1 frame. The audio playback was perfect. The vlc process locked up and a VM reboot was needed to clean up.
In mplayer, there was a warning that your system is too SLOW to play this file. Guess that is what happens in a VM with 8 other active VMs running on the same Core2Duo system. Framedrop and force X11 as the output device helped, a little, but video and audo were terribly out of sync. The video still stopped changing unless the mouse was moving inside the same window. Multiple video-out devices were tried again – about 10. The gl2 device provided the best results.

Youtube

Firefox was started, javascript was allowed from Youtube and a few videos were watched. Frames were definitely dropped, even with 360 resolution videos. HiDef videos were painful to watch. Audio was fine. Switching between an xterm and firefox using {alt}-{tab} had multi-second delays. Unacceptable.

Copy/Paste using X/Windows

This worked perfectly inside the VM, but I’ve become used to copy/paste working between windows on the client machine. Copying between an xterm and Notepad, for example. This did not work with Spice. There is probably a client-side adapter to be installed to better integrate these sorts of tasks.

As most of you know, X/Windows has a copy buffer built in. If you select any text in any X/Windows program, it is automatically added to the buffer. Sadly, many DEs also provide a clipboard, so programs get confused which buffer to copy into and which buffer to paste from. It is complex and I can see where a nice system-wide clipboard can be handy for some people even if 99.99999% of the time, only the last item copied will need to be pasted. BTW, Mozilla seemed to be the worst offenders from my perspective. Let me use the X/Buffer dammit!

Final Decision

you can’t always get what want, but it turns out, if you try sometimes, you get what you need.

- Philosopher Jagger

Spice is not ready for use as a general purpose remote desktop solution if you expect video playback. Audio playback was perfect, even if the screen updates were slightly ahead of the actual audio heard. That is very acceptable.

Mouse clicking and even window displays were slightly delayed. It was very noticeable. I did not attempt any encryted connections, but there appears to be support for those.

I plan to stay with NX for the time being.

Perhaps some configuration and tuning could make the experience better? I don’t know.

Do you use Spice? Any tips?

  1. Walt 03/23/2013 at 22:12

    It was probably 3 years ago, at this point, I had the opportunity to take the RedHat Enterprise Virtualization RHEVCA certification course offered by RedHat. As you likely know KVM is technically owned by Redhat and what was in the works when they bought the company doing KVM was, what was later named, Spice. Since RHEV is competing with VMWare it clearly had to do Windows virtualization on a par with what VMWare could do. KVM may actually be equal to or superior to VMWare but desktop virtualization, KVM sucked. The next to the last section of the week course was Spice. Granted, we didn’t do anything beyond having an XP window full screen and responsive but it was clearly that. I was surprised and disappointed it took as long as it did to get Spice nicely integrated into KVM in other than a RHEL 5 or 6 image. The main thing I like is vm screen resolution is now very high res, which might explain delay, vs. running in a lower res but still be full screen and have the mouse and mouse icon stay in sync. Another thought that just occurred to me is I am running this on a Dell XPS 15z running Ubuntu 12.10, which already has an NVidia issue. Has anyone tried it in Fedora and/or on a GPU that Linux could control?