Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upPersistence is not fully persistent when using JOBDIR setting #4106
Comments
|
From what I have read from docs and issues here so far. I understand that currently scheduler has 2 queues, one in memory and this query holds currently active requests the other one is in disk. When a spider is being (gracefully) closed scrapy tries to finish currently active (in memory queue) requests and then it shuts down because, if a JOBDIR setting is being used, on the next run we can continue from disk queue.
Which brings the issues #2399 (sadly, this one is an issue created in 2016 and still not resolved), this issue and maybe some other that I have missed to notice. So other then overwriting the close functions on many classes and may be adding some other alternative functions for saving the contents of a spider. Do we have a better solution? |
|
This is plaguing me big time lately with large-scale site crawls that typically take 2+ weeks. I thought that having JOBDIR enabled would help alleviate loss of progress when the ill-configured windows server (of which i have no control over) forces a system reboot when updating. Unfortunately, I've run into the same situation @shubidubapp has described; leading to me having to restart the entire site crawl over twice (even after the latest round of collecting 625k+ items). Can someone please help introduce some sort of redundancy for this? I'm currently at a loss as to how to prevent this. It seems the JOBDIR setting could use some well-needed TLC for a few important aspects of its usage (see #4748 for another important one, while not as vital as this issue) as it's a cornerstone for many large-scale scraping projects. |
Description
I have been experimenting with keeping a persistent state for a spider by using the
JOBDIRsetting, so if it crashes or I stop it, I can start it up again from the same point it left off. I notice that the seen request fingerprints are persisted, as well as an active.json file holding information about the queue. However, in my testing, I find that the existence of the queue is inconsistent and when I restart a spider, the queue has not persisted, it just starts from the beginning and filters out all the seen requests.Steps to Reproduce
and parse functions:
Expected behavior: [What you expect to happen]
For true persistency, I would expect the spider to pick up the queue and begin making requests that hadn't already been made when the spider closed, then continue until the spider is finished.
Actual behavior: [What actually happens]
The output of the spider on the second run is shown below:
As the debug logging shows, the spider picks up the queue from the disk and continues the crawl:
[scrapy.core.scheduler] INFO: Resuming crawl (1 requests scheduled)However, after that, it redoes the first request and filters it:
[scrapy.dupefilters] DEBUG: Filtered duplicate request: <GET https://httpbin.org/links/0/0> - no more duplicates will be shown (see DUPEFILTER_DEBUG to show all duplicates)I understand that keeping the entire queue for a spider is probably not feasible, I just want to make sure I understand this correctly, as the documentation claims:
I feel I am either misunderstanding the persistence functionality or the persistence is not complete.
Any feedback is greatly appreciated.
Reproduces how often: [What percentage of the time does it reproduce?]
Everytime
Versions