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

Flow: bigger priority or fifo for jobs after going back from waiting-children to waiting when using the WaitingChildrenError to generate children #1899

Closed
sven-codeculture opened this issue May 15, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@sven-codeculture
Copy link
Contributor

sven-codeculture commented May 15, 2023

Is your feature request related to a problem? Please describe.
We have currently refactored our workflow to initialize a customer to use the flow as described here:
https://docs.bullmq.io/patterns/process-step-jobs#waiting-children
We first run a job, which adds the required children and then throws a WaitingChildrenException. This jobs all have children too and use the same mechanic too. (There are usally 3 steps, create customer, fetch all data for a specific data type, do a job for each fetched data and add it to the database)
This all works like a charm when only initializing a small bunch of customers at the same time, however when doing something like a re-initialize of all customers (which we sometimes require to do) this comes up to about 80 million jobs ran in the end.
Flow

Due to the fact, that the parent gets added at the end of the queue with the same priority as the parents who still have to create its children, this causes to swell the required redis memory over time and at some point redis (we use AWS elasticache) runs out of memory and everything starts failing.

Describe the solution you'd like
The best way would be a possibility for flow parents to optionally change their priority when they move from waiting-children back to waiting. Also putting them as fifo when they get into waiting queue a second time.

Describe alternatives you've considered
As a current workaround we had to limit the amount of customers initializing at the same time. This works as a workaround, however we always lose some time at the end of the number x customers initializing due to the fact that our cron checking if update/initializing is required only runs once every 5 minutes due to API limits.

Additional context
Using fifo directly is not an option. We run jobs with different priorities to make sure all child-data are processed before the next parent is touched, to prevent a memory overflow in redis.

PS: if required i can try to find some time implementing this and creating a PR, however want the OK that this logic would be ok for the bullmq project owners

@roggervalf
Copy link
Collaborator

roggervalf commented May 16, 2023

hi @sven-codeculture, reading your case I'm thinking on a new method, something like changePriority that could be called in your case before moving the parent to waiting-children for example

@roggervalf roggervalf added the enhancement New feature or request label May 16, 2023
github-actions bot pushed a commit that referenced this issue May 31, 2023
# [3.15.0](v3.14.2...v3.15.0) (2023-05-31)

### Features

* **job:** add changePriority method ([#1901](#1901)) ref [#1899](#1899) ([9485ad5](9485ad5))
@roggervalf
Copy link
Collaborator

changePriority method is available since version 3.15.0

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

2 participants