Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add load test to example-axum-otlp to monitor memory leak #200

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ rust = '1.80.0'
just = '1'
grpcurl = '1.9'
protoc = '29.2'
k6 = '0.43'
# grpc-health-probe = "*"
# sccache = "0.5"
"aqua:cargo-bins/cargo-binstall" = "1" # do not use cargo-binstall (it's a special name used by mise)
1 change: 1 addition & 0 deletions examples/axum-otlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ init-tracing-opentelemetry = { path = "../../init-tracing-opentelemetry", featur
"otlp",
"tracing_subscriber_ext",
] }
memory-stats = "1.1"
opentelemetry = { workspace = true }
opentelemetry-otlp = { workspace = true, default-features = false, features = [
"reqwest-rustls",
Expand Down
25 changes: 24 additions & 1 deletion examples/axum-otlp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,28 @@ content-type: application/json
content-length: 15
date: Wed, 28 Dec 2022 17:14:07 GMT

{"status":"UP"}
{"physical_mem":16056320,"status":"UP","virtual_mem":1130790912}
```

## Load test

on terminal 1: launch the server: `just run_example_axum-otlp_server`
on terminal 2: periodically print the memory usage: `just run_example_axum-otlp_load_client`
on terminal 3: launch the load test script `just run_example_axum-otlp_load`

```txt
...
{"physical_mem":16633856,"status":"UP","virtual_mem":1130790912}
{"physical_mem":16633856,"status":"UP","virtual_mem":1130790912}
{"physical_mem":18382848,"status":"UP","virtual_mem":1130790912}
{"physical_mem":19562496,"status":"UP","virtual_mem":1130790912}
{"physical_mem":19689472,"status":"UP","virtual_mem":1130790912}
{"physical_mem":20312064,"status":"UP","virtual_mem":1130790912}
{"physical_mem":20529152,"status":"UP","virtual_mem":1130790912}
{"physical_mem":21012480,"status":"UP","virtual_mem":1130790912}
{"physical_mem":21258240,"status":"UP","virtual_mem":1130790912}
{"physical_mem":21286912,"status":"UP","virtual_mem":1130790912}
...
```

Alternatively, you can use the `examples/load`.
59 changes: 59 additions & 0 deletions examples/axum-otlp/k6-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { sleep } from 'k6'
import http from 'k6/http'

export const options = {
// A number specifying the number of VUs to run concurrently.
vus: 10,
// A string specifying the total duration of the test run.
duration: '120s'

// The following section contains configuration options for execution of this
// test script in Grafana Cloud.
//
// See https://grafana.com/docs/grafana-cloud/k6/get-started/run-cloud-tests-from-the-cli/
// to learn about authoring and running k6 test scripts in Grafana k6 Cloud.
//
// cloud: {
// // The ID of the project to which the test is assigned in the k6 Cloud UI.
// // By default tests are executed in default project.
// projectID: "",
// // The name of the test in the k6 Cloud UI.
// // Test runs with the same name will be grouped.
// name: "script.js"
// },

// Uncomment this section to enable the use of Browser API in your tests.
//
// See https://grafana.com/docs/k6/latest/using-k6-browser/running-browser-tests/ to learn more
// about using Browser API in your test scripts.
//
// scenarios: {
// // The scenario name appears in the result summary, tags, and so on.
// // You can give the scenario any name, as long as each name in the script is unique.
// ui: {
// // Executor is a mandatory parameter for browser-based tests.
// // Shared iterations in this case tells k6 to reuse VUs to execute iterations.
// //
// // See https://grafana.com/docs/k6/latest/using-k6/scenarios/executors/ for other executor types.
// executor: 'shared-iterations',
// options: {
// browser: {
// // This is a mandatory parameter that instructs k6 to launch and
// // connect to a chromium-based browser, and use it to run UI-based
// // tests.
// type: 'chromium',
// },
// },
// },
// }
}

// The function that defines VU logic.
//
// See https://grafana.com/docs/k6/latest/examples/get-started-with-k6/ to learn more
// about authoring k6 scripts.
//
export default function () {
http.get('http://127.0.0.1:3003/')
sleep(0.2)
}
7 changes: 5 additions & 2 deletions examples/axum-otlp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn app() -> Router {
// build our application with a route
Router::new()
.route(
"/proxy/:service/*path",
"/proxy/{service}/{*path}",
get(proxy_handler).post(proxy_handler),
)
.route("/", get(index)) // request processed inside span
Expand All @@ -40,7 +40,10 @@ fn app() -> Router {
}

async fn health() -> impl IntoResponse {
axum::Json(json!({ "status" : "UP" }))
let memory_stats = memory_stats::memory_stats();
axum::Json(
json!({ "status" : "UP", "physical_mem": memory_stats.map(|s| s.physical_mem), "virtual_mem": memory_stats.map(|s| s.virtual_mem) }),
)
}

#[tracing::instrument]
Expand Down
6 changes: 6 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,9 @@ run_example_http_client:

run_example_load:
cd examples/load; cargo run --release 2>/dev/null

run_example_axum-otlp_load:
cd examples/axum-otlp; k6 run k6-script.js

run_example_axum-otlp_load_client:
while true; do curl -S http://127.0.0.1:3003/health; echo ""; sleep 3; done