Skip to content
This repository has been archived by the owner on Oct 17, 2022. It is now read-only.

RFC for CouchDB background workers #409

Merged
merged 2 commits into from
Sep 18, 2019
Merged

Conversation

nickva
Copy link
Contributor

@nickva nickva commented May 7, 2019

No description provided.

@nickva nickva force-pushed the rfc/007-background-workers branch 2 times, most recently from 61a6bda to 212f5de Compare May 7, 2019 04:56
Copy link
Member

@garrensmith garrensmith left a comment

Choose a reason for hiding this comment

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

Nice start @nickva thanks for starting this

rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
@nickva nickva force-pushed the rfc/007-background-workers branch from 212f5de to 1c4169a Compare May 7, 2019 15:12
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
@sansato
Copy link

sansato commented May 7, 2019

This sounds Very good! Thank you very much.

Is the data model for this lightweight to use with good API and manage progress/backlog/and so for "middle-tier" tasks? Think of use-cases being served in old style database with asynchronous triggers following API calls, to change paradigm, like Kafka with consumer-groups. Software agents can connect to couchdb's job-service api, claim ready to serve shard of queue for specific application-layer job, get change-stream like replication queue and post notifications if needed to show progress. It can be simpler and get good help from job infrastructure, make business infrastructure easier to control and manage. They enjoy most of same things like indexing does, optional "reprocess whole database", live processing of newest records even during rebuild and so.

@nickva
Copy link
Contributor Author

nickva commented May 7, 2019

@sansato

Is the data model for this lightweight to use with good API and manage progress/backlog/and so for "middle-tier" tasks?

Ah, that's an interesting idea. The background jobs systems could in theory accept jobs from the outside if there was an HTTP API wrapper around it. So far in the design, jobs's keys and values are FDB tuples and/or json encoded objects so it seems doable. Perhaps something for a future iteration...

We also mention that workers could be implemented as any process which can connect to the FDB cluster. Generally it will be Erlang processes (or applications) but those workers could be written in other language as long as they can talk to the FDB cluster. And we might even end up with that when implementing some of the secondary indexing work. Having a completely custom set of workers, and a more fleshed out API for the workers to claim and do work would be possible. But I suggest we leave that for the future as well.

@sansato
Copy link

sansato commented May 7, 2019

for now, could highlight the integration spots to decrease odds that "future" resolves to "never".

Thanks!

@nickva nickva force-pushed the rfc/007-background-workers branch 3 times, most recently from ca38810 to fc72fcf Compare May 8, 2019 17:18
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
rfcs/007-background-workers.md Outdated Show resolved Hide resolved
@nickva nickva force-pushed the rfc/007-background-workers branch 2 times, most recently from 82fb337 to a63a147 Compare May 14, 2019 14:40
@nickva
Copy link
Contributor Author

nickva commented May 14, 2019

Thank you all for the feedback. Taking it into consideration, and also
discussing with @davisp I think it would make sense make these changes:

  1. Switch the focus from workers to jobs. Previously the focus was on workers.
    How many workers are running, how they are registered, monitoring their
    liveness, etc. The concept of worker was similar to a job manager or job
    supervisor. That introduced unecessary complexity. It was also confusing
    that one worker was running more than one job. So instead the API and the
    implementation switch to making a job as central concept. Users add jobs,
    resubmit jobs, etc. A worker now become just what function (or process)
    happens to execute the job at a particular instant

  2. Previously there was no clear distinction between how the framework would be
    implemented vs what framework API would look like. In the current version,
    the main part of the RFC focuses on the framework API and then implementation
    is discussed separately.

  3. Some concepts like "health" were removed and instead re-used "activity"
    since it is already something CouchDB knows about (thanks @janl for pointing
    it out).

  4. Based on indexing requirements, introduced the concept of job-resubmission.

  5. Mutual exclusion guarantees will be important for indexing and so there is
    a section discussing that aspect as well.

@nickva nickva force-pushed the rfc/007-background-workers branch from a63a147 to 33b9582 Compare May 14, 2019 19:00
Copy link
Member

@garrensmith garrensmith left a comment

Choose a reason for hiding this comment

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

This is really nice and much clearer than the original worker rfc. Nice work.

