Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lffg committed Jun 22, 2024
1 parent f98b813 commit 18423fe
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 42 deletions.
4 changes: 2 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Cli {
#[command(subcommand)]
cmd: Cmd,
#[arg(short, long)]
ctl_addr: IpAddr,
ctl_addr: String,
}

#[derive(Debug, Subcommand)]
Expand Down Expand Up @@ -67,7 +67,7 @@ pub enum ServiceCmd {
#[tokio::main]
async fn main() -> eyre::Result<()> {
let cli = Cli::parse();
let ctl_client = CtlClient::new(cli.ctl_addr);
let ctl_client = CtlClient::new(&cli.ctl_addr);
match cli.cmd {
Cmd::Node(cmd) => handle_node(cmd, ctl_client).await?,
Cmd::Service(cmd) => handle_service(cmd, ctl_client).await?,
Expand Down
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
llvmPackages_16.llvm
llvmPackages_16.bintools
libiconv

k6
];
darwinPackages = lib.optionals isDarwin (with pkgs.darwin.apple_sdk.frameworks; [
CoreFoundation
Expand Down
4 changes: 2 additions & 2 deletions proto/src/clients/ctl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{net::IpAddr, sync::Arc};
use std::sync::Arc;

use chrono::{DateTime, Utc};

Expand Down Expand Up @@ -30,7 +30,7 @@ pub struct CtlClient {

impl CtlClient {
#[must_use]
pub fn new(ctl_addr: IpAddr) -> Self {
pub fn new(ctl_addr: &str) -> Self {
let base_url = format!("http://{ctl_addr}:{CTL_HTTP_PORT}")
.into_boxed_str()
.into();
Expand Down
45 changes: 45 additions & 0 deletions tests/perf-analysis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Pre-steps

Build the image

```bash
docker image build -t lffg/number-fact:latest ./tests/containers/number-fact
```

# Single node

Start:

```bash
docker compose -f ./tests/perf-analysis/single-node/docker-compose.yml up
```

In another terminal session:

```bash
k6 run ./tests/perf-analysis/test.js
```

# Tucano multi node

```bash
docker compose -f ./tests/perf-analysis/tuc-multi-node/docker-compose.yml up
```

Ensure that ctl log shows that 3 worker nodes joined the cluster.

Deploy the application:

```bash
./tucano -c localhost service deploy --id="number-fact" --image="lffg/number-fact" --public --concurrency="1"
```

Ensure that all deployments went right.

In another terminal session:

```bash
k6 run ./tests/perf-analysis/test.js
```

# Tucano multi node (4x)
1 change: 0 additions & 1 deletion tests/perf-analysis/single-node/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
services:
server01:
build: ../../containers/number-fact
hostname: html1
networks:
- tucano-cluster-net
ports:
Expand Down
89 changes: 56 additions & 33 deletions tests/perf-analysis/test.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,86 @@
// k6 run ./test.js

import http from 'k6/http';
import { check, sleep } from 'k6';
import { Trend } from 'k6/metrics';
import http from "k6/http";
import { check, sleep } from "k6";
import { Trend } from "k6/metrics";

const API_URL = 'http://localhost:8080/factors';
const API_URL = "http://localhost:8080/factors";

const easyResponseTimes = new Trend('easy_response_times', true);
const mediumResponseTimes = new Trend('medium_response_times', true);
const hardResponseTimes = new Trend('hard_response_times', true);
const easyResponseTimes = new Trend("easy_response_times", true);
const mediumResponseTimes = new Trend("medium_response_times", true);
const hardResponseTimes = new Trend("hard_response_times", true);

export const options = {
scenarios: {
easyNumbers: {
executor: 'constant-vus',
executor: "constant-vus",
vus: 8,
duration: '30s',
exec: 'easyNumbers',
duration: "30s",
exec: "easyNumbers",
},
mediumNumbers: {
executor: 'constant-vus',
executor: "constant-vus",
vus: 8,
duration: '30s',
exec: 'mediumNumbers',
startTime: '30s',
duration: "30s",
exec: "mediumNumbers",
startTime: "30s",
},
hardNumbers: {
executor: 'constant-vus',
executor: "constant-vus",
vus: 8,
duration: '30s',
exec: 'hardNumbers',
startTime: '60s',
duration: "30s",
exec: "hardNumbers",
startTime: "60s",
},
},
};

export function easyNumbers() {
const numbers = [
'12345', '67890', '111213', '141516', '171819',
'202122', '232425', '262728', '293031', '323334'
"12345",
"67890",
"111213",
"141516",
"171819",
"202122",
"232425",
"262728",
"293031",
"323334",
];
testAPI(numbers, 'easy');
testAPI(numbers, "easy");
}

export function mediumNumbers() {
const numbers = [
'12345678901234567890', '98765432109876543210', '11223344556677889900',
'99887766554433221100', '10203040506070809000', '50607080901020304050',
'21436587092143658709', '13579246801357924680', '98765412309876541230',
'19283746501928374650'
"12345678901234567890",
"98765432109876543210",
"11223344556677889900",
"99887766554433221100",
"10203040506070809000",
"50607080901020304050",
"21436587092143658709",
"13579246801357924680",
"98765412309876541230",
"19283746501928374650",
];
testAPI(numbers, 'medium');
testAPI(numbers, "medium");
}

export function hardNumbers() {
const numbers = [
'123456789012345677777', '987654321098765432777', '112233445566778899075',
'998877665544332211057', '102030405060708090057', '506070809010203040575',
'214365870921436587577', '135792468013579246875', '9876541230987654123775',
'19283746501928374655705'
"123456789012345677777",
"987654321098765432777",
"112233445566778899075",
"998877665544332211057",
"102030405060708090057",
"506070809010203040575",
"214365870921436587577",
"135792468013579246875",
"9876541230987654123775",
"19283746501928374655705",
];
testAPI(numbers, 'hard');
testAPI(numbers, "hard");
}

function testAPI(numbers, tag) {
Expand All @@ -72,15 +92,18 @@ function testAPI(numbers, tag) {

for (const number of numbers) {
const res = http.get(`${API_URL}?number=${number}`, {
headers: {
Host: "number-fact",
},
tags: { scenario: tag },
});

check(res, {
'status is 200': (r) => r.status === 200,
"status is 200": (r) => r.status === 200,
});

trends[tag].add(res.timings.duration);

sleep(1);
sleep(1);
}
}
51 changes: 51 additions & 0 deletions tests/perf-analysis/tuc-multi-node/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
services:
ctl:
build:
context: ../../.. # repo root
dockerfile: ./dockerfiles/node.dockerfile
args:
CRATE: ctl
entrypoint:
- /usr/local/bin/ctl
networks: [tucano-cluster-net]
ports:
- "8080:8080" # balancer
- "7070:7070" # http
environment:
RUST_LOG: info,ctl=trace
deploy:
resources:
limits:
cpus: "0.25"
memory: "128MB"

worker1: &w1
depends_on: [ctl]
build:
context: ../../.. # repo root
dockerfile: ./dockerfiles/node.dockerfile
args:
CRATE: worker
entrypoint:
- /usr/local/bin/worker
- -c=ctl
networks:
- tucano-cluster-net
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
RUST_LOG: info,worker=trace
deploy:
resources:
limits:
cpus: "0.25"
memory: "128MB"

worker2:
<<: *w1
worker3:
<<: *w1

networks:
tucano-cluster-net:
attachable: true
2 changes: 1 addition & 1 deletion tucano
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

cargo build -q
cargo build
./target/debug/cli "$@"
4 changes: 2 additions & 2 deletions worker/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::{net::IpAddr, time::Duration};
use std::time::Duration;

use clap::Parser;

#[derive(Debug, Parser)]
pub struct WorkerArgs {
/// Controller's HTTP address.
#[arg(short, long)]
pub ctl_addr: IpAddr,
pub ctl_addr: String,

/// Interval at which metrics are pushed to the controller.
///
Expand Down
2 changes: 1 addition & 1 deletion worker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async fn main() -> Result<()> {
let args = Arc::new(WorkerArgs::parse());
info!(?args, "started worker");

let ctl_client = CtlClient::new(args.ctl_addr);
let ctl_client = CtlClient::new(&args.ctl_addr);

let proxy_listener = mk_listener(ANY_IP, WORKER_PROXY_PORT).await?;
let http_listener = mk_listener(ANY_IP, WORKER_HTTP_PORT).await?;
Expand Down

0 comments on commit 18423fe

Please sign in to comment.