Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.

Clean up Jobqueues, minor fixes for S3 Queue - #451

Merged
neilkakkar merged 5 commits into
masterfrom
jobqueues
Jun 4, 2021
Merged

neilkakkar merged 5 commits into
masterfrom
jobqueues

Conversation

@neilkakkar

@neilkakkar neilkakkar commented Jun 1, 2021 •

Copy link
Copy Markdown
Contributor

Changes

Ensures S3 queue consumer runs.

Makes GraphileQueue adhere to JobQueueBase.

Checklist

  • Updated Settings section in README.md, if settings are affected
  • Jest tests

@neilkakkar
neilkakkar requested a review from mariusandra June 1, 2021 15:10
@@ -62,8 +64,10 @@ export class JobQueueBase implements JobQueue {
resumeConsumer(): void
// eslint-disable-next-line @typescript-eslint/require-await
async resumeConsumer(): Promise<void> {

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.

Resume is called on drain events emitted by Piscina, which results in multiple calls to sync state. This is okay, as long as dequeue code is idempotent (which it isn't, thus leading to race conditions).

We didn't face this with graphile because the runner object is unchanged over multiple sync state calls.

Comment thread src/main/job-queues/job-queue-base.ts Outdated
// eslint-disable-next-line @typescript-eslint/await-thenable
const hadSomething = await this.readState()
this.timeout = setTimeout(() => this.syncState(), hadSomething ? 0 : this.intervalSeconds * 1000)
await this.readState()

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.

Given existing semantics, readState is supposed to finish everything required with the jobs seen so far. So, it doesn't make sense to poll again right after, if it found some jobs to process.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The idea here is that if you have 10k jobs to run, you shouldn't wait 5 sec between them (or between every 100 of them) :). So if we got a job with the last run, immediately see if there's another one. Otherwise wait a few seconds and then try again.

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.

Ah, that makes sense... assuming there's batching involved. I haven't seen it so far (am I missing something?) - so didn't assume such a state was possible.

Will revert.

Comment thread src/main/job-queues/redlocked/s3-queue.ts Outdated
Comment thread tests/jobs.test.ts
})
})

test('polls for new jobs', async () => {

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.

these tests would fail after 60s (jest timeout) if there's no polling.

@mariusandra mariusandra left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

some thoughts below, still haven't ran it locally

Comment thread src/main/job-queues/job-queue-base.ts Outdated
// eslint-disable-next-line @typescript-eslint/await-thenable
const hadSomething = await this.readState()
this.timeout = setTimeout(() => this.syncState(), hadSomething ? 0 : this.intervalSeconds * 1000)
await this.readState()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The idea here is that if you have 10k jobs to run, you shouldn't wait 5 sec between them (or between every 100 of them) :). So if we got a job with the last run, immediately see if there's another one. Otherwise wait a few seconds and then try again.

Comment thread tests/jobs.test.ts Outdated
Comment thread tests/jobs.test.ts Outdated
@neilkakkar
neilkakkar requested a review from mariusandra June 2, 2021 10:34

@mariusandra mariusandra left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

These changes make sense

@neilkakkar
neilkakkar merged commit b499825 into master Jun 4, 2021
@neilkakkar
neilkakkar deleted the jobqueues branch June 4, 2021 09:49
fuziontech pushed a commit to PostHog/posthog that referenced this pull request Oct 12, 2021
…/plugin-server#451)

* fix s3 consumer, cleanup graphile queue

* tests

* address comments
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants