diff --git a/examples/docker-unix/README.md b/examples/docker-unix/README.md deleted file mode 100644 index 1e93e04..0000000 --- a/examples/docker-unix/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Warning - -Having two services in a docker compose and running both ( seperately) causes a network name conflict diff --git a/examples/docker-unix/cardamon.unix.toml b/examples/docker-unix/cardamon.unix.toml deleted file mode 100644 index aa01550..0000000 --- a/examples/docker-unix/cardamon.unix.toml +++ /dev/null @@ -1,27 +0,0 @@ - - -[[processes]] -name = "db" -up = "bash -c '(cd examples/docker-unix/db && docker compose up -d db)'" -down = "bash -c '(cd examples/docker-unix/db && docker compose down -v )'" -redirect.to = "parent" -process.type = "docker" -process.containers = ["db"] -[[processes]] -name = "test" -up = "bash -c '(cd examples/docker-unix/test && docker compose up -d test)'" -down = "bash -c '(cd examples/docker-unix/test && docker compose down -v)'" -redirect.to = "parent" -process.type = "docker" -process.containers = ["test"] - -[[scenarios]] -name = "basket_10" -desc = "Adds ten items to the basket" -command = "sleep 15" -iterations = 2 -processes = ["test", "db"] - -[[observations]] -name = "obs_1" -scenarios = ["basket_10"] diff --git a/examples/docker-unix/db/docker-compose.yml b/examples/docker-unix/db/docker-compose.yml deleted file mode 100644 index f15e266..0000000 --- a/examples/docker-unix/db/docker-compose.yml +++ /dev/null @@ -1,6 +0,0 @@ -services: - db: - image: postgres:13 - environment: - POSTGRES_PASSWORD: example - container_name: db diff --git a/examples/docker-unix/test/docker-compose.yml b/examples/docker-unix/test/docker-compose.yml deleted file mode 100644 index 5d61cfc..0000000 --- a/examples/docker-unix/test/docker-compose.yml +++ /dev/null @@ -1,8 +0,0 @@ -services: - test: - image: progrium/stress - command: --cpu 1 --timeout 300s - deploy: - resources: - limits: - cpus: '1' diff --git a/examples/hybrid/Dockerfile b/examples/hybrid/Dockerfile new file mode 100644 index 0000000..47b4667 --- /dev/null +++ b/examples/hybrid/Dockerfile @@ -0,0 +1,9 @@ +FROM ubuntu:latest + +WORKDIR /app +COPY rand-api /app/rand-api +RUN chmod +x /app/rand-api + +EXPOSE 4242 +CMD ["./rand-api"] +# ENTRYPOINT ["tail", "-f", "/dev/null"] diff --git a/examples/hybrid/cardamon.toml b/examples/hybrid/cardamon.toml new file mode 100644 index 0000000..443cfae --- /dev/null +++ b/examples/hybrid/cardamon.toml @@ -0,0 +1,47 @@ +# CPU +# ######################################## +[cpu] +name = "AMD Ryzen 7 PRO 6850U with Radeon Graphics" +curve = [ + 7.627190097500079, + 0.07551567953624883, + 20.45110313049153, + -1.5261422759740344, +] + +# Processes +# ######################################## +[[process]] +name = "rand-api" +up = "./rand-api" +down = "kill {pid}" +redirect.to = "file" +process.type = "baremetal" + +[[process]] +name = "rand-api-docker" +up = "docker run -d --name c1 -p 4244:4243 rand-api" +down = "bash -c 'docker stop c1 && docker rm c1'" +redirect.to = "file" +process.type = "docker" +process.containers = ["c1"] +startup_grace = 8000 + +# Scenarios +# ######################################## +[[scenario]] +name = "stress" +desc = "Calls each instance of rand-api 1500 times" +command = "sh scenario.sh" +iterations = 2 +processes = ["rand-api", "rand-api-docker"] + +# Observations +# ######################################## +[[observation]] +name = "stress" +scenarios = ["stress"] + +[[observation]] +name = "live_monitor" +processes = ["test_proc1", "test_proc2"] diff --git a/examples/hybrid/rand-api b/examples/hybrid/rand-api new file mode 100755 index 0000000..9519cee Binary files /dev/null and b/examples/hybrid/rand-api differ diff --git a/examples/hybrid/scenario.sh b/examples/hybrid/scenario.sh new file mode 100644 index 0000000..a149b79 --- /dev/null +++ b/examples/hybrid/scenario.sh @@ -0,0 +1,5 @@ +#!/bin/sh +for i in $(seq 1 1500); do + curl localhost:4243/rand >/dev/null 2>&1 + curl localhost:4244/rand >/dev/null 2>&1 +done diff --git a/examples/tod/Dockerfile b/examples/tod/Dockerfile deleted file mode 100644 index 84faefd..0000000 --- a/examples/tod/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM golang:1.22.5-alpine - -WORKDIR /app - -COPY go.mod go.sum ./ -RUN go mod download - -COPY . . - -RUN go build -o main . - -EXPOSE 8080 - -CMD ["./main"] diff --git a/examples/tod/cardamon.toml b/examples/tod/cardamon.toml deleted file mode 100644 index a5a231d..0000000 --- a/examples/tod/cardamon.toml +++ /dev/null @@ -1,22 +0,0 @@ -[computer] -cpu_name = "AMD Ryzen 7 7840U w/ Radeon 780M Graphics (16) @ 5.132GHz" -cpu_avg_power= 28.0 - -[[processes]] -name = "backend" -up = "docker compose up --build" -down = "docker compose down" -redirect.to = "parent" -process.type = "docker" -process.containers = ["redis","todo-app"] - -[[scenarios]] -name = "rust_test" # Required -desc = "Test each endpoint 100 times" # Optional -command = "bash -c '(cd testing && cargo run)'" # Required - commands for running scenarios -iterations = 1 # Optional - defaults to 1 -processes = ["backend"] # Required - prepend process name with `_` to ignore - -[[observations]] -name = "todo" # Required -scenarios = ["rust_test"] # Required diff --git a/examples/tod/docker-compose.yml b/examples/tod/docker-compose.yml deleted file mode 100644 index 762069b..0000000 --- a/examples/tod/docker-compose.yml +++ /dev/null @@ -1,23 +0,0 @@ -services: - redis: - image: redis:latest - container_name: my-redis - ports: - - "6379:6379" - command: redis-server --appendonly no - networks: - - app-network - - todo-app: - build: . - container_name: todo-app - ports: - - "8080:8080" - depends_on: - - redis - networks: - - app-network - -networks: - app-network: - driver: bridge diff --git a/examples/tod/go.mod b/examples/tod/go.mod deleted file mode 100644 index deb8c1d..0000000 --- a/examples/tod/go.mod +++ /dev/null @@ -1,13 +0,0 @@ -module tod - -go 1.22.5 - -require ( - github.com/go-redis/redis/v8 v8.11.5 - github.com/gorilla/mux v1.8.1 -) - -require ( - github.com/cespare/xxhash/v2 v2.1.2 // indirect - github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect -) diff --git a/examples/tod/go.sum b/examples/tod/go.sum deleted file mode 100644 index 98bf40a..0000000 --- a/examples/tod/go.sum +++ /dev/null @@ -1,26 +0,0 @@ -github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= -github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= -github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= -github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= -github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= -github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= -github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= -github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= -github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= -github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= -github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= -github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= -golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0= -golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/examples/tod/main.go b/examples/tod/main.go deleted file mode 100644 index b019263..0000000 --- a/examples/tod/main.go +++ /dev/null @@ -1,109 +0,0 @@ -package main - -import ( - "encoding/json" - "log" - "net/http" - - "github.com/go-redis/redis/v8" - "github.com/gorilla/mux" -) - -var redisClient *redis.Client - -type Note struct { - ID string `json:"id"` - Text string `json:"text"` -} - -func main() { - // Initialize Redis client - redisClient = redis.NewClient(&redis.Options{ - Addr: "redis:6379", // Using the service name from docker-compose - DB: 0, - }) - - // Initialize router - r := mux.NewRouter() - - // Define routes - r.HandleFunc("/notes", getNotes).Methods("GET") - r.HandleFunc("/notes/{id}", getNote).Methods("GET") - r.HandleFunc("/notes", setNote).Methods("POST") - r.HandleFunc("/notes/{id}", deleteNote).Methods("DELETE") - - // Start server - log.Println("Server is running on port 8080") - log.Fatal(http.ListenAndServe(":8080", r)) -} - -func getNotes(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() - keys, err := redisClient.Keys(ctx, "*").Result() - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - notes := []Note{} - for _, key := range keys { - val, err := redisClient.Get(ctx, key).Result() - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - notes = append(notes, Note{ID: key, Text: val}) - } - - json.NewEncoder(w).Encode(notes) -} - -func getNote(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() - vars := mux.Vars(r) - id := vars["id"] - - val, err := redisClient.Get(ctx, id).Result() - if err == redis.Nil { - http.Error(w, "Note not found", http.StatusNotFound) - return - } else if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - json.NewEncoder(w).Encode(Note{ID: id, Text: val}) -} - -func setNote(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() - var note Note - err := json.NewDecoder(r.Body).Decode(¬e) - if err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - - err = redisClient.Set(ctx, note.ID, note.Text, 0).Err() - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - w.WriteHeader(http.StatusCreated) - json.NewEncoder(w).Encode(note) -} - -func deleteNote(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() - vars := mux.Vars(r) - id := vars["id"] - - _, err := redisClient.Del(ctx, id).Result() - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - w.WriteHeader(http.StatusNoContent) -} diff --git a/examples/tod/testing/Cargo.toml b/examples/tod/testing/Cargo.toml deleted file mode 100644 index 82cb641..0000000 --- a/examples/tod/testing/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "testing" -version = "0.1.0" -edition = "2021" - -[dependencies] -reqwest = {version = "0.12.5", features = ["json"] } -serde_json = "1.0.124" -tokio = { version = "1.37.0", features = ["full"] } - diff --git a/examples/tod/testing/src/main.rs b/examples/tod/testing/src/main.rs deleted file mode 100644 index b669a07..0000000 --- a/examples/tod/testing/src/main.rs +++ /dev/null @@ -1,87 +0,0 @@ -use core::time; -use reqwest::Client; -use serde_json::json; -use std::{thread, time::Instant}; -use tokio; - -const BASE_URL: &str = "http://localhost:8080"; -const NUM_REQUESTS: usize = 1000; - -#[tokio::main] -async fn main() -> Result<(), Box> { - let client = Client::new(); - - println!("Starting API endpoint tests..."); - - // Test POST /notes - let post_start = Instant::now(); - for i in 0..NUM_REQUESTS { - let response = client - .post(format!("{}/notes", BASE_URL)) - .json(&json!({ - "id": format!("test{}", i), - "text": format!("Test note {}", i) - })) - .send() - .await; - match response { - Ok(res) => { - if res.status().is_success() { - print!(".") - } else { - print!("x") - } - } - Err(..) => thread::sleep(time::Duration::from_secs(1)), - } - } - println!("\nPOST /notes: {:?}", post_start.elapsed()); - - // Test GET /notes - let get_all_start = Instant::now(); - for _ in 0..NUM_REQUESTS { - let response = client.get(format!("{}/notes", BASE_URL)).send().await?; - - if response.status().is_success() { - print!("."); - } else { - print!("x"); - } - } - println!("\nGET /notes: {:?}", get_all_start.elapsed()); - - // Test GET /notes/{id} - let get_one_start = Instant::now(); - for i in 0..NUM_REQUESTS { - let response = client - .get(format!("{}/notes/test{}", BASE_URL, i % 100)) - .send() - .await?; - - if response.status().is_success() { - print!("."); - } else { - print!("x"); - } - } - println!("\nGET /notes/{{id}}: {:?}", get_one_start.elapsed()); - - // Test DELETE /notes/{id} - let delete_start = Instant::now(); - for i in 0..NUM_REQUESTS { - let response = client - .delete(format!("{}/notes/test{}", BASE_URL, i % 100)) - .send() - .await?; - - if response.status().is_success() { - print!("."); - } else { - print!("x"); - } - } - println!("\nDELETE /notes/{{id}}: {:?}", delete_start.elapsed()); - - println!("API endpoint tests completed."); - Ok(()) -}