Skip to content

Very slow download speed from ObjectDownloadView #198

Open
@johnthagen

Description

@johnthagen

I have an ObjectDownloadView that is serving very large files (200MB - 2GB). I've observed that the download speed is very slow, even when pulling downloads over localhost where no actual network is involved at all. I must authenticate the file downloads (not shown the example below), which is why I must use django-downloadview rather than serving them statically.

I cannot use NGINX acceleration due to:

My endpoint looks something like:

class MyModelObjectDownloadView(ObjectDownloadView):
    model_class = MyModel
    file_field = "model"
    basename_field = "filename"

The Model:

class MyModel(models.Model):
    MODEL_UPLOAD_TO_DIR = "models"
    model = models.FileField(upload_to=MODEL_UPLOAD_TO_DIR)
    filename = models.TextField()

URLs:

urlpatterns = [
    ...
    path(
        f"media/{MyModel.MODEL_UPLOAD_TO_DIR}/<int:pk>/",
        MyModelObjectDownloadView.as_view(),
        name=SurfaceModel.IMAGE_UPLOAD_TO_DIR,
    ),
]

I've tested downloading the file using a variety of clients over localhost (also running locally on mac and also within a Linux Docker container) and they all show a similar result:

  • httpx
  • Chrome
  • curl
$ curl http://localhost:8000/media/models/1/ --output out.bin
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  118M  100  118M    0     0  5398k      0  0:00:22  0:00:22 --:--:-- 5663k

This corresponds to about 40Mbps, which seemed very slow for a localhost pull. I also see the python executable running at about 100% CPU, as if it's CPU rather than I/O bound?

Is there something about how django-downloadview streams or chunks the file that contributes to why this is so slow?

Are there any configuration settings to speed up serving files natively from django-downloadview?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions