-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Large memory usage test cases and benchmarks (#619)
* Large memory usage test cases and benchmarks * Ignore
- Loading branch information
Showing
18 changed files
with
471 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
integration-tests/src/benchmarks/large_dynamic_memory.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// Copyright 2024 Golem Cloud | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::time::SystemTime; | ||
|
||
use async_trait::async_trait; | ||
|
||
use golem_test_framework::config::{CliParams, TestDependencies}; | ||
use golem_test_framework::dsl::benchmark::{Benchmark, BenchmarkRecorder, RunConfig}; | ||
use golem_test_framework::dsl::TestDsl; | ||
use integration_tests::benchmarks::{ | ||
cleanup_iteration, run_benchmark, setup_benchmark, setup_iteration, BenchmarkContext, | ||
IterationContext, | ||
}; | ||
|
||
struct LargeDynamicMemory { | ||
config: RunConfig, | ||
} | ||
|
||
#[async_trait] | ||
impl Benchmark for LargeDynamicMemory { | ||
type BenchmarkContext = BenchmarkContext; | ||
type IterationContext = IterationContext; | ||
|
||
fn name() -> &'static str { | ||
"large-dynamic-memory" | ||
} | ||
|
||
async fn create_benchmark_context( | ||
params: CliParams, | ||
cluster_size: usize, | ||
) -> Self::BenchmarkContext { | ||
setup_benchmark(params, cluster_size).await | ||
} | ||
|
||
async fn cleanup(benchmark_context: Self::BenchmarkContext) { | ||
benchmark_context.deps.kill_all() | ||
} | ||
|
||
async fn create(_params: CliParams, config: RunConfig) -> Self { | ||
Self { config } | ||
} | ||
|
||
async fn setup_iteration( | ||
&self, | ||
benchmark_context: &Self::BenchmarkContext, | ||
) -> Self::IterationContext { | ||
setup_iteration( | ||
benchmark_context, | ||
self.config.clone(), | ||
"large-initial-memory", | ||
false, | ||
) | ||
.await | ||
} | ||
|
||
async fn warmup( | ||
&self, | ||
benchmark_context: &Self::BenchmarkContext, | ||
context: &Self::IterationContext, | ||
) { | ||
if let Some(worker_id) = context.worker_ids.first() { | ||
let start = SystemTime::now(); | ||
benchmark_context | ||
.deps | ||
.invoke_and_await(worker_id, "run", vec![]) | ||
.await | ||
.expect("invoke_and_await failed"); | ||
let elapsed = start.elapsed().expect("SystemTime elapsed failed"); | ||
println!("Warmup invocation took {:?}", elapsed); | ||
} | ||
} | ||
|
||
async fn run( | ||
&self, | ||
benchmark_context: &Self::BenchmarkContext, | ||
context: &Self::IterationContext, | ||
recorder: BenchmarkRecorder, | ||
) { | ||
// Start each worker and invoke `run` - each worker takes an initial 512Mb memory | ||
let mut fibers = Vec::new(); | ||
for (n, worker_id) in context.worker_ids.iter().enumerate() { | ||
let context_clone = benchmark_context.clone(); | ||
let worker_id_clone = worker_id.clone(); | ||
let recorder_clone = recorder.clone(); | ||
let fiber = tokio::task::spawn(async move { | ||
let start = SystemTime::now(); | ||
context_clone | ||
.deps | ||
.invoke_and_await(&worker_id_clone, "run", vec![]) | ||
.await | ||
.expect("invoke_and_await failed"); | ||
let elapsed = start.elapsed().expect("SystemTime elapsed failed"); | ||
recorder_clone.duration(&"invocation".to_string(), elapsed); | ||
recorder_clone.duration(&format!("worker-{n}"), elapsed); | ||
}); | ||
fibers.push(fiber); | ||
} | ||
|
||
for fiber in fibers { | ||
fiber.await.expect("fiber failed"); | ||
} | ||
} | ||
|
||
async fn cleanup_iteration( | ||
&self, | ||
benchmark_context: &Self::BenchmarkContext, | ||
context: Self::IterationContext, | ||
) { | ||
cleanup_iteration(benchmark_context, context).await | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
run_benchmark::<LargeDynamicMemory>().await; | ||
} |
128 changes: 128 additions & 0 deletions
128
integration-tests/src/benchmarks/large_initial_memory.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// Copyright 2024 Golem Cloud | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::time::SystemTime; | ||
|
||
use async_trait::async_trait; | ||
|
||
use golem_test_framework::config::{CliParams, TestDependencies}; | ||
use golem_test_framework::dsl::benchmark::{Benchmark, BenchmarkRecorder, RunConfig}; | ||
use golem_test_framework::dsl::TestDsl; | ||
use integration_tests::benchmarks::{ | ||
cleanup_iteration, run_benchmark, setup_benchmark, setup_iteration, BenchmarkContext, | ||
IterationContext, | ||
}; | ||
|
||
struct LargeInitialMemory { | ||
config: RunConfig, | ||
} | ||
|
||
#[async_trait] | ||
impl Benchmark for LargeInitialMemory { | ||
type BenchmarkContext = BenchmarkContext; | ||
type IterationContext = IterationContext; | ||
|
||
fn name() -> &'static str { | ||
"large-initial-memory" | ||
} | ||
|
||
async fn create_benchmark_context( | ||
params: CliParams, | ||
cluster_size: usize, | ||
) -> Self::BenchmarkContext { | ||
setup_benchmark(params, cluster_size).await | ||
} | ||
|
||
async fn cleanup(benchmark_context: Self::BenchmarkContext) { | ||
benchmark_context.deps.kill_all() | ||
} | ||
|
||
async fn create(_params: CliParams, config: RunConfig) -> Self { | ||
Self { config } | ||
} | ||
|
||
async fn setup_iteration( | ||
&self, | ||
benchmark_context: &Self::BenchmarkContext, | ||
) -> Self::IterationContext { | ||
setup_iteration( | ||
benchmark_context, | ||
self.config.clone(), | ||
"large-initial-memory", | ||
false, | ||
) | ||
.await | ||
} | ||
|
||
async fn warmup( | ||
&self, | ||
benchmark_context: &Self::BenchmarkContext, | ||
context: &Self::IterationContext, | ||
) { | ||
if let Some(worker_id) = context.worker_ids.first() { | ||
let start = SystemTime::now(); | ||
benchmark_context | ||
.deps | ||
.invoke_and_await(worker_id, "run", vec![]) | ||
.await | ||
.expect("invoke_and_await failed"); | ||
let elapsed = start.elapsed().expect("SystemTime elapsed failed"); | ||
println!("Warmup invocation took {:?}", elapsed); | ||
} | ||
} | ||
|
||
async fn run( | ||
&self, | ||
benchmark_context: &Self::BenchmarkContext, | ||
context: &Self::IterationContext, | ||
recorder: BenchmarkRecorder, | ||
) { | ||
// Start each worker and invoke `run` - each worker takes an initial 512Mb memory | ||
let mut fibers = Vec::new(); | ||
for (n, worker_id) in context.worker_ids.iter().enumerate() { | ||
let context_clone = benchmark_context.clone(); | ||
let worker_id_clone = worker_id.clone(); | ||
let recorder_clone = recorder.clone(); | ||
let fiber = tokio::task::spawn(async move { | ||
let start = SystemTime::now(); | ||
context_clone | ||
.deps | ||
.invoke_and_await(&worker_id_clone, "run", vec![]) | ||
.await | ||
.expect("invoke_and_await failed"); | ||
let elapsed = start.elapsed().expect("SystemTime elapsed failed"); | ||
recorder_clone.duration(&"invocation".to_string(), elapsed); | ||
recorder_clone.duration(&format!("worker-{n}"), elapsed); | ||
}); | ||
fibers.push(fiber); | ||
} | ||
|
||
for fiber in fibers { | ||
fiber.await.expect("fiber failed"); | ||
} | ||
} | ||
|
||
async fn cleanup_iteration( | ||
&self, | ||
benchmark_context: &Self::BenchmarkContext, | ||
context: Self::IterationContext, | ||
) { | ||
cleanup_iteration(benchmark_context, context).await | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
run_benchmark::<LargeInitialMemory>().await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Generated by `wit-bindgen` 0.26.0. DO NOT EDIT! | ||
#include "c_api1.h" | ||
#include <stdlib.h> | ||
|
||
// Exported Functions from `c-api1` | ||
|
||
|
||
// Canonical ABI intrinsics | ||
|
||
__attribute__((__weak__, __export_name__("cabi_realloc"))) | ||
void *cabi_realloc(void *ptr, size_t old_size, size_t align, size_t new_size) { | ||
(void) old_size; | ||
if (new_size == 0) return (void*) align; | ||
void *ret = realloc(ptr, new_size); | ||
if (!ret) abort(); | ||
return ret; | ||
} | ||
|
||
// Component Adapters | ||
|
||
__attribute__((__export_name__("run"))) | ||
int64_t __wasm_export_c_api1_run(void) { | ||
uint64_t ret = c_api1_run(); | ||
return (int64_t) (ret); | ||
} | ||
|
||
// Ensure that the *_component_type.o object is linked in | ||
|
||
extern void __component_type_object_force_link_c_api1(void); | ||
void __component_type_object_force_link_c_api1_public_use_in_this_compilation_unit(void) { | ||
__component_type_object_force_link_c_api1(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Generated by `wit-bindgen` 0.26.0. DO NOT EDIT! | ||
#ifndef __BINDINGS_C_API1_H | ||
#define __BINDINGS_C_API1_H | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
|
||
// Exported Functions from `c-api1` | ||
uint64_t c_api1_run(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
Binary file not shown.
Oops, something went wrong.