<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 2, 2017 at 4:27 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"><span class="">On Tue, May 02, 2017 at 16:16:39 +0530, Prerna wrote:<br>
> On Tue, May 2, 2017 at 4:07 PM, Peter Krempa <<a href="mailto:pkrempa@redhat.com">pkrempa@redhat.com</a>> wrote:<br>
><br>
> > On Tue, May 02, 2017 at 16:01:40 +0530, Prerna wrote:<br>
> ><br>
> > [please don't top-post on technical lists]<br>
> ><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<br>
> > completed.<br>
> ><br>
> > 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>
> ><br>
><br>
> Once a worker thread "picks" an event, it will contend on the per-VM lock<br>
> for that VM. Consequently, the handling for that event will be delayed<br>
> until an existing RPC call for that VM completes.<br>
><br>
><br>
> ><br>
> > If you want to fix this properly, you'll need a dynamic pool.<br>
> ><br>
><br>
> To improve the efficiency of the thread pool, we can try contending for a<br>
> VM's lock for a specific time, say, N seconds, and then relinquish the<br>
> lock. The same thread in the pool can then move on to process events of the<br>
> next VM.<br>
<br>
</span>This would unnecessarily delay events which are not locked.<br>
<span class=""><br>
> Note that this needs all VMs to be hashed to a constant number of threads<br>
> in the pool, say 5. This ensures that each worker thread has a unique ,<br>
> non-overlapping set of VMs to work with.<br>
<br>
</span>How would this help?<br>
<span class=""><br>
> As an example,  {VM_ID: 1, 6,11,16,21 ..} are handled by the same worker<br>
> thread. If this particular worker thread cannot find the requisite VM's<br>
> lock, it will move on to the event list for the next VM and so on. The use<br>
> of pthread_trylock() ensures that the worker thread will never be stuck<br>
> forever.<br>
<br>
</span>No, I think this isn't the right approach at all. You could end up<br>
having all VM's handled with one thread, with others being idle. I think<br>
the right approach will be to have a dynamic pool, which will handle<br>
incomming events. In case when two events for a single VM should be<br>
handled in parallel, the same thread should pick them up in order they<br>
arrived. In that way, you will have at most a thread per VM, while<br>
normally you will have only one.<br>
</blockquote></div><br></div><div class="gmail_extra">I agree that dynamic threadpool is helpful when there are events from distinct VMs that need to be processed at the same time. </div><div class="gmail_extra">But I am also concerned about efficiently using the threads in this pool. If we have a few threads only contend on per-VM locks until the RPCs for that VM complete, it is not a very efficient use of resources. I would rather have this thread drop handling of this VM's events and do something useful while it is unable to grab this VM's lock. </div><div class="gmail_extra">This is the reason I wanted to load-balance incoming events by VM IDs and hash them onto distinct threads. The idea was that a pthread always has something else to take up if the current Vm's lock is not available. Would you have some suggestions on improving the efficacy of the thread pool as a whole ?<br></div></div>