From 6ed4afcba3786b1a13fc4fd78302ece8d336f105 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Wed, 9 Dec 2020 02:36:52 +0100 Subject: [PATCH] CI: Better way of limiting CPU usage --- .github/workflows/ci.yaml | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9fd1646f2527..42c04ace63c0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,12 +9,26 @@ on: env: DOTTY_CI_RUN: true +# In this file, we set `--cpu-shares 4096` on every job. This might seem useless +# since it means that every container has the same weight which should be +# equivalent to doing nothing, but it turns out that OpenJDK computes +# `Runtime.getRuntime.availableProcessors` by dividing the cpu-shares value if +# it exists by 1024 (cf +# http://mail.openjdk.java.net/pipermail/hotspot-dev/2019-January/036087.html), +# so this means that we effectively run every job with 4 cores. This is much +# nicer than setting `--cpus 4` because the latter enforces CPU quotas and ends +# up slowing our jobs more than needed. It's equivalent to running the JVM with +# `-XX:ActiveProcessorCount=4`, but since our tests can spawn new JVM in many +# places, it would be very hard to ensure that this option is always passed to +# `java` (we could use the `_JAVA_OPTIONS` environment variable, but this prints +# text on stderr and so can break tests which check the output of a program). + jobs: test_non_bootstrapped: runs-on: [self-hosted, Linux] container: image: lampepfl/dotty:2020-11-19 - options: --cpus=4 + options: --cpu-shares 4096 volumes: - ${{ github.workspace }}/../../cache/sbt:/root/.sbt - ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache @@ -54,7 +68,7 @@ jobs: runs-on: [self-hosted, Linux] container: image: lampepfl/dotty:2020-11-19 - options: --cpus=4 + options: --cpu-shares 4096 volumes: - ${{ github.workspace }}/../../cache/sbt:/root/.sbt - ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache @@ -139,7 +153,7 @@ jobs: runs-on: [self-hosted, Linux] container: image: lampepfl/dotty:2020-11-19 - options: --cpus=4 + options: --cpu-shares 4096 volumes: - ${{ github.workspace }}/../../cache/sbt:/root/.sbt - ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache @@ -175,7 +189,7 @@ jobs: runs-on: [self-hosted, Linux] container: image: lampepfl/dotty:2020-11-19 - options: --cpus=4 + options: --cpu-shares 4096 volumes: - ${{ github.workspace }}/../../cache/sbt:/root/.sbt - ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache @@ -211,7 +225,7 @@ jobs: runs-on: [self-hosted, Linux] container: image: lampepfl/dotty:2020-11-19 - options: --cpus=4 + options: --cpu-shares 4096 volumes: - ${{ github.workspace }}/../../cache/sbt:/root/.sbt - ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache @@ -247,7 +261,7 @@ jobs: runs-on: [self-hosted, Linux] container: image: lampepfl/dotty:2020-11-19 - options: --cpus=4 + options: --cpu-shares 4096 volumes: - ${{ github.workspace }}/../../cache/sbt:/root/.sbt - ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache @@ -290,7 +304,7 @@ jobs: runs-on: [self-hosted, Linux] container: image: lampepfl/dotty:2020-11-19 - options: --cpus=4 + options: --cpu-shares 4096 volumes: - ${{ github.workspace }}/../../cache/sbt:/root/.sbt - ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache @@ -325,7 +339,7 @@ jobs: runs-on: [self-hosted, Linux] container: image: lampepfl/dotty:2020-11-19 - options: --cpus=4 + options: --cpu-shares 4096 volumes: - ${{ github.workspace }}/../../cache/sbt:/root/.sbt - ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache @@ -367,7 +381,7 @@ jobs: runs-on: [self-hosted, Linux] container: image: lampepfl/dotty:2020-11-19 - options: --cpus=4 + options: --cpu-shares 4096 volumes: - ${{ github.workspace }}/../../cache/sbt:/root/.sbt - ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache @@ -450,7 +464,7 @@ jobs: runs-on: [self-hosted, Linux] container: image: lampepfl/dotty:2020-11-19 - options: --cpus=4 + options: --cpu-shares 4096 volumes: - ${{ github.workspace }}/../../cache/sbt:/root/.sbt - ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache @@ -495,6 +509,7 @@ jobs: runs-on: [self-hosted, Linux] container: image: lampepfl/dotty:2020-11-19 + options: --cpu-shares 4096 volumes: - ${{ github.workspace }}/../../cache/sbt:/root/.sbt - ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache