Skip to content

Commit

Permalink
feat: add initial setup for Encore API with TypeScript and various co…
Browse files Browse the repository at this point in the history
…nfigurations
  • Loading branch information
ImBIOS committed Dec 24, 2024
1 parent a2f2a80 commit 9373699
Show file tree
Hide file tree
Showing 29 changed files with 1,372 additions and 334 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
encore.gen.go
encore.gen.cue
/encore.gen
requests-results/*.png
benchmark.json
cover.out
14 changes: 14 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
matplotlib = "*"
pandas = "*"
seaborn = "*"

[dev-packages]

[requires]
python_version = "3.12"
559 changes: 559 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,72 @@
# Encore Go Benchmarks

## Note Terminal 1

```bash

```

## Note Terminal 2

```bash
   main ✘!?+7 via 🐹 v1.23.1 via 🐍 v3.12.3 (encore)  8s
➜ oha -c 50 -z 10s -m GET "http://localhost:4000/hello" --json > benchmark.json
^C%

󰀵  󱑍 07:56  ﱮ encore-go-benchmarks/requests/encore    main ✘!?+7 via 🐹 v1.23.1 via 🐍 v3.12.3 (encore)  8s
➜ oha -c 150 -z 10s -m GET "http://localhost:4000/hello" --json > benchmark.json
^C%

󰀵  󱑍 07:57  ﱮ encore-go-benchmarks/requests/encore    main ✘!?+7 via 🐹 v1.23.1 via 🐍 v3.12.3 (encore)  9s
➜ oha -c 150 -z 10s -m GET "http://localhost:4000/hello" --json > benchmark.json
^C%

󰀵  󱑍 07:57  ﱮ encore-go-benchmarks/requests/encore    main ✘!?+7 via 🐹 v1.23.1 via 🐍 v3.12.3 (encore)  5s
➜ oha -c 150 -z 10s -m GET "http://127.0.0.1:4000/hello" --json > benchmark.json
^C%

󰀵  󱑍 07:57  ﱮ encore-go-benchmarks/requests/encore    main ✘!?+7 via 🐹 v1.23.1 via 🐍 v3.12.3 (encore)  5s
➜ oha -c 150 -z 3s -m GET "http://127.0.0.1:4000/hello" --json --latency-correction --disable-keepalive > benchmark.json
^C%

󰀵  󱑍 07:58  ﱮ encore-go-benchmarks/requests/encore    main ✘!?+7 via 🐹 v1.23.1 via 🐍 v3.12.3 (encore)
➜ oha -c 150 -z 3s -m GET "http://127.0.0.1:4000/hello" --json --latency-correction --disable-keepalive > benchmark.json

󰀵  󱑍 07:58  ﱮ encore-go-benchmarks/requests/encore    main ✘!?+7 via 🐹 v1.23.1 via 🐍 v3.12.3 (encore)  3s
➜ pipenv run python visualize_benchmark.py

󰀵  󱑍 07:59  ﱮ encore-go-benchmarks/requests/encore    main ✘!?+7 via 🐹 v1.23.1 via 🐍 v3.12.3 (encore)
➜ oha -c 150 -z 10s -m GET "http://127.0.0.1:4000/hello" --json --latency-correction --disable-keepalive > benchmark.json
^C%

󰀵  󱑍 07:59  ﱮ encore-go-benchmarks/requests/encore    main ✘!?+7 via 🐹 v1.23.1 via 🐍 v3.12.3 (encore)  5s
➜ oha -c 150 -z 5s -m GET "http://127.0.0.1:4000/hello" --json --latency-correction --disable-keepalive > benchmark.json

󰀵  󱑍 07:59  ﱮ encore-go-benchmarks/requests/encore    main ✘!?+7 via 🐹 v1.23.1 via 🐍 v3.12.3 (encore)  5s
➜ oha -c 150 -z 3s -m GET "http://127.0.0.1:4000/hello" --json --latency-correction --disable-keepalive > benchmark.json

󰀵  󱑍 07:59  ﱮ encore-go-benchmarks/requests/encore    main ✘!?+7 via 🐹 v1.23.1 via 🐍 v3.12.3 (encore)  3s
➜ pipenv run python visualize_benchmark.py

󰀵  󱑍 07:59  ﱮ encore-go-benchmarks/requests/encore    main ✘!?+7 via 🐹 v1.23.1 via 🐍 v3.12.3 (encore)
➜ oha -c 150 -z 10s -m GET "http://127.0.0.1:4000/hello" --json --latency-correction --disable-keepalive > benchmark.json
^C%

󰀵  󱑍 08:00  ﱮ encore-go-benchmarks/requests/encore    main ✘!?+7 via 🐹 v1.23.1 via 🐍 v3.12.3 (encore)  4s
➜ oha -c 150 -z 4s -m GET "http://127.0.0.1:4000/hello" --json --latency-correction --disable-keepalive > benchmark.json

󰀵  󱑍 08:02  ﱮ encore-go-benchmarks/requests/encore    main ✘!?+7 via 🐹 v1.23.1 via 🐍 v3.12.3 (encore)  4s
➜ oha -c 150 -z 3s -m GET "http://127.0.0.1:4000/hello" --json --latency-correction --disable-keepalive > benchmark.json

󰀵  󱑍 08:03  ﱮ encore-go-benchmarks/requests/encore    main ✘!?+7 via 🐹 v1.23.1 via 🐍 v3.12.3 (encore)  3s
➜ oha -c 150 -z 3s -m GET "http://127.0.0.1:4000/hello" --json --latency-correction --disable-keepalive > benchmark.json

󰀵  󱑍 08:03  ﱮ encore-go-benchmarks/requests/encore    main ✘!?+7 via 🐹 v1.23.1 via 🐍 v3.12.3 (encore)  3s
➜ oha -c 150 -z 3s -m GET "http://127.0.0.1:4000/hello" --json --latency-correction --disable-keepalive > benchmark.json

󰀵  󱑍 08:03  ﱮ encore-go-benchmarks/requests/encore    main ✘!?+7 via 🐹 v1.23.1 via 🐍 v3.12.3 (encore)  3s
➜ pipenv run python visualize_benchmark.py

󰀵  󱑍 08:03  ﱮ encore-go-benchmarks/requests/encore    main ✘!?+7 via 🐹 v1.23.1 via 🐍 v3.12.3 (encore)
➜ oha -c 150 -z 3s -m GET "http://127.0.0.1:4000/hello" --json --latency-correction --disable-keepalive > benchmark.json
```
72 changes: 72 additions & 0 deletions benchmark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash

# Paths
ENCORE_DIR="requests/encore"
ENCORE_TS_DIR="requests/encore-ts"
PYTHON_SCRIPT="./visualize_benchmark.py"

# Benchmark parameters
CONCURRENT_USERS=150
DURATION="3s"

# Function to extract the API server port from Encore logs
get_api_server_port() {
local log_output=$1
echo "$log_output" | grep "api server listening for incoming requests" | grep -oP "127\.0\.0\.1:\K[0-9]+"
}

# Function to run benchmark
run_benchmark() {
local dir=$1
local name=$2
echo "Starting benchmark for $name..."

# Navigate to the directory
cd "$dir" || exit 1

# Start the Encore server and capture logs
LOG_OUTPUT=$(ENCORE_LOG=off ENCORE_NOTRACE=1 ENCORE_RUNTIME_LOG=debug encore run 2>&1) &
SERVER_PID=$!
echo "Server started (PID: $SERVER_PID)."

# Extract the API server port from the logs
API_SERVER_PORT=$(get_api_server_port "$LOG_OUTPUT" || echo "4000")
if [ -z "$API_SERVER_PORT" ]; then
echo "Failed to extract API server port from logs. Aborting."
kill "$SERVER_PID"
wait "$SERVER_PID" 2>/dev/null
exit 1
fi
BENCHMARK_URL="http://127.0.0.1:$API_SERVER_PORT/hello"
echo "Benchmarking against URL: $BENCHMARK_URL"

# Wait for server to be ready
sleep 5

# Run oha benchmark
echo "Running benchmark for $name..."
oha -c "$CONCURRENT_USERS" -z "$DURATION" -m GET "$BENCHMARK_URL" --json --latency-correction --disable-keepalive >benchmark.json

# Stop the server
echo "Stopping server for $name..."
kill "$SERVER_PID"
wait "$SERVER_PID" 2>/dev/null
echo "Benchmark for $name completed."

# Navigate back
cd - || exit 1
}

# Run benchmarks for encore and encore-ts
run_benchmark "$ENCORE_DIR" "Encore-Go"
run_benchmark "$ENCORE_TS_DIR" "Encore-TS"

# Visualize benchmark results
echo "Visualizing results..."
python3 visualize_benchmark.py \
"$ENCORE_DIR/benchmark.json" \
"$ENCORE_TS_DIR/benchmark.json" \
"Encore-Go" \
"Encore-TS"

echo "All benchmarks completed."
1 change: 1 addition & 0 deletions cold-starts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# IDK if we would need cold0starts test or no
6 changes: 6 additions & 0 deletions cold-starts/encore/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.encore
encore.gen.go
encore.gen.cue
/.encore
node_modules
/encore.gen
48 changes: 48 additions & 0 deletions cold-starts/encore/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# REST API Starter

This is a RESTful API Starter with a single Hello World API endpoint.

## Developing locally

When you have [installed Encore](https://encore.dev/docs/install), you can create a new Encore application and clone this example with this command.

```bash
encore app create my-app-name --example=ts/hello-world
```

## Running locally
```bash
encore run
```

While `encore run` is running, open <http://localhost:9400/> to view Encore's [local developer dashboard](https://encore.dev/docs/observability/dev-dash).

## Using the API

To see that your app is running, you can ping the API.

```bash
curl http://localhost:4000/hello/World
```

## Deployment

Deploy your application to a staging environment in Encore's free development cloud:

```bash
git add -A .
git commit -m 'Commit message'
git push encore
```

Then head over to the [Cloud Dashboard](https://app.encore.dev) to monitor your deployment and find your production URL.

From there you can also connect your own AWS or GCP account to use for deployment.

Now off you go into the clouds!

## Testing

```bash
encore test
```
4 changes: 4 additions & 0 deletions cold-starts/encore/encore.app
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"id": "",
"lang": "typescript"
}
76 changes: 76 additions & 0 deletions cold-starts/encore/hello/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { api } from "encore.dev/api";

interface Response {
message: string;
}

export const e1 = api(
{ expose: true, method: "GET", path: "/1" },
(data: { q1: string; excitement: number }): Response => {
return { message: "Hello, World" };
}
);

export const e2 = api(
{ expose: true, method: "GET", path: "/2" },
(data: { q2: string; excitement: number }): Response => {
return { message: "Hello, World" };
}
);

export const e3 = api(
{ expose: true, method: "GET", path: "/3" },
(data: { q3: string; excitement: number }): Response => {
return { message: "Hello, World" };
}
);

export const e4 = api(
{ expose: true, method: "GET", path: "/4" },
(data: { q4: string; excitement: number }): Response => {
return { message: "Hello, World" };
}
);

export const e5 = api(
{ expose: true, method: "GET", path: "/5" },
(data: { q5: string; excitement: number }): Response => {
return { message: "Hello, World" };
}
);

export const e6 = api(
{ expose: true, method: "GET", path: "/6" },
(data: { q6: string; excitement: number }): Response => {
return { message: "Hello, World" };
}
);

export const e7 = api(
{ expose: true, method: "GET", path: "/7" },
(data: { q7: string; excitement: number }): Response => {
return { message: "Hello, World" };
}
);

export const e8 = api(
{ expose: true, method: "GET", path: "/8" },
(data: { q8: string; excitement: number }): Response => {
return { message: "Hello, World" };
}
);

export const e9 = api(
{ expose: true, method: "GET", path: "/9" },
(data: { q9: string; excitement: number }): Response => {
return { message: "Hello, World" };
}
);

export const e10 = api(
{ expose: true, method: "GET", path: "/10" },
(data: { q10: string; excitement: number }): Response => {
return { message: "Hello, World" };
}
);

14 changes: 14 additions & 0 deletions cold-starts/encore/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "encore-benchmark",
"private": true,
"version": "0.0.1",
"license": "MIT",
"type": "module",
"devDependencies": {
"@types/node": "^20.5.7",
"typescript": "^5.2.2"
},
"dependencies": {
"encore.dev": "^1.40.0"
}
}
31 changes: 31 additions & 0 deletions cold-starts/encore/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
/* Basic Options */
"lib": ["ES2022"],
"target": "ES2022",
"module": "ES2022",
"types": ["node"],
"paths": {
"~encore/*": ["./encore.gen/*"]
},

/* Workspace Settings */
"composite": true,

/* Strict Type-Checking Options */
"strict": true,

/* Module Resolution Options */
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"isolatedModules": true,
"sourceMap": true,

"declaration": true,

/* Advanced Options */
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true
}
}
6 changes: 6 additions & 0 deletions requests/encore-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.encore
encore.gen.go
encore.gen.cue
/.encore
node_modules
/encore.gen
Loading

0 comments on commit 9373699

Please sign in to comment.