senconscious

senconscious

What is the optimal --max-requires option for tests?

Hello everyone,
I have encountered a strange bottleneck when trying to run tests. The execution time of specific tests was increasing according to the number of schedulers online: each scheduler added about 100ms to the execution time.

CI Setup

I’m running CI tests using a GitLab runner on Amazon EC2 c6g instances. The runner has 32 CPUs.

Local Setup

8 CPUs, Mac M1.

Test Details

I have 2 partitions for tests, each with about 3.5k tests. Running the command:

MIX_TEST_PARTITION=1 elixir --erl "+S 8:8" -S mix test --partitions 2

The unstable test uses the test_server library to open a socket on a random port with plug_cowboy. There are no heavy computations inside the mocked request; it just responds with a hardcoded small JSON map. Two subsequent requests are made.

From the client side, I’m using Finch with Mint, with a pool size of 10.

Test Running Time

Below are the execution times for the unstable test when running locally on 8 CPUs:

| Single       | 20ms  |
|--------------|-------|
| During suite | 800ms |

I then experimented with the number of schedulers:

| 1 scheduler  | ~100ms |
|--------------|--------|
| 2 schedulers | ~200ms |
| 3 schedulers | ~300ms |
| 8 schedulers | ~800ms |

Telemetry

To find the cause, I attached telemetry to finch and cowboy:

finch.queue.stop duration: 388ms : idle time: 0ms
finch.connect.stop duration: 982ms
finch.send.stop duration: 395ms : idle time: 0ms
cowboy.request.stop duration: 1916ms : req_body_duration: 0ms : resp_duration: 0ms
finch.recv.stop duration: 3248ms : idle time: 0ms
finch.request.stop duration: 5608ms

Given that no work is done inside dispatching except Plug.Conn.send_resp/3, this seemed very strange.

Running fprof

{ suspend,                                      70,  680.139,    0.000},     %
 [ ]}.

{[{{error_handler,undefined_function,3},          1,  659.626,    0.003},      
  {{'Elixir.Acme.Operations.SF.IN.SyncServiceContracts',
    request_page,2},   1,   10.840,    0.002}],     

....


 { {code_server,call,1},                         30,  383.299,    0.411},     %
 [{suspend,                                      33,  382.695,    0.000},      
  {{erlang,demonitor,2},                         30,    0.152,    0.119},      
  {{erlang,monitor,2},                           30,    0.041,    0.041}]}.    

{[{{error_handler,undefined_function,3},         19,  360.224,    0.044}],     

These are the most expensive nodes in the whole fprof logs. It seems the process gets descheduled and was suspended most of the time while code was loading into the memory inside Mix.Compilers.Test

Researching Similar Issue

After a while, I found a discussion and tried explicitly setting the max-requires option. It turns out that on 8 CPUs, the test ran in less than 100ms with max-requires set to 100. In Elixir core, it defaults to the maximum between the system schedulers online and 2.

However, the docs lack details about how this parameter can affect test execution time. Maybe someone can help explain the algorithm for calibrating it?

Where Next?

Popular in Questions Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement