-
Notifications
You must be signed in to change notification settings - Fork 744
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
fix: Simplified RequestQueueV2 implementation #2775
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 💪
I would do some testing myself, but the first what about some unit tests, did you consider,add some? There are none -> https://github.com/apify/crawlee/blob/03951bdba8fb34f6bed00d1b68240ff7cd0bacbf/test/core/storages/request_queue.test.ts
Honesly, we are dealing with various bugs during time and we do not have any tests for these features still.
The build did not finish, can you check @janbuchar ? |
I can, but only later this week - I have different stuff to finish first. |
@drobnikj the unit tests are now passing so you should be able to build. I'm still working on some e2e tests, if you have any ideas for scenarios to test (e2e, unit, doesn't matter), I'd love to hear those. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I did not find any issue, even during testing.
I have a few more comments, can you check pls? @janbuchar
|
||
const headData = await this.client.listAndLockHead({ | ||
limit: Math.min(forefront ? this.assumedForefrontCount : 25, 25), | ||
limit: Math.min(hasPendingForefrontRequests ? this.assumedForefrontCount : 25, 25), | ||
lockSecs: this.requestLockSecs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked where requestLockSecs
was set and I think we should consider to change it.
The currrent is 2x of requestHandlerTimeoutSecs plus 5 secs.
this.requestQueue.requestLockSecs = Math.max(this.internalTimeoutMillis / 1000 + 5, 60); |
I think we should set it to
requestHandlerTimeoutSecs plus some safe buffer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, what do you think a safe buffer would be?
@@ -361,7 +430,8 @@ export class RequestQueue extends RequestProvider { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot comment it below but during code review, I see that we are removing locks one by one in _clearPossibleLock
.
see
while ((requestId = this.queueHeadIds.removeFirst()) !== null) { |
There is 200 rps rate limit. I would remove lock in some batches maybe 10 to speed it up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean? I don't think there is a batch unlock endpoint. Launching those requests in parallel surely won't help against rate limiting, too.
@@ -53,7 +53,8 @@ const RECENTLY_HANDLED_CACHE_SIZE = 1000; | |||
* @category Sources | |||
*/ | |||
export class RequestQueue extends RequestProvider { | |||
private _listHeadAndLockPromise: Promise<void> | null = null; | |||
private listHeadAndLockPromise: Promise<void> | null = null; | |||
private queueHasLockedRequests: boolean | undefined = undefined; | |||
|
|||
/** | |||
* Returns `true` if there are any requests in the queue that were enqueued to the forefront. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please update this function regarding notes in
https://github.com/apify/apify-core/issues/19218#issuecomment-2621466723 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I managed to make it work regardless of whether or not there are multiple clients.
@drobnikj thanks! You really went above and beyond for this one. I'll try to wrap this up today/tomorrow. |
@barjin I gave the forefront handling a makeover. If you could check that out, I'd be super grateful. |
Looking good to me 👍🏽 I remember reversing the forefront array somewhere already (likely |
queueHasLockedRequests
to simplify RequestQueue v2 #2767