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,31 +88,16 @@ public class ClusterAlertAdapter implements AlertAdapter {
|
|||||||
|
|
||||||
for (ManagementServerHostVO mshost : args.getLeftNodes()) {
|
for (ManagementServerHostVO mshost : args.getLeftNodes()) {
|
||||||
if (mshost.getId() != args.getSelf().longValue()) {
|
if (mshost.getId() != args.getSelf().longValue()) {
|
||||||
GlobalLock lock = GlobalLock.getInternLock("ManagementAlert." + mshost.getId());
|
if(_mshostDao.increaseAlertCount(mshost.getId()) > 0) {
|
||||||
try {
|
|
||||||
if (lock.lock(180)) {
|
|
||||||
try {
|
|
||||||
ManagementServerHostVO alertHost = _mshostDao.findById(mshost.getId());
|
|
||||||
if (alertHost.getAlertCount() == 0) {
|
|
||||||
_mshostDao.increaseAlertCount(mshost.getId());
|
|
||||||
|
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("Detected management server node " + mshost.getServiceIP() + " is down, send alert");
|
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", "");
|
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_MANAGMENT_NODE, 0, new Long(0), "Management server node " + mshost.getServiceIP() + " is down", "");
|
||||||
} else {
|
} else {
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("Detected management server node " + mshost.getServiceIP() + " is down, but alert has already been set");
|
s_logger.debug("Detected management server node " + mshost.getServiceIP() + " is down, but alert has already been set");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
lock.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
lock.releaseRef();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,7 @@ public interface ManagementServerHostDao extends GenericDao<ManagementServerHost
|
|||||||
boolean remove(Long id);
|
boolean remove(Long id);
|
||||||
|
|
||||||
ManagementServerHostVO findByMsid(long msid);
|
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, String name, String version, String serviceIP, int servicePort, Date lastUpdate);
|
||||||
void update(long id, long runid, Date lastUpdate);
|
void update(long id, long runid, Date lastUpdate);
|
||||||
|
|||||||
@ -167,21 +167,24 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@DB
|
@DB
|
||||||
public void increaseAlertCount(long id) {
|
public int increaseAlertCount(long id) {
|
||||||
Transaction txn = Transaction.currentTxn();
|
Transaction txn = Transaction.currentTxn();
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
|
int changedRows = 0;
|
||||||
try {
|
try {
|
||||||
txn.start();
|
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.setLong(1, id);
|
||||||
|
|
||||||
pstmt.executeUpdate();
|
changedRows = pstmt.executeUpdate();
|
||||||
txn.commit();
|
txn.commit();
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
s_logger.warn("Unexpected exception, ", e);
|
s_logger.warn("Unexpected exception, ", e);
|
||||||
txn.rollback();
|
txn.rollback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return changedRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ManagementServerHostDaoImpl() {
|
protected ManagementServerHostDaoImpl() {
|
||||||
|
|||||||
@ -52,6 +52,7 @@ public class VmwareContext {
|
|||||||
private String _serverAddress;
|
private String _serverAddress;
|
||||||
|
|
||||||
private Map<String, Object> _stockMap = new HashMap<String, Object>();
|
private Map<String, Object> _stockMap = new HashMap<String, Object>();
|
||||||
|
private int _CHUNKSIZE = 1*1024*1024; // 1M
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
@ -267,7 +268,7 @@ public class VmwareContext {
|
|||||||
|
|
||||||
InputStream in = conn.getInputStream();
|
InputStream in = conn.getInputStream();
|
||||||
OutputStream out = new FileOutputStream(new File(localFileFullName));
|
OutputStream out = new FileOutputStream(new File(localFileFullName));
|
||||||
byte[] buf = new byte[102400];
|
byte[] buf = new byte[_CHUNKSIZE];
|
||||||
int len = 0;
|
int len = 0;
|
||||||
while ((len = in.read(buf)) > 0) {
|
while ((len = in.read(buf)) > 0) {
|
||||||
out.write(buf, 0, len);
|
out.write(buf, 0, len);
|
||||||
@ -289,7 +290,7 @@ public class VmwareContext {
|
|||||||
try {
|
try {
|
||||||
out = conn.getOutputStream();
|
out = conn.getOutputStream();
|
||||||
in = new FileInputStream(localFile);
|
in = new FileInputStream(localFile);
|
||||||
byte[] buf = new byte[102400];
|
byte[] buf = new byte[_CHUNKSIZE];
|
||||||
int len = 0;
|
int len = 0;
|
||||||
while ((len = in.read(buf)) > 0) {
|
while ((len = in.read(buf)) > 0) {
|
||||||
out.write(buf, 0, len);
|
out.write(buf, 0, len);
|
||||||
@ -322,8 +323,7 @@ public class VmwareContext {
|
|||||||
conn.setDoOutput(true);
|
conn.setDoOutput(true);
|
||||||
conn.setUseCaches(false);
|
conn.setUseCaches(false);
|
||||||
|
|
||||||
int CHUCK_LEN = 64*1024;
|
conn.setChunkedStreamingMode(_CHUNKSIZE);
|
||||||
conn.setChunkedStreamingMode(CHUCK_LEN);
|
|
||||||
conn.setRequestMethod(httpMethod);
|
conn.setRequestMethod(httpMethod);
|
||||||
conn.setRequestProperty("Connection", "Keep-Alive");
|
conn.setRequestProperty("Connection", "Keep-Alive");
|
||||||
conn.setRequestProperty("Content-Type", "application/x-vnd.vmware-streamVmdk");
|
conn.setRequestProperty("Content-Type", "application/x-vnd.vmware-streamVmdk");
|
||||||
@ -336,7 +336,7 @@ public class VmwareContext {
|
|||||||
bos = new BufferedOutputStream(conn.getOutputStream());
|
bos = new BufferedOutputStream(conn.getOutputStream());
|
||||||
is = new BufferedInputStream(new FileInputStream(localFileName));
|
is = new BufferedInputStream(new FileInputStream(localFileName));
|
||||||
int bytesAvailable = is.available();
|
int bytesAvailable = is.available();
|
||||||
int bufferSize = Math.min(bytesAvailable, CHUCK_LEN);
|
int bufferSize = Math.min(bytesAvailable, _CHUNKSIZE);
|
||||||
byte[] buffer = new byte[bufferSize];
|
byte[] buffer = new byte[bufferSize];
|
||||||
while (true) {
|
while (true) {
|
||||||
int bytesRead = is.read(buffer, 0, bufferSize);
|
int bytesRead = is.read(buffer, 0, bufferSize);
|
||||||
@ -378,7 +378,7 @@ public class VmwareContext {
|
|||||||
in = conn.getInputStream();
|
in = conn.getInputStream();
|
||||||
out = new FileOutputStream(new File(localFileName));
|
out = new FileOutputStream(new File(localFileName));
|
||||||
|
|
||||||
byte[] buf = new byte[64*1024];
|
byte[] buf = new byte[_CHUNKSIZE];
|
||||||
int len = 0;
|
int len = 0;
|
||||||
while ((len = in.read(buf)) > 0) {
|
while ((len = in.read(buf)) > 0) {
|
||||||
out.write(buf, 0, len);
|
out.write(buf, 0, len);
|
||||||
@ -406,7 +406,7 @@ public class VmwareContext {
|
|||||||
InputStream in = conn.getInputStream();
|
InputStream in = conn.getInputStream();
|
||||||
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
byte[] buf = new byte[102400];
|
byte[] buf = new byte[_CHUNKSIZE];
|
||||||
int len = 0;
|
int len = 0;
|
||||||
while ((len = in.read(buf)) > 0) {
|
while ((len = in.read(buf)) > 0) {
|
||||||
out.write(buf, 0, len);
|
out.write(buf, 0, len);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user