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

Dynamic pool implementation and process separation per worker id #10

Merged
merged 16 commits into from
Oct 14, 2024

Conversation

wavewave
Copy link
Collaborator

GHC compilation for different package modules needs to be separated to different GHC process for various reasons, such as safe dynamic linking / symbol finding and safe interface loading etc. So now each worker status is tagged with worker id and so jobs are distributed with the tag. Once done, the worker needs to be removed from the pool.
Therefore, this intrinsically introduces dynamic pool, spawning and terminating processes as demanded.
This PR implements such dynamic mechanism and worker-id based job distribution. Worker-id assignment per different haskell target is assumed from the build system rules.

@wavewave wavewave requested a review from tek October 11, 2024 13:50
Comment on lines 25 to 26
open f = E.bracketOnError (socket AF_UNIX Stream 0) close $ \sock -> do
bind sock (SockAddrUnix f)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
open f = E.bracketOnError (socket AF_UNIX Stream 0) close $ \sock -> do
bind sock (SockAddrUnix f)
open = E.bracketOnError (socket AF_UNIX Stream 0) close $ \sock -> do
bind sock (SockAddrUnix fp)

😅

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed. thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

oh I meant that you can use the top-level fp without passing it to open 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hah! right 🤣 !

hFlush stdout

getAssignableWorker :: IntMap (Bool, Maybe Id) -> Maybe Id -> Maybe (Int, (Bool, Maybe Id))
getAssignableWorker workers mid' = List.find (isAssignable . snd) . IM.toAscList $ workers
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, Foldable.find @IntMap searches in ascending key order 🙂

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks. Unfortunately, in this case, we need to get Key (= Int) as well, so I couldn't use find directly on the map. toAscList was simply to fuse that key as element.

writeTVar ref (pool {poolStatus = workers'})

removeWorker :: TVar Pool -> Id -> IO ()
removeWorker ref id' = do
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe mask this function? not sure if these processes get cleaned up reliably on interrupt

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks for the suggestion. now wrapped it minimally.

@wavewave wavewave merged commit b0f4579 into main Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants