Using system call for downloading files

Using system call `sendfile` for downloading files using glance
image service. It's more efficient than passing the entire image
through Python `shutil`.

Change-Id: Ic36c593538fd97d3ac02d3ad77feebcfdb9f1868
Closes-Bug: #1199522
This commit is contained in:
Mikhail Durnosvistov 2014-05-07 14:20:17 +03:00
parent 3ee46a8e32
commit c59800edbe
2 changed files with 6 additions and 9 deletions

View File

@ -17,10 +17,12 @@
import functools
import logging
import shutil
import os
import sys
import time
import sendfile
from glanceclient import client
import six.moves.urllib.parse as urlparse
@ -209,14 +211,8 @@ class BaseImageService(object):
url = urlparse.urlparse(location)
if url.scheme == "file":
with open(url.path, "r") as f:
#TODO(ghe): Use system call for downloading files.
# Bug #1199522
# FIXME(jbresnah) a system call to cp could have
# significant performance advantages, however we
# do not have the path to files at this point in
# the abstraction.
shutil.copyfileobj(f, data)
filesize = os.path.getsize(f.name)
sendfile.sendfile(data.fileno(), f.fileno(), 0, filesize)
return
image_chunks = self.call(method, image_id)

View File

@ -19,6 +19,7 @@ python-neutronclient>=2.3.4,<3
python-glanceclient>=0.9.0
python-keystoneclient>=0.8.0
stevedore>=0.14
pysendfile==2.0.0
websockify>=0.5.1,<0.6
oslo.config>=1.2.0
oslo.rootwrap