mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
1) Increase working buffer size to 1M when downloading/uploading VMDK, hopefully can improve OVF exporting/importing performance. 2) use atomic SQL operation to get rid of global lock usage
This commit is contained in:
parent
5a67bfd7f0
commit
3c41775184
@ -88,30 +88,15 @@ public class ClusterAlertAdapter implements AlertAdapter {
|
||||
|
||||
for (ManagementServerHostVO mshost : args.getLeftNodes()) {
|
||||
if (mshost.getId() != args.getSelf().longValue()) {
|
||||
GlobalLock lock = GlobalLock.getInternLock("ManagementAlert." + mshost.getId());
|
||||
try {
|
||||
if (lock.lock(180)) {
|
||||
try {
|
||||
ManagementServerHostVO alertHost = _mshostDao.findById(mshost.getId());
|
||||
if (alertHost.getAlertCount() == 0) {
|
||||
_mshostDao.increaseAlertCount(mshost.getId());
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Detected management server node " + mshost.getServiceIP() + " is down, send alert");
|
||||
}
|
||||
|
||||
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_MANAGMENT_NODE, 0, new Long(0), "Management server node " + mshost.getServiceIP() + " is down", "");
|
||||
} else {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Detected management server node " + mshost.getServiceIP() + " is down, but alert has already been set");
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
if(_mshostDao.increaseAlertCount(mshost.getId()) > 0) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Detected management server node " + mshost.getServiceIP() + " is down, send alert");
|
||||
}
|
||||
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_MANAGMENT_NODE, 0, new Long(0), "Management server node " + mshost.getServiceIP() + " is down", "");
|
||||
} else {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Detected management server node " + mshost.getServiceIP() + " is down, but alert has already been set");
|
||||
}
|
||||
} finally {
|
||||
lock.releaseRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ public interface ManagementServerHostDao extends GenericDao<ManagementServerHost
|
||||
boolean remove(Long id);
|
||||
|
||||
ManagementServerHostVO findByMsid(long msid);
|
||||
void increaseAlertCount(long id);
|
||||
int increaseAlertCount(long id);
|
||||
|
||||
void update(long id, long runid, String name, String version, String serviceIP, int servicePort, Date lastUpdate);
|
||||
void update(long id, long runid, Date lastUpdate);
|
||||
|
||||
@ -167,21 +167,24 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public void increaseAlertCount(long id) {
|
||||
public int increaseAlertCount(long id) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
PreparedStatement pstmt = null;
|
||||
PreparedStatement pstmt = null;
|
||||
int changedRows = 0;
|
||||
try {
|
||||
txn.start();
|
||||
|
||||
pstmt = txn.prepareAutoCloseStatement("update mshost set alert_count=alert_count+1 where id=?");
|
||||
pstmt = txn.prepareAutoCloseStatement("update mshost set alert_count=alert_count+1 where id=? and alert_count=0");
|
||||
pstmt.setLong(1, id);
|
||||
|
||||
pstmt.executeUpdate();
|
||||
changedRows = pstmt.executeUpdate();
|
||||
txn.commit();
|
||||
} catch(Exception e) {
|
||||
s_logger.warn("Unexpected exception, ", e);
|
||||
txn.rollback();
|
||||
}
|
||||
}
|
||||
|
||||
return changedRows;
|
||||
}
|
||||
|
||||
protected ManagementServerHostDaoImpl() {
|
||||
|
||||
@ -52,6 +52,7 @@ public class VmwareContext {
|
||||
private String _serverAddress;
|
||||
|
||||
private Map<String, Object> _stockMap = new HashMap<String, Object>();
|
||||
private int _CHUNKSIZE = 1*1024*1024; // 1M
|
||||
|
||||
static {
|
||||
try {
|
||||
@ -267,7 +268,7 @@ public class VmwareContext {
|
||||
|
||||
InputStream in = conn.getInputStream();
|
||||
OutputStream out = new FileOutputStream(new File(localFileFullName));
|
||||
byte[] buf = new byte[102400];
|
||||
byte[] buf = new byte[_CHUNKSIZE];
|
||||
int len = 0;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
@ -289,7 +290,7 @@ public class VmwareContext {
|
||||
try {
|
||||
out = conn.getOutputStream();
|
||||
in = new FileInputStream(localFile);
|
||||
byte[] buf = new byte[102400];
|
||||
byte[] buf = new byte[_CHUNKSIZE];
|
||||
int len = 0;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
@ -322,8 +323,7 @@ public class VmwareContext {
|
||||
conn.setDoOutput(true);
|
||||
conn.setUseCaches(false);
|
||||
|
||||
int CHUCK_LEN = 64*1024;
|
||||
conn.setChunkedStreamingMode(CHUCK_LEN);
|
||||
conn.setChunkedStreamingMode(_CHUNKSIZE);
|
||||
conn.setRequestMethod(httpMethod);
|
||||
conn.setRequestProperty("Connection", "Keep-Alive");
|
||||
conn.setRequestProperty("Content-Type", "application/x-vnd.vmware-streamVmdk");
|
||||
@ -336,7 +336,7 @@ public class VmwareContext {
|
||||
bos = new BufferedOutputStream(conn.getOutputStream());
|
||||
is = new BufferedInputStream(new FileInputStream(localFileName));
|
||||
int bytesAvailable = is.available();
|
||||
int bufferSize = Math.min(bytesAvailable, CHUCK_LEN);
|
||||
int bufferSize = Math.min(bytesAvailable, _CHUNKSIZE);
|
||||
byte[] buffer = new byte[bufferSize];
|
||||
while (true) {
|
||||
int bytesRead = is.read(buffer, 0, bufferSize);
|
||||
@ -378,7 +378,7 @@ public class VmwareContext {
|
||||
in = conn.getInputStream();
|
||||
out = new FileOutputStream(new File(localFileName));
|
||||
|
||||
byte[] buf = new byte[64*1024];
|
||||
byte[] buf = new byte[_CHUNKSIZE];
|
||||
int len = 0;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
@ -406,7 +406,7 @@ public class VmwareContext {
|
||||
InputStream in = conn.getInputStream();
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
byte[] buf = new byte[102400];
|
||||
byte[] buf = new byte[_CHUNKSIZE];
|
||||
int len = 0;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user