Skip to content

Commit

Permalink
Add max_concurrent_runs setting (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikhuijzer authored Apr 11, 2022
1 parent cdbf335 commit 6c4d634
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PlutoStaticHTML"
uuid = "359b1769-a58e-495b-9770-312e911026ad"
authors = ["Rik Huijzer <[email protected]>"]
version = "5.0.1"
version = "5.0.2"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
50 changes: 34 additions & 16 deletions src/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,22 @@ end
html_output
end

const WRITE_FILES_DEFAULT = true
const PREVIOUS_DIR_DEFAULT = nothing
const OUTPUT_FORMAT_DEFAULT = html_output
const ADD_DOCUMENTER_CSS_DEFAULT = true
const USE_DISTRIBUTED_DEFAULT = true
const MAX_CONCURRENT_RUNS = 4

"""
BuildOptions(
dir::AbstractString;
write_files::Bool=true,
previous_dir::Union{Nothing,AbstractString}=nothing,
output_format::OutputFormat=html_output,
add_documenter_css::Bool=true,
use_distributed::Bool=true
write_files::Bool=$WRITE_FILES_DEFAULT,
previous_dir::Union{Nothing,AbstractString}=$PREVIOUS_DIR_DEFAULT,
output_format::OutputFormat=$OUTPUT_FORMAT_DEFAULT,
add_documenter_css::Bool=$ADD_DOCUMENTER_CSS_DEFAULT,
use_distributed::Bool=$USE_DISTRIBUTED_DEFAULT,
max_concurrent_runs::Int=$MAX_CONCURRENT_RUNS
)
Arguments:
Expand Down Expand Up @@ -53,6 +61,9 @@ Arguments:
By setting this option to `false`, all notebooks are built sequentially in the same process which avoids recompilation.
This is likely quicker in situations where there are few threads available such as GitHub Runners depending on the notebook contents.
Beware that `use_distributed=false` will not work with Pluto's built-in package manager.
- `max_concurrent_runs`:
Maximum number of notebooks to evaluate concurrently when `use_distributed=true`.
Note that each notebook starts in a different thread and can start multiple threads, so don't set this number too high.
"""
struct BuildOptions
dir::String
Expand All @@ -61,22 +72,25 @@ struct BuildOptions
output_format::OutputFormat
add_documenter_css::Bool
use_distributed::Bool
max_concurrent_runs::Int

function BuildOptions(
dir::AbstractString;
write_files::Bool=true,
previous_dir::Union{Nothing,AbstractString}=nothing,
output_format::OutputFormat=html_output,
add_documenter_css::Bool=true,
use_distributed::Bool=true
write_files::Bool=WRITE_FILES_DEFAULT,
previous_dir::Union{Nothing,AbstractString}=PREVIOUS_DIR_DEFAULT,
output_format::OutputFormat=OUTPUT_FORMAT_DEFAULT,
add_documenter_css::Bool=ADD_DOCUMENTER_CSS_DEFAULT,
use_distributed::Bool=USE_DISTRIBUTED_DEFAULT,
max_concurrent_runs::Int=MAX_CONCURRENT_RUNS
)
return new(
string(dir)::String,
write_files,
nothingstring(previous_dir),
output_format,
add_documenter_css,
use_distributed
use_distributed,
max_concurrent_runs
)
end
end
Expand Down Expand Up @@ -284,13 +298,17 @@ function _evaluate_file(bopts::BuildOptions, hopts::HTMLOptions, session, in_fil
end
end

"""
Evaluate `files` in parallel.
Using asynchronous tasks instead of multi-threading since Downloads is not thread-safe on Julia 1.6/1.7.
https://github.com/JuliaLang/Downloads.jl/issues/110.
"""
function _evaluate_parallel(bopts, hopts, session, files)
X = Vector{Any}(undef, length(files))
Threads.@threads :static for i in 1:length(files)
in_file = files[i]
X[i] = _evaluate_file(bopts, hopts, session, in_file)
ntasks = bopts.max_concurrent_runs
asyncmap(files; ntasks) do in_file
_evaluate_file(bopts, hopts, session, in_file)
end
return X
end

function _evaluate_sequential(bopts, hopts, session, files)
Expand Down

2 comments on commit 6c4d634

@rikhuijzer
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/58342

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v5.0.2 -m "<description of version>" 6c4d6348fdf89f15986b15192b8d7451960c0657
git push origin v5.0.2

Please sign in to comment.