Skip to content

docs: Document LoadSignal customization for ConcurrencySystem - #3976

Merged
janbuchar merged 2 commits into
v4from
concurrency-system-docs
Aug 6, 2026
Merged

docs: Document LoadSignal customization for ConcurrencySystem#3976
janbuchar merged 2 commits into
v4from
concurrency-system-docs

Conversation

@janbuchar

Copy link
Copy Markdown
Contributor

@janbuchar janbuchar added the t-tooling Issues with this label are in the ownership of the tooling team. label Aug 6, 2026
@janbuchar
janbuchar requested review from B4nan, barjin and l2ysho August 6, 2026 10:15

@barjin barjin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd love to see the proxy example shrink a little, but the other examples seem alright to me. Thanks!

Comment on lines +12 to +38
class ProxyHealthSignal implements LoadSignal {
readonly name = 'proxyHealth';
readonly overloadedRatio = 0.3;

private readonly store = new SnapshotStore();
private interval?: NodeJS.Timeout;

async start({ maxSampleWindowMillis }: LoadSignalStartContext): Promise<void> {
// Retain exactly the window we will be sampled over - a store never given one keeps everything.
this.store.useSampleWindow(maxSampleWindowMillis);
// This may be a restart, so drop anything measured before the downtime.
this.store.clear();

this.interval = setInterval(async () => {
const createdAt = new Date();
this.store.push({ createdAt, isOverloaded: await areProxiesStruggling() }, createdAt);
}, 1_000);
}

async stop(): Promise<void> {
clearInterval(this.interval);
}

getSample(sampleDurationMillis?: number): LoadSnapshot[] {
return this.store.getSample(sampleDurationMillis);
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there any chance we could make this a bit more concise with SnapshotStore.fromInterval (source)?

The actual user-specific part is the (very clear and understandable) areProxiesStruggling(): Promise<boolean> indicator - we should, imo, advertise the simplest way to plug a function like this into Crawlee.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice! But aren't we still reimplementing parts of SnapshotStore.fromInterval here (namely, starting, owning and stopping the Interval)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, I must have been checking master 💡

imho it's a shame the users cannot plug their fn(): boolean | Promise<boolean> function into the LoadSignal directly (or via a simple shim... like SnapshotStore.fromInterval, for example 😄 )

But we can always add that later on, no need to deal with this now 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it felt kinda gratuitious to me so I removed it in the name of minimizing the public API.

Comment on lines +5 to +6
// Our storage backend reports no rate-limit statistics, so stop polling it every second.
client: false,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Another spot for client -> (storage)Backend rename?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Huh, thank you! #3979

@janbuchar
janbuchar merged commit 9cd3d16 into v4 Aug 6, 2026
8 checks passed
@janbuchar
janbuchar deleted the concurrency-system-docs branch August 6, 2026 12:59
@janbuchar janbuchar self-assigned this Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants