mirror of
https://github.com/fluencelabs/aquavm
synced 2024-12-04 15:20:16 +00:00
Use pooled AVMRunner for tests
Use pooled `avm::server::AVMRunner` instances of air_iterpreter_server.wasm to reduce tests' running time. It avoids repeated WASM loading and compilation. On my hardware, `cargo test --release` execution time (precompiled) decreases from almost 6 minutes to 1.5 minutes.
This commit is contained in:
parent
da95089513
commit
dcfa51c756
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -142,6 +142,8 @@ dependencies = [
|
|||||||
"avm-server",
|
"avm-server",
|
||||||
"fstrings",
|
"fstrings",
|
||||||
"marine-rs-sdk",
|
"marine-rs-sdk",
|
||||||
|
"object-pool",
|
||||||
|
"once_cell",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1494,6 +1496,15 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "object-pool"
|
||||||
|
version = "0.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ee9a3e7196d09ec86002b939f1576e8e446d58def8fd48fe578e2c72d5328d68"
|
||||||
|
dependencies = [
|
||||||
|
"parking_lot 0.11.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.10.0"
|
version = "1.10.0"
|
||||||
|
@ -13,7 +13,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "air"
|
name = "air"
|
||||||
version = "0.21.0"
|
version = "0.24.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"air-execution-info-collector",
|
"air-execution-info-collector",
|
||||||
"air-interpreter-data",
|
"air-interpreter-data",
|
||||||
@ -25,9 +25,11 @@ dependencies = [
|
|||||||
"air-trace-handler",
|
"air-trace-handler",
|
||||||
"boolinator",
|
"boolinator",
|
||||||
"concat-idents",
|
"concat-idents",
|
||||||
|
"fstrings",
|
||||||
"log",
|
"log",
|
||||||
"maplit",
|
"maplit",
|
||||||
"marine-rs-sdk",
|
"marine-rs-sdk",
|
||||||
|
"non-empty-vec",
|
||||||
"polyplets 0.2.0",
|
"polyplets 0.2.0",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@ -53,7 +55,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "air-interpreter-interface"
|
name = "air-interpreter-interface"
|
||||||
version = "0.8.0"
|
version = "0.10.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence-it-types",
|
"fluence-it-types",
|
||||||
"marine-rs-sdk",
|
"marine-rs-sdk",
|
||||||
@ -306,6 +308,28 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fstrings"
|
||||||
|
version = "0.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7845a0f15da505ac36baad0486612dab57f8b8d34e19c5470a265bbcdd572ae6"
|
||||||
|
dependencies = [
|
||||||
|
"fstrings-proc-macro",
|
||||||
|
"proc-macro-hack",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fstrings-proc-macro"
|
||||||
|
version = "0.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "63b58c0e7581dc33478a32299182cbe5ae3b8c028be26728a47fb0a113c92d9d"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro-hack",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
@ -594,6 +618,12 @@ version = "0.1.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
|
checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro-hack"
|
||||||
|
version = "0.5.19"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.26"
|
version = "1.0.26"
|
||||||
|
@ -13,7 +13,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "air"
|
name = "air"
|
||||||
version = "0.21.0"
|
version = "0.24.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"air-execution-info-collector",
|
"air-execution-info-collector",
|
||||||
"air-interpreter-data",
|
"air-interpreter-data",
|
||||||
@ -25,9 +25,11 @@ dependencies = [
|
|||||||
"air-trace-handler",
|
"air-trace-handler",
|
||||||
"boolinator",
|
"boolinator",
|
||||||
"concat-idents",
|
"concat-idents",
|
||||||
|
"fstrings",
|
||||||
"log",
|
"log",
|
||||||
"maplit",
|
"maplit",
|
||||||
"marine-rs-sdk",
|
"marine-rs-sdk",
|
||||||
|
"non-empty-vec",
|
||||||
"polyplets 0.2.0",
|
"polyplets 0.2.0",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@ -53,7 +55,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "air-interpreter-interface"
|
name = "air-interpreter-interface"
|
||||||
version = "0.8.0"
|
version = "0.10.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence-it-types",
|
"fluence-it-types",
|
||||||
"marine-rs-sdk",
|
"marine-rs-sdk",
|
||||||
@ -298,6 +300,28 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fstrings"
|
||||||
|
version = "0.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7845a0f15da505ac36baad0486612dab57f8b8d34e19c5470a265bbcdd572ae6"
|
||||||
|
dependencies = [
|
||||||
|
"fstrings-proc-macro",
|
||||||
|
"proc-macro-hack",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fstrings-proc-macro"
|
||||||
|
version = "0.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "63b58c0e7581dc33478a32299182cbe5ae3b8c028be26728a47fb0a113c92d9d"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro-hack",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
@ -594,6 +618,12 @@ version = "0.1.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
|
checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro-hack"
|
||||||
|
version = "0.5.19"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.26"
|
version = "1.0.26"
|
||||||
|
@ -110,6 +110,11 @@ impl AVMRunner {
|
|||||||
max_memory_size: stats[0].max_memory_size,
|
max_memory_size: stats[0].max_memory_size,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn set_peer_id(&mut self, current_peer_id: impl Into<String>) {
|
||||||
|
self.current_peer_id = current_peer_id.into();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prepare_args(
|
fn prepare_args(
|
||||||
|
@ -20,4 +20,6 @@ avm-server = { path = "../../../avm/server" }
|
|||||||
marine-rs-sdk = "0.6.15"
|
marine-rs-sdk = "0.6.15"
|
||||||
|
|
||||||
fstrings = "0.2.3"
|
fstrings = "0.2.3"
|
||||||
|
object-pool = "0.5.4"
|
||||||
|
once_cell = "1.10.0"
|
||||||
serde_json = "1.0.61"
|
serde_json = "1.0.61"
|
||||||
|
@ -17,18 +17,33 @@
|
|||||||
use super::CallServiceClosure;
|
use super::CallServiceClosure;
|
||||||
use avm_server::avm_runner::*;
|
use avm_server::avm_runner::*;
|
||||||
|
|
||||||
|
use once_cell::sync::OnceCell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
// 10 Mb
|
// 10 Mb
|
||||||
const AVM_MAX_HEAP_SIZE: u64 = 10 * 1024 * 1024;
|
const AVM_MAX_HEAP_SIZE: u64 = 10 * 1024 * 1024;
|
||||||
|
const AIR_WASM_PATH: &str = "../target/wasm32-wasi/debug/air_interpreter_server.wasm";
|
||||||
|
|
||||||
pub struct TestRunner {
|
pub struct TestRunner {
|
||||||
pub runner: AVMRunner,
|
pub runner: object_pool::Reusable<'static, AVMRunner>,
|
||||||
pub call_service: CallServiceClosure,
|
pub call_service: CallServiceClosure,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn make_pooled_avm_runner() -> AVMRunner {
|
||||||
|
let fake_current_peer_id = "";
|
||||||
|
let logging_mask = i32::MAX;
|
||||||
|
|
||||||
|
AVMRunner::new(
|
||||||
|
PathBuf::from(AIR_WASM_PATH),
|
||||||
|
fake_current_peer_id,
|
||||||
|
Some(AVM_MAX_HEAP_SIZE),
|
||||||
|
logging_mask,
|
||||||
|
)
|
||||||
|
.expect("vm should be created")
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct TestRunParameters {
|
pub struct TestRunParameters {
|
||||||
pub init_peer_id: String,
|
pub init_peer_id: String,
|
||||||
@ -97,17 +112,19 @@ pub fn create_avm(
|
|||||||
call_service: CallServiceClosure,
|
call_service: CallServiceClosure,
|
||||||
current_peer_id: impl Into<String>,
|
current_peer_id: impl Into<String>,
|
||||||
) -> TestRunner {
|
) -> TestRunner {
|
||||||
let air_wasm_path = PathBuf::from("../target/wasm32-wasi/debug/air_interpreter_server.wasm");
|
static POOL_CELL: OnceCell<object_pool::Pool<AVMRunner>> = OnceCell::new();
|
||||||
let current_peer_id = current_peer_id.into();
|
|
||||||
let logging_mask = i32::MAX;
|
let pool = POOL_CELL.get_or_init(|| {
|
||||||
|
object_pool::Pool::new(
|
||||||
|
// we create an empty pool and let it fill on demand
|
||||||
|
0,
|
||||||
|
|| unreachable!(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut runner = pool.pull(make_pooled_avm_runner);
|
||||||
|
runner.set_peer_id(current_peer_id);
|
||||||
|
|
||||||
let runner = AVMRunner::new(
|
|
||||||
air_wasm_path,
|
|
||||||
current_peer_id,
|
|
||||||
Some(AVM_MAX_HEAP_SIZE),
|
|
||||||
logging_mask,
|
|
||||||
)
|
|
||||||
.expect("vm should be created");
|
|
||||||
TestRunner {
|
TestRunner {
|
||||||
runner,
|
runner,
|
||||||
call_service,
|
call_service,
|
||||||
|
Loading…
Reference in New Issue
Block a user