-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add initial setup for Encore API with TypeScript and various co…
…nfigurations
- Loading branch information
Showing
29 changed files
with
1,372 additions
and
334 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,6 @@ | |
encore.gen.go | ||
encore.gen.cue | ||
/encore.gen | ||
requests-results/*.png | ||
benchmark.json | ||
cover.out |
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,14 @@ | ||
[[source]] | ||
url = "https://pypi.org/simple" | ||
verify_ssl = true | ||
name = "pypi" | ||
|
||
[packages] | ||
matplotlib = "*" | ||
pandas = "*" | ||
seaborn = "*" | ||
|
||
[dev-packages] | ||
|
||
[requires] | ||
python_version = "3.12" |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -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 | ||
``` |
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,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." |
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 @@ | ||
# IDK if we would need cold0starts test or no |
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,6 @@ | ||
.encore | ||
encore.gen.go | ||
encore.gen.cue | ||
/.encore | ||
node_modules | ||
/encore.gen |
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,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 | ||
``` |
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,4 @@ | ||
{ | ||
"id": "", | ||
"lang": "typescript" | ||
} |
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,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" }; | ||
} | ||
); | ||
|
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,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" | ||
} | ||
} |
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,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 | ||
} | ||
} |
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,6 @@ | ||
.encore | ||
encore.gen.go | ||
encore.gen.cue | ||
/.encore | ||
node_modules | ||
/encore.gen |
Oops, something went wrong.