Under the Hood of Rapid Photo Downloader

Rapid Photo Downloader is written in Python. To get the best performance using Python on modern multi-core computers, the program uses multiple OS-level processes that communicate with each other using the messaging library 0MQ.

Process model
(Click on the image to expand it)

Each box in the diagram represents one and sometimes more OS-level processes. The dashed lines emanating from the main process indicate that the process being pointed to is typically short-lived. For example, the Scan Device process exists only as long as it takes to scan a device. As soon as the scan is finished, the Scan Device process exits. Because the program can scan multiple devices at one time, the diagram shows two lines going to the Scan Device process. To keep the diagram simple, there are only two lines to the Scan Device process, but in reality when the program runs the number of scan processes running at any one time will match the number of unique devices being scanned.

Solid lines between the processes indicate that the process runs for the duration that Rapid Photo Downloader is being run. As soon as the program is started, Rapid Photo Downloader starts one process each to take care of renaming files and generating subfolder names, another for the load balancer for extracting thumbnails, two or more thumbnail extractor processes, and a helper process onto which computationally expensive tasks are offloaded from the main GUI process.

To keep the code as simple as possible, different units of the program's code handle specific tasks. For example, the Copy Files process does only one thing: copy photos, videos and associated files (XMP file, WAV file etc.) from a device (camera, memory card, hard drive etc.) onto the computer, and that's it. It doesn't know anything about backing up the files or generating thumbnails, for example. The Rename Files process generates file and folder names, renames the files that have just been copied and creates subfolders to put them in. The Backup Files process copies files that have just been copied and renamed from the computer to a backup device. Each backup device has its own backup process. For instance if you have two external drives you're backing up to, there will be two backup processes running as long as those drives remain plugged in.

Although it may not be obvious from the diagram at first glance, when downloading simultaneously from multiple devices (e.g. two memory cards), a process for each device is used to copy the files onto the computer, but only one process renames them. That keeps the name generation code as simple as possible. Given aspects of generating file names can actually be fairly complex, especially with respect to sequence numbers, the simpler the overall renaming series of steps is, the better.

Thumbnailing: Optimized for Speed

The thumbnailing part of the program is the most complex. Thanks to its load balancer and multiple processes, Rapid Photo Downloader can extract and resize thumbnails from one file's metadata while it is simultaneously copying another file's metadata.

Consider for instance generating thumbnails for photos on a DSLR. Getting the file's metadata requires the program calling libgphoto2 to copy the file's metadata from the camera onto the computer. So Rapid Photo Downloader dedicates a process to doing only that (the Thumbnailer box in the diagram). All that process does is check the if the file already has a thumbnail in Rapid Photo Downloader's thumbnail cache, and if it doesn't, copies the photo's metadata which contains the photo's thumbnails and then sends a message to the load balancer that it can assign one of the Thumbnail Extractors the task of extracting the photo's thumbnail. The Thumbnail Extractor process simply extracts and resizes thumbnails from metadata (if it can) or by rendering it from the file itself if required. Because there are at least two extractors running at any one time, the extractors can work on multiple files simultaneously. The extractors always work on metadata or actual files that are already on the computer, whether in memory or on disk. They don't need to know whether the file just came from a camera or from a hard drive or memory card. They have a specific task and that's all they work on.

In case you're wondering about the purpose of the Thumbnail Daemon process, that's used to generate thumbnails for the GUI after a file has been downloaded (which happens when auto-downloading is activated) and also to generate freedesktop.org thumbnails, which are used in programs like Gnome Files (Nautilus) and other file browsers. Freedesktop.org thumbnails come in two sizes, 128x128 and 256x256. The latter size is larger than the 160x120 thumbnail found in a photo's metadata. Nowadays all DSLR cameras output JPEG and RAW files with several embedded thumbnails, the largest of which is full size for RAW files. However large embedded thumbnails are much slower to extract and resize than the 160x120 thumbnail, so Rapid Photo Downloader puts off doing that until it absolutely has to. It has no need to do that while generating thumbnails for the GUI, so the Thumbnailer process doesn't do that for DSLR photos, for instance. But the program does need to extract those large embedded thumbnails while generating an up to 256x256 thumbnail for the freedesktop.org cache for RAW files, so it does that after the file is download onto the computer, using the Thumbnail Daemon process, which like the Thumbnailer passes the task of extracting the thumbnail from the metadata onto the load balancer, which in turn passes that task onto the extractors.

Design Tradeoffs

Admittedly Rapid Photo Downloader's design does not suit itself to all photo and video download situations. For some very simple computers that have only one CPU core and don't have much memory, the multi-process setup is ridiculously complex. Moreover, even on modern multi-core computers, because to run the program involves starting several processes at once, version 0.9 starts up slower than previous versions.

However the program's design comes into its own when dealing with thousands of images at a time, or when downloading from or backing up to multiple devices. Some photographers come back to their computer with tens or even hundreds of thousands of images at a time, e.g. time lapse photographers. For them it can take many minutes just to generate the thumbnails. Even if you don't download thousands of images at a time, you might notice that version 0.9 generates thumbnails considerably more quickly than previous versions.