Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: cheerio experimental queue #188

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

petrpatek
Copy link

This is a POC version with minimal API and minimal request footprint.

Possible improvements:

  • Use magazine instead of the queue to allow syncing with kv-store during the run and save only the rest loaded in memory.
  • compress the requested objects in memory
  • use large-set package to bypass nodeJs internal limit for Set

@metalwarrior665
Copy link
Member

Let's keep this non-merged for some time.

Copy link
Member

@metalwarrior665 metalwarrior665 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Should have a few more comments. Nothing urgent with the remarks.

}

await Promise.all(orderedKeys.map(({ key }) => {
return storeClient.deleteRecord(key);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be dangerous if you crash right after this delete, you loose everything. I would prefer to figure out how to overwrite properly.

await this.persistQueueState();
this.log.info('State persisted!');
});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably make an option store on interval too. This would not persist anything in case of abrupt abort.

@@ -0,0 +1,27 @@
export default class Queue<T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment explaining where is this used, wasn't obvious at first


for (let i = 0; i < arr.length; i += chunkSize) {
const chunk = arr.slice(i, i + chunkSize);
// Faster with got
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain why pls

method: 'PUT',
json: chunk,
http2: false,
}).catch((e: any) => this.log.exception(e.message, e.status)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like if we get rate limited or fail on 502 we just give up. I know this means reimplementing our client...perhaps there is a way to use the client in the end...

this.log.info('State Loaded!', { requestCount: this.requests.size() });
}

_stripRequest(requestLike: Request | RequestOptions) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comment here would be nice

}

addRequest(requestLike: any) {
const uid = requestLike.uniqueKey ? requestLike.uniqueKey : requestLike.url;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the request.id hashing function from crawlee. e.g. url is converted to uniqueKey (if not present) and then hashed to id (we can throw that away later). This way we replicate Crawlee and hashes are smaller to keep.

But not sure if it wouldn't have bad perf for when you need to refill after migration. If yes, please add comment that we decided to skip this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants