From c59800edbec84376e83f21bc9ae8d779e26e13a6 Mon Sep 17 00:00:00 2001 From: Mikhail Durnosvistov Date: Wed, 7 May 2014 14:20:17 +0300 Subject: [PATCH] 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 --- ironic/common/glance_service/base_image_service.py | 14 +++++--------- requirements.txt | 1 + 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/ironic/common/glance_service/base_image_service.py b/ironic/common/glance_service/base_image_service.py index 88de587674..a3d118ddcb 100644 --- a/ironic/common/glance_service/base_image_service.py +++ b/ironic/common/glance_service/base_image_service.py @@ -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) diff --git a/requirements.txt b/requirements.txt index 1651c3ff95..5d9fb9e601 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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