rfcs/007-background-jobs.md Outdated Show resolved Hide resolved
rfcs/007-background-jobs.md Outdated Show resolved Hide resolved
rfcs/007-background-jobs.md Outdated Show resolved Hide resolved
rfcs/007-background-jobs.md Outdated Show resolved Hide resolved
rfcs/007-background-jobs.md Outdated Show resolved Hide resolved
@nickva nickva force-pushed the rfc/007-background-workers branch from 33b9582 to 597c3a2 Compare May 15, 2019 15:02
Copy link
Member

@davisp davisp left a comment

Choose a reason for hiding this comment

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

Super awesome work on this! I'm quite like how the overall structure has turned out and made the whole approach seem a lot more intuitive.

I would like to spend some effort reorganizing the layout of this doc though. I could see this either being the basis for or even just as-is the documentation for a developer that wants to implement a new job type. As is that developer would have to read the entire document and comprehend the entire structure and implementation of job processing before being certain that a job processing implementation was correct. I think splitting it out into a few more sections that go from high level to progressively lower level details would be quite helpful for future when we've paged this out of brain cache and accidentally overwritten those meat sectors with intervening years of coding. I'd propose something like the following:

  1. Front matter
  2. Reason for existence
  3. High-level description of a job
  4. API description from the developer point of view
  5. Internals concepts
  6. API algorithm descriptions
  7. Explicit data model
  8. API implementation referencing fdb level functions and data model
  9. Mutual exclusion (if not sufficiently covered in 8)
  10. Activity monitor (samesies if not covered)

All of those things already exist, but they're jumbled around in such a way that makes the various concepts hard to absorb. I tend to think of it as starting high level and then working towards actual bytes. I'm basically thinking that sections 3 and 4 should basically contain enough information for a developer implementing a new job type and then everything else just gets progressively closer to the actual fdb interface.

Again, super awesome work!

rfcs/007-background-jobs.md Outdated Show resolved Hide resolved
rfcs/007-background-jobs.md Outdated Show resolved Hide resolved
rfcs/007-background-jobs.md Outdated Show resolved Hide resolved
rfcs/007-background-jobs.md Outdated Show resolved Hide resolved
rfcs/007-background-jobs.md Outdated Show resolved Hide resolved
rfcs/007-background-jobs.md Outdated Show resolved Hide resolved
rfcs/007-background-jobs.md Show resolved Hide resolved
rfcs/007-background-jobs.md Outdated Show resolved Hide resolved
rfcs/007-background-jobs.md Outdated Show resolved Hide resolved
rfcs/007-background-jobs.md Outdated Show resolved Hide resolved
@nickva nickva force-pushed the rfc/007-background-workers branch 4 times, most recently from 2a6f306 to cc99b71 Compare June 6, 2019 14:40
@nickva
Copy link
Contributor Author

nickva commented Jun 6, 2019

@davisp, @garrensmith Thanks for the great comments and input. I had pushed the update that hopefully addresses most of the issues. I think the API looks cleaner and the structure of the RFC is more reasonable as well.

@nickva nickva force-pushed the rfc/007-background-workers branch from cc99b71 to 659941b Compare June 6, 2019 16:28
@nickva nickva force-pushed the rfc/007-background-workers branch from 659941b to 1f8c2ac Compare June 6, 2019 16:30
Copy link
Member

@garrensmith garrensmith left a comment

Choose a reason for hiding this comment

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

Some minor changes. But really nice RFC. Really nice and clear.

rfcs/007-background-jobs.md Outdated Show resolved Hide resolved
rfcs/007-background-jobs.md Outdated Show resolved Hide resolved
Jobs in the system can be in a few different states. After a job is added and
is waiting to run, the job is considered to be `pending`. A job executed by
a job processor is considered to be `running`. When a job is neither `running`,
nor `pending`, it is considered to be `finished`. This is the state transition
Copy link
Member

Choose a reason for hiding this comment

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

Should we mention that a finished job could be resubmitted later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the job was running, then resubmitting it would make it pending again after the job processor calls finish. However if it already finished, then it won't start running again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was updated such that job creator can just call add/4,5 again. If the job is running it will be flagged to be re-enqueued when it finishes. If it is pending, only the scheduled time value may be updated (if provided). If the job was already finished it is re-enqueued for execution.

