Michael Kublin has uploaded a new change for review.

Change subject: engine: Fixing perfromance issue between VdsRunTimeInfo and 
RunVmCommandBase
......................................................................

engine: Fixing perfromance issue between VdsRunTimeInfo and RunVmCommandBase

After introducing atomic update, no need for special lock inside of
RunVmCommandBase.decreasePendingVms()
In order to keep funcytionality for delay: SynchronousQueue will be used.
The thread will stuck untill time out or some other thread will add some object 
to queue

Change-Id: Ia6c6e26c79dc6c06c9621e1938ecd034e9ce7ec7
Signed-off-by: Michael Kublin <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsMonitor.java
2 files changed, 20 insertions(+), 48 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/40/13740/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java
index dc0587c..2ffa2a3 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java
@@ -7,10 +7,8 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.Lock;
-
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.bll.job.ExecutionContext;
 import org.ovirt.engine.core.bll.job.ExecutionContext.ExecutionMethod;
@@ -323,21 +321,15 @@
     }
 
     protected void decreasePendingVms(Guid vdsId) {
-        getDecreaseLock(vdsId).lock();
-        try {
-            DbFacade.getInstance()
-                    .getVdsDynamicDao()
-                    .updatePartialVdsDynamicCalc(vdsId, 0, 
-getVm().getNumOfCpus(), -getVm().getMinAllocatedMem(), 0, 0);
+        DbFacade.getInstance()
+                .getVdsDynamicDao()
+                .updatePartialVdsDynamicCalc(vdsId, 0, 
-getVm().getNumOfCpus(), -getVm().getMinAllocatedMem(), 0, 0);
 
-            if (log.isDebugEnabled()) {
-                log.debugFormat("DecreasePendingVms::Decreasing vds {0} 
pending vcpu count, in {1}. Vm: {2}",
-                        vdsId, getVm().getNumOfCpus(), getVm().getName());
-                log.debugFormat("DecreasePendingVms::Decreasing vds {0} 
pending vmem size, in {1}. Vm: {2}",
-                        vdsId, getVm().getMinAllocatedMem(), 
getVm().getName());
-            }
-            getDecreseCondition(vdsId).signal();
-        } finally {
-            getDecreaseLock(vdsId).unlock();
+        if (log.isDebugEnabled()) {
+            log.debugFormat("DecreasePendingVms::Decreasing vds {0} pending 
vcpu count, in {1}. Vm: {2}",
+                    vdsId, getVm().getNumOfCpus(), getVm().getName());
+            log.debugFormat("DecreasePendingVms::Decreasing vds {0} pending 
vmem size, in {1}. Vm: {2}",
+                    vdsId, getVm().getMinAllocatedMem(), getVm().getName());
         }
     }
 
@@ -351,30 +343,23 @@
     public void delay(Guid vdsId) {
         log.debug("try to wait for te engine update the host memory and cpu 
stats");
 
-        getDecreaseLock(vdsId).lock();
         try {
             // time out waiting for an update is the highest between the 
refresh rate and the last update elapsed time
             // but still no higher than a configurable max to prevent very 
long updates to stall command.
-            long t =   Math.max(
+            long t = Math.max(
                     
ResourceManager.getInstance().GetVdsManager(vdsId).getLastUpdateElapsed(),
                     TimeUnit.SECONDS.toMillis(Config.<Integer> 
GetValue(VdsRefreshRate)));
             t = Math.max(Config.<Integer> 
GetValue(ConfigValues.ThrottlerMaxWaitForVdsUpdateInMillis), t);
 
             // wait for the run-time refresh to decrease any current 
powering-up VMs
-            getDecreseCondition(vdsId).await(t, TimeUnit.MILLISECONDS);
+            getBlockingQueue(vdsId).poll(t, TimeUnit.MILLISECONDS);
         } catch (InterruptedException e) {
             // ignore
-        } finally {
-            getDecreaseLock(vdsId).unlock();
         }
     }
 
-    private Condition getDecreseCondition(Guid vdsId) {
-        return getMonitor(vdsId).getDecreasedMemoryCondition();
-    }
-
-    private Lock getDecreaseLock(Guid vdsId) {
-        return getMonitor(vdsId).getLock();
+    private BlockingQueue<Boolean> getBlockingQueue(Guid vdsId) {
+        return getMonitor(vdsId).getQueue();
     }
 
     /**
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsMonitor.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsMonitor.java
index 2825aec..959d88a 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsMonitor.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsMonitor.java
@@ -1,35 +1,22 @@
 package org.ovirt.engine.core.vdsbroker;
 
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.SynchronousQueue;
 
 public class VdsMonitor {
 
-    private final Lock lock;
-    private final Condition decreasedMemoryCondition;
+    private final BlockingQueue<Boolean> queue;
 
     public VdsMonitor() {
-        lock = new ReentrantLock();
-        decreasedMemoryCondition = getLock().newCondition();
+        queue = new SynchronousQueue<Boolean>();
     }
 
     /**
-     * A lock for the enclosing VDS
+     * A synchronous queue for the enclosing VDS
      *
      * @return
      */
-    public Lock getLock() {
-        return lock;
+    public BlockingQueue<Boolean> getQueue() {
+        return queue;
     }
-
-    /**
-     * a signal condition to communicate updates the decreased amount of 
memory this vds reserevs for scheduling a VM
-     *
-     * @return
-     */
-    public Condition getDecreasedMemoryCondition() {
-        return decreasedMemoryCondition;
-    }
-
 }


--
To view, visit http://gerrit.ovirt.org/13740
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia6c6e26c79dc6c06c9621e1938ecd034e9ce7ec7
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Michael Kublin <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to