Skip to content

Commit 6ed4afc

Browse files
committed
CI: Better way of limiting CPU usage
1 parent f334e3f commit 6ed4afc

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

.github/workflows/ci.yaml

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,26 @@ on:
99
env:
1010
DOTTY_CI_RUN: true
1111

12+
# In this file, we set `--cpu-shares 4096` on every job. This might seem useless
13+
# since it means that every container has the same weight which should be
14+
# equivalent to doing nothing, but it turns out that OpenJDK computes
15+
# `Runtime.getRuntime.availableProcessors` by dividing the cpu-shares value if
16+
# it exists by 1024 (cf
17+
# http://mail.openjdk.java.net/pipermail/hotspot-dev/2019-January/036087.html),
18+
# so this means that we effectively run every job with 4 cores. This is much
19+
# nicer than setting `--cpus 4` because the latter enforces CPU quotas and ends
20+
# up slowing our jobs more than needed. It's equivalent to running the JVM with
21+
# `-XX:ActiveProcessorCount=4`, but since our tests can spawn new JVM in many
22+
# places, it would be very hard to ensure that this option is always passed to
23+
# `java` (we could use the `_JAVA_OPTIONS` environment variable, but this prints
24+
# text on stderr and so can break tests which check the output of a program).
25+
1226
jobs:
1327
test_non_bootstrapped:
1428
runs-on: [self-hosted, Linux]
1529
container:
1630
image: lampepfl/dotty:2020-11-19
17-
options: --cpus=4
31+
options: --cpu-shares 4096
1832
volumes:
1933
- ${{ github.workspace }}/../../cache/sbt:/root/.sbt
2034
- ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache
@@ -54,7 +68,7 @@ jobs:
5468
runs-on: [self-hosted, Linux]
5569
container:
5670
image: lampepfl/dotty:2020-11-19
57-
options: --cpus=4
71+
options: --cpu-shares 4096
5872
volumes:
5973
- ${{ github.workspace }}/../../cache/sbt:/root/.sbt
6074
- ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache
@@ -139,7 +153,7 @@ jobs:
139153
runs-on: [self-hosted, Linux]
140154
container:
141155
image: lampepfl/dotty:2020-11-19
142-
options: --cpus=4
156+
options: --cpu-shares 4096
143157
volumes:
144158
- ${{ github.workspace }}/../../cache/sbt:/root/.sbt
145159
- ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache
@@ -175,7 +189,7 @@ jobs:
175189
runs-on: [self-hosted, Linux]
176190
container:
177191
image: lampepfl/dotty:2020-11-19
178-
options: --cpus=4
192+
options: --cpu-shares 4096
179193
volumes:
180194
- ${{ github.workspace }}/../../cache/sbt:/root/.sbt
181195
- ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache
@@ -211,7 +225,7 @@ jobs:
211225
runs-on: [self-hosted, Linux]
212226
container:
213227
image: lampepfl/dotty:2020-11-19
214-
options: --cpus=4
228+
options: --cpu-shares 4096
215229
volumes:
216230
- ${{ github.workspace }}/../../cache/sbt:/root/.sbt
217231
- ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache
@@ -247,7 +261,7 @@ jobs:
247261
runs-on: [self-hosted, Linux]
248262
container:
249263
image: lampepfl/dotty:2020-11-19
250-
options: --cpus=4
264+
options: --cpu-shares 4096
251265
volumes:
252266
- ${{ github.workspace }}/../../cache/sbt:/root/.sbt
253267
- ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache
@@ -290,7 +304,7 @@ jobs:
290304
runs-on: [self-hosted, Linux]
291305
container:
292306
image: lampepfl/dotty:2020-11-19
293-
options: --cpus=4
307+
options: --cpu-shares 4096
294308
volumes:
295309
- ${{ github.workspace }}/../../cache/sbt:/root/.sbt
296310
- ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache
@@ -325,7 +339,7 @@ jobs:
325339
runs-on: [self-hosted, Linux]
326340
container:
327341
image: lampepfl/dotty:2020-11-19
328-
options: --cpus=4
342+
options: --cpu-shares 4096
329343
volumes:
330344
- ${{ github.workspace }}/../../cache/sbt:/root/.sbt
331345
- ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache
@@ -367,7 +381,7 @@ jobs:
367381
runs-on: [self-hosted, Linux]
368382
container:
369383
image: lampepfl/dotty:2020-11-19
370-
options: --cpus=4
384+
options: --cpu-shares 4096
371385
volumes:
372386
- ${{ github.workspace }}/../../cache/sbt:/root/.sbt
373387
- ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache
@@ -450,7 +464,7 @@ jobs:
450464
runs-on: [self-hosted, Linux]
451465
container:
452466
image: lampepfl/dotty:2020-11-19
453-
options: --cpus=4
467+
options: --cpu-shares 4096
454468
volumes:
455469
- ${{ github.workspace }}/../../cache/sbt:/root/.sbt
456470
- ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache
@@ -495,6 +509,7 @@ jobs:
495509
runs-on: [self-hosted, Linux]
496510
container:
497511
image: lampepfl/dotty:2020-11-19
512+
options: --cpu-shares 4096
498513
volumes:
499514
- ${{ github.workspace }}/../../cache/sbt:/root/.sbt
500515
- ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache

0 commit comments

Comments
 (0)