Skip to content

Add --semaphore flag to enable interaction with GHC Job Server… #8557

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

Closed
wants to merge 11 commits into from

Conversation

mpickering
Copy link
Collaborator

… (-jsem)

This is a WIP patch which allows testing GHC jobserver (-jsem) using cabal. When --semaphore is passed to cabal-install then cabal will create a semaphore with the number of capabilities suggested by -j and then use this semaphore to mediate parallelism between GHC processes.

@ulysses4ever ulysses4ever marked this pull request as draft February 7, 2023 03:06
@mpickering mpickering force-pushed the wip/jsem branch 2 times, most recently from 3a6312e to 5563a57 Compare March 16, 2023 12:11
res <- try job `finally` releaseSemaphore sem 1
atomically $ writeTChan outqVar res
-- Wait for spawned process to take some capabilities if it wants some
threadDelay 1_000_000
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there any sense in making this configurable? Have you experimented with different values?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think so.. I didn't try any different values. I think just something non-zero is good and not so small to prevent thrashing.

@mpickering
Copy link
Collaborator Author

Updated based on @sheaf s comments now

  • Made the semaphore name fresh, so that you can run multiple cabal processes at once.
  • Parametrised the ParStrat type so it can be used by cabal-install and Cabal
  • Fixed the logic taking/returning semaphores to correctly handle async exceptions (thanks @sheaf for discussing this with me)

@mpickering
Copy link
Collaborator Author

Testing this feature will have to wait because there isn't a released compiler yet which supports -jsem.

@mpickering mpickering changed the title WIP: Add --semaphore flag to enable interaction with GHC Job Server… Add --semaphore flag to enable interaction with GHC Job Server… Mar 21, 2023
@mpickering mpickering marked this pull request as ready for review March 22, 2023 11:40
@mpickering mpickering force-pushed the wip/jsem branch 2 times, most recently from 95c8d6a to 660d45c Compare March 22, 2023 11:52
@mpickering mpickering force-pushed the wip/jsem branch 2 times, most recently from 5c4fd97 to 1d74397 Compare March 22, 2023 13:57
@fgaz
Copy link
Member

fgaz commented Mar 23, 2023

This will close #976, right?

, option [] ["semaphore"]
"Use a semaphore so GHC can compile components in parallel"
installUseSemaphore (\v flags -> flags { installUseSemaphore = v })
trueArg
Copy link
Member

@fgaz fgaz Mar 23, 2023

Choose a reason for hiding this comment

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

maybe this should be a boolOpt, so it can be enabled or disabled in the global or project config (I assume we'll enable this by default after the next release if not in this pr)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed this to boolOpt.

I am not sure how to go about enabling it by default because you would also need a very new version of GHC, at the moment if it's enabled and you use an older version of GHC then you get an error (rather than falling back to old behaviour).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I implemented it now so that if you use an older compiler and pass --sempahore then you get a warning about falling back to old behaviour but things still work. That way it can be enabled globally without too much hassle.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I actually changed the option to a yesNoOpt which seemed to fit in better.. and also hopefully fixes some failing roundtrip tests I couldn't work out how to fix.

@mpickering
Copy link
Collaborator Author

mpickering commented Mar 23, 2023

This will close #976, right?

It seems related to #976... but there are lots of ideas there and the idea of using one shot mode could still be implemented and give better parallelism results.

@mpickering mpickering force-pushed the wip/jsem branch 4 times, most recently from 8cb82fb to 3303449 Compare March 23, 2023 11:32
@mpickering
Copy link
Collaborator Author

As a data point, using this feature to compile exe:cabal in the cabal repo halved the build time.

@mpickering mpickering force-pushed the wip/jsem branch 3 times, most recently from a7331a8 to 5c6c4ce Compare March 23, 2023 15:11
@mpickering
Copy link
Collaborator Author

CI is passing now :)

@Kleidukos Kleidukos force-pushed the wip/jsem branch 2 times, most recently from 959c4a2 to d63ae09 Compare July 11, 2023 21:12
@Kleidukos
Copy link
Member

@sheaf @fgaz ok I believe we're good now but I'd highly appreciate a last review from you so that we can conclude this saga. :)

@Kleidukos Kleidukos removed attention: needs-help Help wanted with this issue/PR attention: needs-rebase labels Jul 13, 2023
mpickering and others added 9 commits July 14, 2023 11:11
* The top-level user interface to enable the use of the semaphore is the
  `--semaphore` flag. If you pass `-j4 --semaphore` then cabal will
  create a semaphore with 4 slots which is passed to ghc using the
  `-jsem` option so that all GHC processes coordinate to use 4
  capabilities.

  - The semaphore logic is provided by a new package `semaphore-compat`
    which provides a cross-platform abstraction for semaphores.

* The low level `./Setup.hs build` interface accepts the `--semaphore
  <SEMAPHORE>` option, which can be used to directly pass the semaphore
  you require to the Setup script.
@Kleidukos Kleidukos force-pushed the wip/jsem branch 2 times, most recently from 7fbfb0f to 25e00c3 Compare July 14, 2023 09:17
Copy link
Collaborator

@ffaf1 ffaf1 left a comment

Choose a reason for hiding this comment

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

Good as far as I can see!

@Kleidukos
Copy link
Member

@Mergifyio backport 3.10

@mergify
Copy link
Contributor

mergify bot commented Jul 14, 2023

backport 3.10

🟠 Waiting for conditions to match

  • merged [:pushpin: backport requirement]

@Kleidukos Kleidukos added the squash+merge me Tell Mergify Bot to squash-merge label Jul 14, 2023
@mergify mergify bot added the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label Jul 16, 2023
@ulysses4ever
Copy link
Collaborator

GitHub needed a rebase and I pushed the button. Results are not hopeful:

  • one lint failure
  • one actual failure because of a change to the options interface

@bgamari
Copy link
Contributor

bgamari commented Jul 18, 2023

I have rebased this and opened #9139 proposing merge.

@andreabedini
Copy link
Collaborator

I understand this was subsumed by #9139 which is now merged. Please reopen if I am mistaken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
attention: needs-review merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days squash+merge me Tell Mergify Bot to squash-merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants