-
Notifications
You must be signed in to change notification settings - Fork 696
[Poc] Use Background pool to get JobInfo from Ray Dashboard #4043
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
base: master
Are you sure you want to change the base?
Changes from all commits
4069033
45635be
72142c0
fe90e70
727d2c2
d9a1a88
0f1f766
da0e45e
afcb9e1
82b3acf
69be5fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,48 @@ | ||||||
| package dashboardclient | ||||||
|
|
||||||
| import ( | ||||||
| "sync" | ||||||
| ) | ||||||
|
|
||||||
| type WorkerPool struct { | ||||||
| taskQueue chan func() | ||||||
| stopChan chan struct{} | ||||||
| wg sync.WaitGroup | ||||||
| workers int | ||||||
| } | ||||||
|
|
||||||
| func NewWorkerPool(taskQueue chan func()) *WorkerPool { | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Passing a task queue channel is weird. Specifying a worker count is more understandable. You can also make a buffered channel based on the worker count internally. |
||||||
| wp := &WorkerPool{ | ||||||
| taskQueue: taskQueue, | ||||||
| workers: 10, | ||||||
| stopChan: make(chan struct{}), | ||||||
| } | ||||||
|
|
||||||
| // Start workers immediately | ||||||
| wp.start() | ||||||
| return wp | ||||||
| } | ||||||
|
|
||||||
| // Start launches worker goroutines to consume from queue | ||||||
| func (wp *WorkerPool) start() { | ||||||
| for i := 0; i < wp.workers; i++ { | ||||||
| wp.wg.Add(1) | ||||||
| go wp.worker() | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // worker consumes and executes tasks from the queue | ||||||
| func (wp *WorkerPool) worker() { | ||||||
| defer wp.wg.Done() | ||||||
|
|
||||||
| for { | ||||||
| select { | ||||||
| case <-wp.stopChan: | ||||||
| return | ||||||
| case task := <-wp.taskQueue: | ||||||
| if task != nil { | ||||||
| task() // Execute the job | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's actually an edge case.
Let's assume
jobIDitem fromjobInfoMapandworkerPool.channelContentr.workerPool.taskQueueIn this case, we shouldn't store the result.
However, it's hard to handle this edge case, and the data we store will be near 100 bytes, is it ok not to handle this?
(Let's do the calculation, let's say we have 100,000 RayJob CR, the most stale cache we can produce will be 10MB (100 bytes *100000)
I think the solution to handle this edge case is using another backgroud go routine to list all rayjob CR, and check is there any additional key in
jobInfoMap, and delete themcc @rueian @andrewsykim
need your two's advice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is not hard to avoid. We just need to put a placeholder into the map and only update the map if the placeholder exists.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And we also need to clear the jobInfoMap before each job retry and deletion.