Fellow PixInsight Enthusiasts,
Warning: This is another of my very long posts on various subjects. I like to give enough background information and details on a topic like this so that it can be more easily followed. The net summary of this will be to say "Running a RAMDisk for PixInsight can give you much improved Benchmark results but can actually be detrimental to overall performance when used in some configurations." Read on to find out when to use a RAMDisk and how to use one to increase PixInsight performance under selected conditions.
This post was prompted by several comments and questions in another thread here on Cloudy Nights -- namely "PixInsight Benchmark - How low can you go?". The comments I make here apply to several other threads also. I have made a number of the points in this post in other threads before. I wanted to consolidate all of my thoughts regarding the use of RAMDisk in one place rather than derail other threads with side discussions. I will give brief answers and then post pointers in the other threads.
The commentary below is my opinion and inferences based on testing that anyone can easily duplicate. I have no internal knowledge of PixInsight process operation. All of the following is based on careful observation which is verifiable.
First, I will address the concepts of PixInsight Swap Directories and Windows (or other) OS Swap Files. I often see confusion on what each of these are and how they be related. (Short answer -- they are not directly related at all.) They serve different functions that are independently important in PixInsight processes.
PixInsight Swap Folders
PixInsight Swap Directory entries are file system folders that can be used by PixInsight to store its "Swap Files". In PixInsight, these swap files are stored in the swap folders you specify in the PI Preferences (Process | Global | Preferences; Directories and Network). These swap files are part of the mechanism to handle the UnDo and ReDo operations while working with images. When you make a change to an image in the PI Workspace, a backup image file is saved to the Swap Folders. This allows PI to very quickly UnDo the operation by just reloading the saved image file. The same mechanism is used for a ReDo operation. The next version of the image is simply reloaded from the files saved in the Swap Folders.
PixInsight writes these swap files for each change in one or more images. The image is first divided into "parts" governed by the number of directories specified in preferences. For example, if you have an image loaded that is 128 MB in size and make a change to it, the file size of the image would be divided into 4 parts if you have 4 Swap Folders defined. Each of those parts is then written into the Swap Folders. If you have Swap Folders defined on more than one physical disk location, then the parts are striped across the devices (making the writing operation faster).
This UnDo / ReDo operation is the only use I have observed for the Swap Folders. If the current PI Process creates a * completely new* image frame during an operation, nothing is written to the Swap Folders. Tasks such as ImageCalibration, DeBayer, StarAlignment, ImageIntegration, and Cosmetic Correction all create new image files. These processes do not create new files in the Swap Folders. The Swap Folders are not used at all for these operations. On the other hand, processes that change an existing image do create new swap files in the Swap Folders. Processes in this group are things like HistogramTransformation, CurvesTransformation, Resample, Rescale, ColorCalibration, and lots of others. These "change an image" operations do create a new set of swap file entries when they execute.
If you look at the PixInsight Benchmark Script, you will find that only executes processes which modify the ininitial image. Specifically, the Benchmark performs the following operations on the input image: BackgroundNeutralization, ColorCalibration, DynamicCrop, MultiscaleMedianTransform, HistogramTransformation, HDRMultiscaleTransform, CurvesTransformation, CurvesTransformation (yes, twice but with different paraemters), SCNR, Resample, Resample, Resample, Resample (yes, 4 different resamples), UnsharpMask, and finally another Resample (yes, yet again). As you can see, the Benchmark does not invoke any process that creates new images along the way. So, the Benchmark Script makes heavy use of the Swap Folder structure since every operation it performs creates a new entry for a possible UnDo operation.
How do you use PixInsight? Which processes take the most time when you are processing your images. I'd bet that like me, much of the time consuming activities are Calibration, Cosmetic Correction, Sub-Frame Selection and Weighting, DeBayering, Local Normalization, and Integration and Drizzle Integration. These operations make no use of the Swap Folders since there is nothing to UnDo. (You cannot "UnDo" an image integration. You can only delete the new integration image frame.) Since the Swap Folders are not even used in these very lengthy operations, using a RAMDisk for those swap files is no help at all. However as will be seen in the next few paragraphs, having a large RAMDisk in place during those operations will make them take these new image creation processes even longer to process.
For those reasons, running a large RAMDisk can greatly boost your PixInsight Benchmark score but not help at all in the specific processes that take the most time. In fact, using RAM to build a RAMDisk for Swap Folders can lengthen the time consumed in those operations on large files sets.
OS Swap Files
Now, let's consider the Windows (or other) OS Swap Files. These files are managed solely by the OS. They can be thought of as a huge extension of your RAM memory pool. In fact, the OS uses the OS Swap Files to implement Virtual memory. Each computer system has a certain amount of physical DRAM which is used to execute programs. All modern OS implementations use disk storage to extend the amount of (Virtual) RAM you have to work with. Many programs (and background processes and services) can be running "at the same time". Just open up the Windows Task Manager to see what all is running behind the scenes.
All of those programs, processes, and services allocate and use RAM without regard to anything else that might be running. You can have running processes using more RAM than you physically have installed. The OS takes care of all that for you. It creates a very large pool of virtual RAM on one or more of your disk drives. Behind the scenes, it constantly moves contents back and forth between physical RAM and the virtual RAM image stored on disk. You are usually not aware of any of this. Every running program gets its RAM image loaded into physical RAM when it is actively running. If it goes idle, the OS can push it out to disk to make room for another program which starts running.
This becomes important to our use of PixInsight when doing things like integrating a large number of image frames. PI allocates RAM to build up the stacks of each pixel position in the frames being integrated. These needs can be huge. As an example, for my ASI294MC-Pro OSC camera, each deBayered is 4144 x 2822 pixels in size. Each pixel position contains three channel layers and each channel's pixel is represented by a 32 bit (4 byte) floating point number. Each image is then 133.83 MB is size. When I integrate multiple nights of images, I have had as many as 750 frames that need to be in RAM. This amounts to 100,373 MB of RAM needed. Since I only have 32 GB (32,768 MB) of RAM installed, Windows is paging much of this virtual RAM to disk while PI does its integration work.
So why does having a RAMDisk slow down PI's integrations? Lets' say I decided to "speed things up" and define a 16 GB RAMDisk for PI's Swap Folders. That RAM is now dedicated to something else other than being used as RAM or program space. When I start my large image integration run, the OS runs out of RAM at 16 GB rather than 32 GB. Thus it starts paging (swapping) RAM to Virtual Memory (on disk) much sooner than before. Since Disk is generally slower than RAM, that means there is a performance loss for my Image Integration operation by having the RAMDisk in place. The RAMDisk isn't even being used but hinders the OS use of Virtual memory paging.
It is this aspect of RAMDisk usage that can cause issues for running "real life" operations in PixInsight. RAMDisk use is a boon to running the PI Benchmark, but if your use of PI includes any processes that spend more time creating new files as they run, then a RAM Disk is working against you.
Times A RAMDisk Can Help Speed Up PixInsight
Obviously, as discussed above, the PI Benchmark is a clear place that RAMDisk helps (assuming you point the PI Swap Folders at the RAMDisk). Any operations that use only processes that are making changes to an image frame are also benefited by using a RAMDisk. Often though, these operations will be mostly compute bound and the RAM Disk actually isn't helping as much as you might think.
RAMDisk can help if you do more than use it for PI's Swap Folders. Assuming you have lots and lots of physical RAM, you could use the RAMDisk for temporary frames that you do not intend to save long term. For instance, if you never save your calibrated frames after integrating them, you could point the Output Directory of the ImageCalibration process to your RAMDisk (Assuming it is big enough to hold all copies of the calibrated frames. (In other words, if you camera files for a session total less that 8 GB, then you could save all the calibrated frames to an 8 GB RAMDisk. In this case, the RAMDisk would speed up the Image Calibration process nicely since writing to the RAMDisk would be faster than writing to one of your normal disks in the system. This methodology can be extended to other new frame creation processes so long as you have space for the file on the RAMDisk. Since the RAMDisk may be volatile (depending on implementation), you should always copy your final files from RAMDisk to your normal storage media when complete processing.
Pointing some of your output files to a RAMDisk will almost always speed up the running process (so long you RAMDisk doesn't run out of space). The amount of the speed up will be proportional to the storage speed of where you traditionally write the files. RAMDisk Will be much faster if your system only has HDD space for writing the files. Similarly, even if you have an SSD storage device in your system, RAMDisk may be faster. It depends on the SSD in question. A SATA SSD will usually be slower than other types. The next fastest will be a PCIe (AHCI) drive followed by an NVMe drive. For PCIe/AHCI and NVMe drives, PCIe 4.0 will be faster than PCIe3.0 or lower. My own experience is that PCIe 4.0 capable NVMe drives can be as fast as a RAMDisk drive once software management overhead is factored in. You can always use a Drive Benchmark program like Crystal Disk Mark to see the read and write speeds of the drives available to PixInsight.
Most of the above can be verified by duplicating a few observations. You can test when PixInsight uses Swap folders and how it slices up the data for an UnDo / ReDo operation. You can use the Windows Task Manager combined with watching the Resource Monitor to watch your virtual memory grow beyond your physical RAM during large PI Integration operations. (Just keep watch on the "Committed" memory to see how the Virtual Memory is allocated as needed during an operation. The Memory Resource Monitor shows the Page Fault rate when the OS starts to frantically move Virtual Memory back and forth to physical memory. Watching these as PI chugs along on large processes will give you some insights as to how important it is to have ample physical RAM if you process lots frames to build an image.
OK, I've rambled around enough for this post. I hope some find it useful. If I have made any errors, please feel free to point them out as I don't want to propagate any errors.
John