<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 2, 2017 at 4:07 PM, Peter Krempa <span dir="ltr"><<a href="mailto:pkrempa@redhat.com" target="_blank">pkrempa@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Tue, May 02, 2017 at 16:01:40 +0530, Prerna wrote:<br>
<br>
[please don't top-post on technical lists]<br>
<span class=""><br>
> Thanks for the quick response Peter !<br>
> This ratifies the basic approach I had in mind.<br>
> It needs some (not-so-small) cleanup of the qemu driver code, and I have<br>
> already started cleaning up some of it. I am planning to have a constant<br>
> number of event handler threads to start with. I'll try adding this as a<br>
> configurable parameter in qemu.conf once basic functionality is completed.<br>
<br>
</span>That is wrong, since you can't guarantee that it will not lock up. Since<br>
the workers handling monitor events tend to call monitor commands<br>
themselves it's possible that it will get stuck due to unresponsive<br>
qemu. Without having a worst-case-scenario of a thread per VM you can't<br>
guarantee that the pool won't be depleted.<br></blockquote><div><br></div><div>Once a worker thread "picks" an event, it will contend on the per-VM lock for that VM. Consequently, the handling for that event will be delayed until an existing RPC call for that VM completes.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
If you want to fix this properly, you'll need a dynamic pool.<br></blockquote><div><br></div><div>To improve the efficiency of the thread pool, we can try contending for a VM's lock for a specific time, say, N seconds, and then relinquish the lock. The same thread in the pool can then move on to process events of the next VM.</div><div><br></div><div>Note that this needs all VMs to be hashed to a constant number of threads in the pool, say 5. This ensures that each worker thread has a unique , non-overlapping set of VMs to work with.</div><div><br></div><div>As an example,  {VM_ID: 1, 6,11,16,21 ..} are handled by the same worker thread. If this particular worker thread cannot find the requisite VM's lock, it will move on to the event list for the next VM and so on. The use of pthread_trylock() ensures that the worker thread will never be stuck forever.</div><div><br></div><div> </div></div><br></div></div>