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] Option to execute jobs on the same event loop "inline" #68

Open
naz opened this issue Dec 15, 2020 · 5 comments
Open

[feat] Option to execute jobs on the same event loop "inline" #68

naz opened this issue Dec 15, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@naz
Copy link
Member

naz commented Dec 15, 2020

Problem

Executing jobs on a separate thread through worker_thread or in a separate process comes with a price of additional memory allocation and time taken to spawn up a thread/process. Because of these constraints it's sometimes more efficient to run jobs in the same event loop. For example, a job which has few non blocking (async) operations and needs to be executed on specific schedule.

Solution

Introduce an option to job configuration to execute it as an "inline" function. Proposing an option name: offloaded, which would have to be set to false to run in the same even loop.

The solution would need to look into restrictions that would come with running such functions.

@niftylettuce @shadowgate15 would love to hear your opinions on this topic and hear your thoughts about the new option naming.

naz added a commit to TryGhost/Utils that referenced this issue Jan 6, 2021
refs #122

- In future changes there's a plan to add "inline" scheduled jobs, which would conflict current method naming.
- The amount of parameters in the methods was more than 3, so it made sense to transform them into an options object
- Scheduling still doesn't work for "inline" jobs. This should be solved as a part of upstream library (breejs/bree#68)
@naz naz added the enhancement New feature or request label Jan 6, 2021
@cayuu
Copy link

cayuu commented Jun 7, 2021

We ended up having to roll our own to enable something like this, for a variety of use-cases where this was the right trade off. It was also handy being able to share DB connection pool context for certain types of jobs.

@shadowgate15
Copy link
Member

In order for it to offload it would probably make since for bree to create a dedicated worker that could then accept a message containing the path to the job and run the job. This way the main thread does not get stuck and therefore no longer processing other scheduled jobs that should be run on a separate event loop.

It probably makes sense to address #45, before trying to do this. If #45 was addressed it might resolve this issue without a specified "offload" option, since the overhead wouldn't be a problem any more.

daniellockyer pushed a commit to TryGhost/Ghost that referenced this issue Jul 26, 2022
refs #122

- In future changes there's a plan to add "inline" scheduled jobs, which would conflict current method naming.
- The amount of parameters in the methods was more than 3, so it made sense to transform them into an options object
- Scheduling still doesn't work for "inline" jobs. This should be solved as a part of upstream library (breejs/bree#68)
@naz
Copy link
Member Author

naz commented Apr 15, 2023

Hey @niftylettuce, @titanism, and @shadowgate15 is inlining jobs still something you'd be happy to have as a part of the package?

One of the usecases for such jobs is being able to have all the environment setup as the parent process has already but use same messaging, scheduling, etc. as the rest of jobs in bree. The implementation I'm thinking of is similar to one Ghost has taken through fastq - I'd aim to mostly port the functionality from Ghost's job manager into bree.

Or do you think non-worker-thread work is not something that belongs to bree?

@titanism
Copy link
Contributor

New features and PR's always welcome. We don't use inline jobs because if one crashes then all crash on same process, which is why we did this with worker threads.

@naz
Copy link
Member Author

naz commented Apr 15, 2023

Awesome, thanks @titanism. Yes, you are spot on with the downside of inline jobs. It's a trade-off a developer would need to decide on when choosing a way to run their jobs 👍

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

No branches or pull requests

4 participants