You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by pquentin <gi...@git.apache.org> on 2017/10/16 11:10:26 UTC
[GitHub] libcloud pull request #1132: Ensure RawResponse downloads don't consume RAM
GitHub user pquentin opened a pull request:
https://github.com/apache/libcloud/pull/1132
Ensure RawResponse downloads don't consume RAM
## Ensure RawResponse downloads don't consume RAM
The fix is general but the cause is very specific: since libcloud 2.0, `download_object()` in the S3 and GCS drivers first places the item in RAM, then writes it to a file. The main reason it broke is that accessing `body` in a requests Response consumes it entirely and loads it in RAM. To fix this, I moved `body` to a property: it is still accessibly, but loaded only if requested.
Tested this change by downloading a 38M file using this code:
```
from libcloud.storage.drivers.google_storage import GoogleStorageDriver
driver = GoogleStorageDriver(key=..., secret=...)
obj = driver.get_object('container_name', 'object_name')
driver.download_object(obj, '/path/to/file')
```
The RAM usage before:

The RAM usage after:

### Status
- done, ready for review
### Checklist (tick everything that applies)
- [x] [Code linting](http://libcloud.readthedocs.org/en/latest/development.html#code-style-guide) (required, can be done after the PR checks)
- [ ] Documentation
- [ ] [Tests](http://libcloud.readthedocs.org/en/latest/testing.html)
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/pquentin/libcloud streaming-s3
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/libcloud/pull/1132.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #1132
----
commit 374cb88c64e4d77c338a9d1b0269d8c01ffc15b8
Author: Quentin Pradet <qu...@clustree.com>
Date: 2017-10-16T10:58:45Z
Ensure RawResponse downloads don't consume RAM
The fix is general but the cause is very specific: since libcloud 2.0,
`download_object()` in the S3 and GCS drivers first places the item in
RAM, then writes it to a file. The reason it broke is that accessing
`body` in a requests Response consumes it entirely and loads it in RAM.
To fix this, I moved `body` to a property: it is still accessibly, but
loaded only if requested.
----
---
[GitHub] libcloud pull request #1132: Ensure RawResponse downloads don't consume RAM
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/libcloud/pull/1132
---