Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with S3BotoStorageFile and a file greater than 5Mb #160

Closed
iceseyes opened this issue Jun 12, 2016 · 1 comment · Fixed by Coverfox/django-storages#1 or #504
Closed

Problem with S3BotoStorageFile and a file greater than 5Mb #160

iceseyes opened this issue Jun 12, 2016 · 1 comment · Fixed by Coverfox/django-storages#1 or #504
Labels

Comments

@iceseyes
Copy link

iceseyes commented Jun 12, 2016

My team and I have found a problem in file-like interface for S3botoStorageFile.

If I do something like that:

 storage = S3BotoStorage()
 with storage.open("test.csv", "w") as f:
     df.to_csv(f)

where df is a Pandas' Dataframe, and file is greater than 5Mb, when we run the program from an ec2 instance, program stops over a write instruction.

Debugging we have seen that when file size become 5Mb the test in s3boto.py:159

if self.buffer_size <= self._buffer_file_size:
     self._flush_write_buffer()

is True for every write request, so for every write I have a request to upload to s3.... and after a few of seconds program freezes.

I think that test should be something like that

if (self._write_counter * self.buffer_size) <= self._buffer_file_size:
     self._flush_write_buffer()

Thank you.

vinayinvicible added a commit to Coverfox/django-storages that referenced this issue Sep 6, 2016
vinayinvicible added a commit to Coverfox/django-storages that referenced this issue Sep 6, 2016
mattswoon added a commit to mattswoon/django-storages that referenced this issue Jul 24, 2017
             part upload.

             fixes similar issue to jschneier#160 for s3boto3. Inspired by
             vinayinvicible's fix for jschneier#160.
mattswoon added a commit to mattswoon/django-storages that referenced this issue Jul 24, 2017
             part upload.

             Fixes jschneier#364, similar issue to jschneier#160 for s3boto3. Inspired by
             vinayinvicible's fix for jschneier#160.
@timur-orudzhov
Copy link

We've also encountered with that issue and pr, that provided by tommwatson, fixed that issue. In our case, we open local file that weight about 13 mb and write to file by chunks (~ 1mb), that on s3, as a result we have file with weight about 76 mb. How to reproduce:

from django.core.files.storage import default_storage

def read_in_chunks(file_object, chunk_size=1024 * 1000):
    """Lazy function (generator) to read a file piece by piece.
       Default chunk size: 1mb.
    """
    while True:
        data = file_object.read(chunk_size)
        if not data:
            break
        yield data


with open('/path/to/file', 'r+b') as local_file:
    with default_storage.open('path/to/s3_file', mode='wb') as s3_file:
        for chunk in read_in_chunks(local_file):
            s3_file.write(chunk)

Are there chances to merge fix i've mentioned earlier ?

jschneier pushed a commit that referenced this issue Jun 1, 2018
…504)

* fix for files with size more than buffer size

fixes #160

* fix(s3bot3): spool buffer file to end of all uploaded parts after each
             part upload.

             Fixes #364, similar issue to #160 for s3boto3. Inspired by
             vinayinvicible's fix for #160.

* Fix style issues flagged by flake8

* `At least two spaces before inline comment (E261)`
* `Imports are incorrectly sorted.`

* Fix s3boto3 test incompatibility with Python 3.4
nitely pushed a commit to satellogic/django-storages that referenced this issue Jul 30, 2018
…schneier#504)

* fix for files with size more than buffer size

fixes jschneier#160

* fix(s3bot3): spool buffer file to end of all uploaded parts after each
             part upload.

             Fixes jschneier#364, similar issue to jschneier#160 for s3boto3. Inspired by
             vinayinvicible's fix for jschneier#160.

* Fix style issues flagged by flake8

* `At least two spaces before inline comment (E261)`
* `Imports are incorrectly sorted.`

* Fix s3boto3 test incompatibility with Python 3.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants