Downloading filmstrips is very slow

Hi,

I have the below code to download film strips for a shot but it takes 2-3 seconds which is rather slow for a 188K file. Obviously it’s not the download itself but the DB queries that are the bottleneck.
Does anybody know how to speed this up?

Cheers,
frank

    start = time.time()     
    print("getting url")
    sg = shotgun_api3.Shotgun(server, script, key)
    data = sg.find_one("Shot", [["id", "is", 8832]], ["image", "filmstrip_image"])
    out_img_path = "/tmp/test_filmstrip.jpg"
    print("downloading")   
    response = requests.get(data["filmstrip_image"])
    with open(out_img_path, "wb") as out_file:
        out_file.write(response.content)
    end = time.time()
    print(end-start)

I would alter teh code to make sure you are not counting for the sg connection creation, also add some time loging for the writing of the file.

And if you are doing this in a loop, batch requests may be better,

The sowness is definitely the database query.
I might have to re-think the way I am writing the app and pre-cache filmstrips rather than download them on demand.
Damn, had hoped to keep that part simple.

1 Like

Yes that is usually something that should run in the bg, just like how workfiles and loader do it.

I am running it in the bg anyway but will refactor to pre-fetch stuff

1 Like