We have a mid-sized project of roughly 75K lines of elixir code, spread over 500+ files.
When we compile this project on a 16 core machine, we can see in Grafana that only 4 cores are utilized at most. We would like to push this to at least 8 if possible.
The fascinating thing is that it caps out at 4 cores with no peaks beyond, making me wonder if there is some limit involved.
What controls how many cores are utilized and is there a cap, maximum, or default? I’ve been looking through compiler and mix documentation and have found nothing so far.
Elixir will use as many cores as there are scheduler threads available which defaults to the number of cores in your system.
Elixir will try to parallelize the compilation of individual files as much as possible, but any file’s compile time dependencies will have to be compiled before it which can limit the number of files that can be compiled in parallel. If you have many such dependencies in your project the compiler will not be able to use all cores.
Hi, @ericmj.
The machine is listed as having 16 virtual cores, being a cloud instance. Yet elixir only utilizes only 4 at any time.
I have hundreds of files, I doubt that there is no combination of 5 that can’t be compiled independently.
elixir release was 1.10.4. We can’t go forward beyond that right now for reasons having to do with the organization maintaining the infrastructure.
What system call or variables does elixir evaluate to determine how many cores to use for compilation? I could query those to learn more about why this happens.
So, in principle I could add a dozen or so .ex files with no external dependencies, all in the same folder. Would I expect the core utilization to go up, or is it less deterministic than that?
If it helps the experiment, I could generate some code to make sure compilation takes a while.
totally understandable - but do give it a go on latest stable elixir and perhaps even master, to see/check if there are any gains there, potentially the entire solution is there… (and yes deploying the “fix” will be a future thing then…)
While I don’t have control over the CI machine, maybe I could change the job script so that pulls in the elixir tarball, builds it, and then let it use that one instead of the one we have deployed. Maybe.