Skip to content

Commit

Permalink
Nitishm/enhancement/42/module config concurrency param (#107)
Browse files Browse the repository at this point in the history
Add http_concurrency option to modules config
  • Loading branch information
nitishm authored Aug 17, 2021
1 parent 8043ae8 commit b0e3402
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
wagi-cache/
/ssl-example.*
.vscode/
_scratch/
_scratch/
1 change: 1 addition & 0 deletions examples/modules.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module = "examples/hello.wasm"
route = "/http-example"
module = "examples/http-example.wasm"
allowed_hosts = ["https://api.brigade.sh"]
http_max_concurrency = 2

[[module]]
# Example error.
Expand Down
1 change: 1 addition & 0 deletions src/runtime/bindle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ fn wagi_features(inv_id: &Id, parcel: &Parcel) -> Module {
route,
allowed_hosts,
volumes: None,
http_max_concurrency: None,
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ pub struct Module {
/// If none or an empty vector is supplied, the guest module cannot send
/// requests to any server.
pub allowed_hosts: Option<Vec<String>>,

/// Max http concurrency that the guest module configures for the HTTP
/// client. If none, the guest module uses the default concurrency provided
/// by the WASM HTTP client module.
pub http_max_concurrency: Option<u32>,
}

// For hashing, we don't need all of the fields to hash. A wasm module (not a `Module`) can be used
Expand Down Expand Up @@ -142,6 +147,7 @@ impl Module {
entrypoint: None,
allowed_hosts: None,
bindle_server: None,
http_max_concurrency: None,
}
}

Expand Down Expand Up @@ -595,7 +601,7 @@ impl Module {
let mut linker = Linker::new(&engine);
wasmtime_wasi::add_to_linker(&mut linker, |cx| cx)?;

let http = wasi_experimental_http_wasmtime::HttpCtx::new(self.allowed_hosts.clone(), None)?;
let http = wasi_experimental_http_wasmtime::HttpCtx::new(self.allowed_hosts.clone(), self.http_max_concurrency.clone())?;
http.add_to_linker(&mut linker)?;

let module = self.load_cached_module(&store, &info.module_cache_dir)?;
Expand Down Expand Up @@ -964,7 +970,6 @@ mod test {

let log_tempdir = tempfile::tempdir().expect("Unable to create tempdir");
let cache_tempdir = tempfile::tempdir().expect("new cache temp dir");

mc.build_registry(&cache, cache_tempdir.path(), log_tempdir.path())
.await
.expect("registry build cleanly");
Expand Down

0 comments on commit b0e3402

Please sign in to comment.