<br><font size=2 face="sans-serif">Hi all,</font>
<br><font size=2 face="sans-serif">I know that this is not a libvirt issue but this badly impacts libvirt usage.</font>
<br><font size=2 face="sans-serif">Is anyone aware of any status on this issue ? Daniel ?</font>
<br>
<br><font size=2 face="sans-serif">Here is some history I could get from the libvirt mailing list :</font>
<br>
<br><font size=2 face="sans-serif">* October 12, 2006 (Daniel Berrange).</font>
<br><font size=2 face="sans-serif">I've been trying to track down just why talking to XenD is resulting in so much CPU time being</font>
<br><font size=2 face="sans-serif">comsumed by both xend & xenstored. As a test case, I'm running 'virsh dominfo demo' which results in</font>
<br><font size=2 face="sans-serif">a single HTTP request to Xend to fetch domain info, eg 'GET /xend/domains/demo'</font>
<br><font size=2 face="sans-serif">Run this in a tight loop & I'll see xenstored taking > 50% CPU, and XenD taking another 11%</font>
<br><font size=2 face="sans-serif">PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND</font>
<br><font size=2 face="sans-serif">2647 root 16 0 6188 840 464 R 52 0.0 0:55.04 xenstored</font>
<br><font size=2 face="sans-serif">11600 root 18 0 259m 7568 1516 S 11 0.2 0:04.53 python</font>
<br><font size=2 face="sans-serif">Its not surprising that xend is consuming time since we are making many requests per second, but for</font>
<br><font size=2 face="sans-serif">an operation which is only doing reads it having so much time attributed to xenstored seems very</font>
<br><font size=2 face="sans-serif">excessive. So I ran oprofile & collected some data about xenstored:</font>
<br><font size=2 face="sans-serif">CPU: AMD64 processors, speed 2211.33 MHz (estimated)</font>
<br><font size=2 face="sans-serif">Counted CPU_CLK_UNHALTED events (Cycles outside of halt state) with a unit mask of 0x00 (No</font>
<br><font size=2 face="sans-serif">unit mask) count 100000</font>
<br><font size=2 face="sans-serif">samples % image name symbol name</font>
<br><font size=2 face="sans-serif">347226 45.9445 ext3 (no symbols)</font>
<br><font size=2 face="sans-serif">264664 35.0200 jbd (no symbols)</font>
<br><font size=2 face="sans-serif">31778 4.2048 libc-2.5.so memset</font>
<br><font size=2 face="sans-serif">10763 1.4241 xenstored main</font>
<br><font size=2 face="sans-serif">8884 1.1755 libc-2.5.so _int_malloc</font>
<br><font size=2 face="sans-serif">7053 0.9332 libc-2.5.so vfprintf</font>
<br><font size=2 face="sans-serif">4264 0.5642 xenstored initialize_set</font>
<br><font size=2 face="sans-serif">So almost 80% of xenstored's CPU time is attributed to ext3 & journalling modules, suggesting</font>
<br><font size=2 face="sans-serif">xenstored is doing alot of disk I/O. strace()'ing the xenstored process shows the only file it is opening</font>
<br><font size=2 face="sans-serif">is:</font>
<br><font size=2 face="sans-serif"># strace -p 2647 -e trace=open,rename,unlink</font>
<br><font size=2 face="sans-serif">Process 2647 attached - interrupt to quit</font>
<br><font size=2 face="sans-serif">open("/var/lib/xenstored/tdb.0x62aa80", O_WRONLY|O_CREAT|O_TRUNC, 0640) = 13</font>
<br><font size=2 face="sans-serif">open("/var/lib/xenstored/tdb.0x62aa80", O_RDWR) = 15</font>
<br><font size=2 face="sans-serif">rename("/var/lib/xenstored/tdb.0x62aa80", "/var/lib/xenstored/tdb") = 0</font>
<br><font size=2 face="sans-serif">unlink("/var/lib/xenstored/tdb.0x62aa80") = -1 ENOENT (No such file or directory)</font>
<br><font size=2 face="sans-serif">open("/var/lib/xenstored/tdb.0x62b2b0", O_WRONLY|O_CREAT|O_TRUNC, 0640) = 13</font>
<br><font size=2 face="sans-serif">open("/var/lib/xenstored/tdb.0x62b2b0", O_RDWR) = 14</font>
<br><font size=2 face="sans-serif">rename("/var/lib/xenstored/tdb.0x62b2b0", "/var/lib/xenstored/tdb") = 0</font>
<br><font size=2 face="sans-serif">unlink("/var/lib/xenstored/tdb.0x62b2b0") = -1 ENOENT (No such file or directory)</font>
<br><font size=2 face="sans-serif">...</font>
<br><font size=2 face="sans-serif">So basically it is repeatedly copying its persistent TBD database over and over again. The TDB on this</font>
<br><font size=2 face="sans-serif">system is 128 KB in size and each individual HTTP GET on /xend/domain/demo is resulting in 16</font>
<br><font size=2 face="sans-serif">copies being made.</font>
<br><font size=2 face="sans-serif">Do the maths - 128 * 16 == 2 MB of reads, and 2 MB of writes - for a single read in XenD. Now if I</font>
<br><font size=2 face="sans-serif">monitor the status of 20 domains, once per second that's causing 40 MB of writes & 40 MB of reads</font>
<br><font size=2 face="sans-serif">every second which is utterly ridiculous & completely non scalable for enterprise deployment :-(</font>
<br><font size=2 face="sans-serif">There's two problems I see here:</font>
<br><font size=2 face="sans-serif">1. Why the need for xenstored to be doing any of this I/O in the first place?</font>
<br><font size=2 face="sans-serif">If the DB needs to be kept on disk at all, it really needs to have a much saner update/transactional</font>
<br><font size=2 face="sans-serif">model to only update bits which actually change, rather than re-creating the entire DB on every</font>
<br><font size=2 face="sans-serif">transaction. But it strikes me that the DB could potentially be kept entirely in memory removing the</font>
<br><font size=2 face="sans-serif">disk I/O completely. Sure yyou wouldn't be able to restart the daemon then, but even today you can't</font>
<br><font size=2 face="sans-serif">restart xenstored & expect things to still be working.</font>
<br><font size=2 face="sans-serif">2. Why does XenD create sooo many transactions in XenStored for a read op ?</font>
<br><font size=2 face="sans-serif">Having instrumented Xend it sems that the root cause of the problem is the</font>
<br><font size=2 face="sans-serif">xen.xend.xenstore.xstransact class. This alllows one to start a transaction, do a bunch of</font>
<br><font size=2 face="sans-serif">reads/writes & then commit the transaction. At the same time though it has a bunch of static</font>
<br><font size=2 face="sans-serif">'convenience' methods for read & write which will implicitly start & commit a transaction. Well</font>
<br><font size=2 face="sans-serif">90% of the code in XenD seems to be using these 'convenience' methods instead of explicitly</font>
<br><font size=2 face="sans-serif">starting a transaction to cover a piece of work - the result is a simple GET causes 16 transactions</font>
<br><font size=2 face="sans-serif">....and an 'xm create' results in 80 transactions. These convenience methods are utterly destroying</font>
<br><font size=2 face="sans-serif">performance.</font>
<br><font size=2 face="sans-serif">Clearly we can't address these for 3.0.3, but I think both of these areas need serious work in 3.0.4 if we</font>
<br><font size=2 face="sans-serif">want a scalable control plane in Dom0. Fixing the XenD bit looks particularly hard because any single</font>
<br><font size=2 face="sans-serif">method using the convenience xenstored read functions can be called under many different contexts, so</font>
<br><font size=2 face="sans-serif">of which needs transactions, others which don't. It ought to be possible to trace back all the calls &</font>
<br><font size=2 face="sans-serif">make it possible to pass explicit xstransct objects into all calls & then kill off the convenience methods.</font>
<br>
<br><font size=2 face="sans-serif">* Answer, same day (October 12, 2006)</font>
<br>
<br><font size=2 face="sans-serif">Yes, xenstored is very simple minded in many respects. We will certainly be improving this during</font>
<br><font size=2 face="sans-serif">3.0.4 development -- I think we can get the costs down very significantly for commonplace operations</font>
<br><font size=2 face="sans-serif">without enormous effort.</font>
<br>
<br><font size=2 face="sans-serif">* Avril 25, 2007 (Daniel Berrange)</font>
<br>
<br><font size=2 face="sans-serif">> Xen 3.0.3 has a serious performance bug</font>
<br><font size=2 face="sans-serif">> (see http://lists.xensource.com/archives/html/xen-devel/2006-10/msg00487.html)</font>
<br><font size=2 face="sans-serif">> This bug is fixed in Xen 3.0.4</font>
<br><font size=2 face="sans-serif">No it isn't. The performance bug is actually at least x2 worse in Xen 3.0.4</font>
<br>