Skip to content

Commit c0c99f5

Browse files
committed
Only spawn tasks if more than one core
1 parent cd1511b commit c0c99f5

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

‎lib/ecto/repo.ex‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,8 +1319,9 @@ defmodule Ecto.Repo do
13191319
are already loaded. By setting this option to true, any existing
13201320
association will be discarded and reloaded.
13211321
* `:in_parallel` - If the preloads must be done in parallel. It can
1322-
only be performed when we have more than one preload and the
1323-
repository is not in a transaction. Defaults to `true`.
1322+
only be performed when we have more than one preload, the repository
1323+
is not in a transaction, and the machine has more than one scheduler.
1324+
Defaults to `true`.
13241325
* `:prefix` - the prefix to fetch preloads from. By default, queries
13251326
will use the same prefix as the first struct in the given collection.
13261327
This option allows the prefix to be changed.

‎lib/ecto/repo/preloader.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ defmodule Ecto.Repo.Preloader do
151151
# Then we execute queries in parallel
152152
defp maybe_pmap(preloaders, _repo_name, {adapter_meta, opts}) do
153153
if match?([_, _ | _], preloaders) and not adapter_meta.adapter.checked_out?(adapter_meta) and
154-
Keyword.get(opts, :in_parallel, true) do
154+
Keyword.get(opts, :in_parallel, true) and System.schedulers_online() > 1 do
155155
# We pass caller: self() so the ownership pool knows where
156156
# to fetch the connection from and set the proper timeouts.
157157
# Note while the ownership pool uses '$callers' from pdict,

0 commit comments

Comments
 (0)