rfcs/007-background-jobs.md Outdated Show resolved Hide resolved
rfcs/007-background-jobs.md Outdated Show resolved Hide resolved
rfcs/007-background-jobs.md Outdated Show resolved Hide resolved
rfcs/007-background-jobs.md Outdated Show resolved Hide resolved
nickva added a commit to apache/couchdb that referenced this pull request Jun 12, 2019
RFC: apache/couchdb-documentation#409

Main API is in the `couch_jobs` module. Additional description of internals is
in the README.md file.
nickva added a commit to apache/couchdb that referenced this pull request Jun 12, 2019
RFC: apache/couchdb-documentation#409

Main API is in the `couch_jobs` module. Additional description of internals is
in the README.md file.
@nickva nickva force-pushed the rfc/007-background-workers branch from 1f8c2ac to d98ee3f Compare June 12, 2019 21:36
@nickva nickva force-pushed the rfc/007-background-workers branch from d98ee3f to d065db3 Compare June 13, 2019 20:29
nickva added a commit to apache/couchdb that referenced this pull request Jul 2, 2019
RFC: apache/couchdb-documentation#409

Main API is in the `couch_jobs` module. Additional description of internals is
in the README.md file.
nickva added a commit to apache/couchdb that referenced this pull request Jul 2, 2019
RFC: apache/couchdb-documentation#409

Main API is in the `couch_jobs` module. Additional description of internals is
in the README.md file.
nickva added a commit to apache/couchdb that referenced this pull request Jul 3, 2019
RFC: apache/couchdb-documentation#409

Main API is in the `couch_jobs` module. Additional description of internals is
in the README.md file.
nickva added a commit to apache/couchdb that referenced this pull request Jul 3, 2019
RFC: apache/couchdb-documentation#409

Main API is in the `couch_jobs` module. Additional description of internals is
in the README.md file.
nickva added a commit to apache/couchdb that referenced this pull request Jul 3, 2019
RFC: apache/couchdb-documentation#409

Main API is in the `couch_jobs` module. Additional description of internals is
in the README.md file.
nickva added a commit to apache/couchdb that referenced this pull request Jul 8, 2019
RFC: apache/couchdb-documentation#409

Main API is in the `couch_jobs` module. Additional description of internals is
in the README.md file.
@nickva nickva force-pushed the rfc/007-background-workers branch from d065db3 to de330f5 Compare July 9, 2019 16:49
@nickva nickva force-pushed the rfc/007-background-workers branch from de330f5 to 7b795d4 Compare July 9, 2019 19:19
davisp pushed a commit to apache/couchdb that referenced this pull request Jul 31, 2019
RFC: apache/couchdb-documentation#409

Main API is in the `couch_jobs` module. Additional description of internals is
in the README.md file.
@kocolosk
Copy link
Member

@davisp @garrensmith @nickva is this one approved and ready to merge? I don't see any outstanding comments

@nickva
Copy link
Contributor Author

nickva commented Sep 17, 2019

I think I addressed most of the issues. Didn't know if @davisp wanted to take another look at it

@davisp
Copy link
Member

davisp commented Sep 18, 2019

I haven't got anything to add.

@nickva nickva merged commit e33ac3c into master Sep 18, 2019
@nickva nickva deleted the rfc/007-background-workers branch September 18, 2019 16:33
davisp pushed a commit to apache/couchdb that referenced this pull request Feb 26, 2020
RFC: apache/couchdb-documentation#409

Main API is in the `couch_jobs` module. Additional description of internals is
in the README.md file.
davisp pushed a commit to apache/couchdb that referenced this pull request Feb 27, 2020
RFC: apache/couchdb-documentation#409

Main API is in the `couch_jobs` module. Additional description of internals is
in the README.md file.
davisp pushed a commit to apache/couchdb that referenced this pull request Mar 2, 2020
RFC: apache/couchdb-documentation#409

Main API is in the `couch_jobs` module. Additional description of internals is
in the README.md file.
davisp pushed a commit to apache/couchdb that referenced this pull request Mar 2, 2020
RFC: apache/couchdb-documentation#409

Main API is in the `couch_jobs` module. Additional description of internals is
in the README.md file.
davisp pushed a commit to apache/couchdb that referenced this pull request Sep 9, 2020
RFC: apache/couchdb-documentation#409

Main API is in the `couch_jobs` module. Additional description of internals is
in the README.md file.
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.

None yet

8 participants