Repository: cloudstack
Updated Branches:
  refs/heads/master 9c56b3d4d -> 6de4dcb10


speed up template download: don't sync io for each write


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/6de4dcb1
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/6de4dcb1
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/6de4dcb1

Branch: refs/heads/master
Commit: 6de4dcb10a076671acc0f7486d493e914b59d1d4
Parents: 9c56b3d
Author: Edison Su <[email protected]>
Authored: Tue Sep 30 16:52:36 2014 -0700
Committer: Edison Su <[email protected]>
Committed: Tue Sep 30 16:52:36 2014 -0700

----------------------------------------------------------------------
 .../com/cloud/storage/template/HttpTemplateDownloader.java   | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6de4dcb1/core/src/com/cloud/storage/template/HttpTemplateDownloader.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/storage/template/HttpTemplateDownloader.java 
b/core/src/com/cloud/storage/template/HttpTemplateDownloader.java
index ed6c9f0..62762b9 100644
--- a/core/src/com/cloud/storage/template/HttpTemplateDownloader.java
+++ b/core/src/com/cloud/storage/template/HttpTemplateDownloader.java
@@ -26,6 +26,7 @@ import java.io.InputStream;
 import java.io.RandomAccessFile;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.net.URL;
 import java.util.Date;
 
 import org.apache.commons.httpclient.ChunkedInputStream;
@@ -233,9 +234,10 @@ public class HttpTemplateDownloader extends 
ManagedContextRunnable implements Te
                 remoteSize = maxTemplateSizeInBytes;
             }
 
-            InputStream in = !chunked ? new 
BufferedInputStream(request.getResponseBodyAsStream()) : new 
ChunkedInputStream(request.getResponseBodyAsStream());
+            URL url = new URL(getDownloadUrl());
+            InputStream in = url.openStream();
 
-            RandomAccessFile out = new RandomAccessFile(file, "rwd");
+            RandomAccessFile out = new RandomAccessFile(file, "rw");
             out.seek(localFileSize);
 
             s_logger.info("Starting download from " + getDownloadUrl() + " to 
" + toFile + " remoteSize=" + remoteSize + " , max size=" + 
maxTemplateSizeInBytes);
@@ -279,6 +281,8 @@ public class HttpTemplateDownloader extends 
ManagedContextRunnable implements Te
                     done = true;
                 }
             }
+            out.getFD().sync();
+
             Date finish = new Date();
             String downloaded = "(incomplete download)";
             if (totalBytes >= remoteSize) {

Reply via email to