UltimaScraper icon indicating copy to clipboard operation
UltimaScraper copied to clipboard

Amount of free RAM must be double the largest file to be downloaded

Open E0911CD45B19686 opened this issue 5 years ago • 2 comments

I'm running this on a Synology NAS with 8GB of RAM. I was getting some out of memory errors during my recent scrapes and I was able to trace it to one specific model, and one specific video.

The error:

100%|█████████████████████████████████████████████████▉| 2.84G/2.84G [01:39<00:00, 25.3MB/s]
Traceback (most recent call last):
  File "/usr/src/app/./start_ofd.py", line 44, in main
    api = await main_datascraper.start_datascraper(json_config, site_name_lower)
  File "/usr/src/app/datascraper/main_datascraper.py", line 113, in start_datascraper
    x = await main_helper.process_downloads(api, module)
  File "/usr/src/app/helpers/main_helper.py", line 692, in process_downloads
    await module.prepare_downloads(subscription)
  File "/usr/src/app/modules/onlyfans.py", line 1266, in prepare_downloads
    a = await subscription.session_manager.async_downloads(
  File "/usr/src/app/apis/api_helper.py", line 318, in async_downloads
    results = await asyncio.ensure_future(run(download_list))
  File "/usr/src/app/apis/api_helper.py", line 313, in run
    result = await asyncio.gather(*tasks)
  File "/usr/src/app/apis/api_helper.py", line 290, in process_download
    response = await self.download_content(
  File "/usr/src/app/apis/api_helper.py", line 335, in download_content
    response, task = await asyncio.ensure_future(
  File "/usr/src/app/apis/api_helper.py", line 195, in json_request
    final_buffer = b"".join(buffer)
MemoryError

I quit all the other stuff I could and tried again and it finished successfully, I did however notice that the used ram was double the file being downloaded. Here's a graph of the memory usage: memory

Based on the code section linked from the traceback and the fact that the memory is doubled, it looks like the json_request is creating an array in memory to hold the download, then converting that to a byte string, also in memory?

This is certainly an edge case, but it does seem silly that 6+ gigs of RAM would be required to download one file, I think I can figure out double buffer issue, but it would be cool if we could stream directly to disk instead of RAM (that looks like a bigger refactor though).

E0911CD45B19686 avatar Jun 12 '21 17:06 E0911CD45B19686

Yeah, the way I'm doing it isn't memory friendly at all. I'll be changing it so when a download starts, it will write to disk.

Does lowering max threads to 1 help? Max threads controls how many downloads should happen at once.

UltimaHoarder avatar Jun 12 '21 18:06 UltimaHoarder

Does lowering max threads to 1 help?

I tried that first and it didn't help in this specific case because it was just one very large file, so even a single thread maxxed it out.

Thanks for the fix.

E0911CD45B19686 avatar Jun 13 '21 05:06 E0911CD45B19686