[Fixed]-Can I slow down Django


depending on where you want to simulate such you could simply sleep?

from time import sleep


On osx or freebds, you can use ipfw to limit bandwidth on specific ports:

  sudo ipfw pipe 1 config bw 1Bytes/s delay 100ms
  sudo ipfw add 1 pipe 1 src-port 8000

Do not forget to delete it when you do not need it anymore:

sudo ipfw delete 1

Credit: jaguarcy

For osx there is also free app that will allow this:



You could write a customized upload handler or subclass current upload handler to mainly slow down receive_data_chunk() method in it. Or set a pdb breakpoint inside receive_data_chunk() and manually proceed the uploading. Or even simpler, try to upload some large file.



I’m a big fan of the Charles HTTP Proxy. It lets you throttle the connection and can simulate all sorts of network conditions.



Use the slow file upload handler from django-gubbins:

import time
from django.core.files.uploadhandler import FileUploadHandler

class SlowFileUploadHandler(FileUploadHandler):
    This is an implementation of the Django file upload handler which will
    sleep between processing chunks in order to simulate a slow upload. This
    is intended for development when creating features such as an AJAXy
    file upload progress bar, as uploading to a local process is often too
    def receive_data_chunk(self, raw_data, start):
        return raw_data

    def file_complete(self, file_size):
        return None

You can either enable this globally, by adding it to:


Or enable it for a specific request:

request.upload_handlers.insert(0, SlowFileUploadHandler())

Make sure the request is excepted from CSRF checking, as mentioned at https://docs.djangoproject.com/en/dev/topics/http/file-uploads/#id1



If you want to slow things down across all requests a very easy way to go would be to use ngrok https://ngrok.com/ . Use the ngrok url for requests then connect to a vpn in another country. That will make your requests really slow.

Leave a comment