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

Feat benchmarks #4615

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
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
42 changes: 42 additions & 0 deletions .github/workflows/benchmark-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: "Benchmark Update Baseline"

on:
push:
branches:
- master

jobs:
benchmark-update:
name: Benchmark Update Baseline
runs-on: ubuntu-22.04

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
token: ${{ secrets.GH_TOKEN }}
fetch-depth: 1

- name: Build & Run Appwrite
run: |
export COMPOSE_INTERACTIVE_NO_CLI
export DOCKER_BUILDKIT=1
export COMPOSE_DOCKER_CLI_BUILD=1
export BUILDKIT_PROGRESS=plain
docker pull composer:2.0
docker compose build appwrite
docker compose up -d
sleep 30

- name: Doctor
run: docker compose exec -T appwrite doctor

- name: Run Benchmark and Update Baseline
run: |
rm -rf .phpbench/*
docker compose exec -T appwrite benchmark --tag=baseline

- name: Commit updated baseline benchmark
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Update benchmark baseline
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

strategy:
fail-fast: false
Expand Down
20 changes: 0 additions & 20 deletions .github/workflows/linter.yml

This file was deleted.

31 changes: 19 additions & 12 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@ name: "Tests"
on: [pull_request]
jobs:
tests:
name: Unit & E2E
runs-on: ubuntu-latest
name: Lint, Test, Benchmark
runs-on: ubuntu-22.04

steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Checkout Repository
uses: actions/checkout@v3
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2

# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}
- name: Checkout Pull Request HEAD
run: git checkout HEAD^2

- name: Install Dependencies
run: docker run --rm -v $PWD:/app composer install --profile --ignore-platform-reqs

- name: Run Linter
run: docker run --rm -v $PWD:/app composer lint

- name: Build Appwrite
# Upstream bug causes buildkit pulls to fail so prefetch base images
Expand All @@ -31,11 +33,16 @@ jobs:
docker compose build appwrite
docker compose up -d
sleep 30
- name: Doctor

- name: Run Doctor
run: docker compose exec -T appwrite doctor

- name: Environment Variables
- name: Print Environment Variables
run: docker compose exec -T appwrite vars

- name: Run Tests
run: docker compose exec -T appwrite test --debug

- name: Run Benchmark
continue-on-error: true
run: docker compose exec -T appwrite benchmark --ref=baseline --progress=plain

Large diffs are not rendered by default.

51 changes: 31 additions & 20 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,12 @@ The Runtimes for all supported cloud functions (multicore builds) can be found a

For generating a new console SDK follow the next steps:

1. Update the console spec file located at `app/config/specs/swagger2-<version-number>.console.json` using Appwrite Tasks. Run the `php app/cli.php specs <version-number> normal` command in a running `appwrite/appwrite` container.
2. Generate a new SDK using the command `php app/cli.php sdks`
1. Generate new spec files using the command `docker compose exec appwrite specs <version-number>`
2. Generate new SDKs using the command `docker compose exec appwrite sdks`
3. Change your working dir using `cd app/sdks/console-web`
4. Build the new SDK `npm run build`
5. Copy `iife/sdk.js` to `appwrite.js`
6. Go back to the root of the project `run npm run build`
5. Copy `dist/iife/sdk.js` to `public/scripts/dependencies/appwrite.js`
6. Go back to the root of the project and run `npm run build`

## Checklist for Releasing SDKs

Expand All @@ -332,7 +332,7 @@ Things to remember when releasing SDKs
- Update the Changelogs in **docs/sdks** (right now only Dart and Flutter are using these)
- Update **GETTING_STARTED.md** in **docs/sdks** for each SDKs if any changes in the related APIs in there
- Update SDK versions as required on **app/config/platforms.php**
- Generate SDKs using the command `php app/cli.php sdks` and follow the instructions
- Generate SDKs using the command `docker compose exec appwrite sdks` and follow the instructions
- Release new tags on GitHub repository for each SDKs

## Debug
Expand Down Expand Up @@ -370,42 +370,53 @@ docker compose exec appwrite test
To run unit tests use:

```bash
docker compose exec appwrite test /usr/src/code/tests/unit
docker compose exec appwrite test tests/unit
```

To run end-2-end tests use:

```bash
docker compose exec appwrite test /usr/src/code/tests/e2e
docker compose exec appwrite test tests/e2e
```

To run end-2-end tests for a specific service use:

```bash
docker compose exec appwrite test /usr/src/code/tests/e2e/Services/[ServiceName]
docker compose exec appwrite test tests/e2e/Services/[ServiceName]
```

## Benchmarking

You can use WRK Docker image to benchmark the server performance. Benchmarking is extremely useful when you want to compare how the server behaves before and after a change has been applied. Replace [APPWRITE_HOSTNAME_OR_IP] with your Appwrite server hostname or IP. Note that localhost is not accessible from inside the WRK container.
Benchmarking is extremely useful when you want to compare how the server behaves before and after a change has been applied.

To run all benchmarks manually, run the following command:

```bash
composer benchmark
```

To run benchmarks for a specific service, run the following command:

```bash
composer benchmark tests/benchmarks/Services/[ServiceName]
```
Options:
-c, --connections <N> Connections to keep open
-d, --duration <T> Duration of test
-t, --threads <N> Number of threads to use

-s, --script <S> Load Lua script file
-H, --header <H> Add header to request
--latency Print latency statistics
--timeout <T> Socket/request timeout
-v, --version Print version details

Because benchmarking is dependent on the resources available to the server, results will vary from machine to machine. To combat this, you should first run a benchmark to set a baseline using your machine before making any changes, then run a comparison after you've completed your changes.

To create a baseline benchmark, run the following command:

```bash
composer benchmark-tag
```

To run a comparison benchmark, run the following command:

```bash
docker run --rm skandyla/wrk -t3 -c100 -d30 https://[APPWRITE_HOSTNAME_OR_IP]
composer benchmark-compare
```

The comparison benchmark output will show you a % difference in performance between the baseline and the current code.

## Code Maintenance

We use some automation tools to help us keep a healthy codebase.
Expand Down
23 changes: 1 addition & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -330,28 +330,7 @@ RUN mkdir -p /storage/uploads && \
chown -Rf www-data.www-data /storage/debug && chmod -Rf 0755 /storage/debug

# Executables
RUN chmod +x /usr/local/bin/doctor && \
chmod +x /usr/local/bin/maintenance && \
chmod +x /usr/local/bin/usage && \
chmod +x /usr/local/bin/install && \
chmod +x /usr/local/bin/migrate && \
chmod +x /usr/local/bin/realtime && \
chmod +x /usr/local/bin/executor && \
chmod +x /usr/local/bin/schedule && \
chmod +x /usr/local/bin/sdks && \
chmod +x /usr/local/bin/specs && \
chmod +x /usr/local/bin/ssl && \
chmod +x /usr/local/bin/test && \
chmod +x /usr/local/bin/vars && \
chmod +x /usr/local/bin/worker-audits && \
chmod +x /usr/local/bin/worker-certificates && \
chmod +x /usr/local/bin/worker-databases && \
chmod +x /usr/local/bin/worker-deletes && \
chmod +x /usr/local/bin/worker-functions && \
chmod +x /usr/local/bin/worker-builds && \
chmod +x /usr/local/bin/worker-mails && \
chmod +x /usr/local/bin/worker-messaging && \
chmod +x /usr/local/bin/worker-webhooks
RUN chmod +x /usr/local/bin/*

# Letsencrypt Permissions
RUN mkdir -p /etc/letsencrypt/live/ && chmod -Rf 755 /etc/letsencrypt/live/
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/api/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,11 @@
throw new Exception(Exception::DEPLOYMENT_NOT_FOUND);
}

$build = $dbForProject->getDocument('builds', $deployment->getAttribute('buildId', ''));
$deployment->setAttribute('status', $build->getAttribute('status', 'processing'));
$deployment->setAttribute('buildStderr', $build->getAttribute('stderr', ''));
$deployment->setAttribute('buildStdout', $build->getAttribute('stdout', ''));

$response->dynamic($deployment, Response::MODEL_DEPLOYMENT);
});

Expand Down
3 changes: 3 additions & 0 deletions bin/benchmark
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sh

/usr/src/code/vendor/bin/phpbench run --config /usr/src/code/phpbench.json --report appwrite $@
Empty file modified bin/executor
100644 → 100755
Empty file.
Empty file modified bin/maintenance
100644 → 100755
Empty file.
Empty file modified bin/realtime
100644 → 100755
Empty file.
Empty file modified bin/schedule
100644 → 100755
Empty file.
Empty file modified bin/sdks
100644 → 100755
Empty file.
Empty file modified bin/specs
100644 → 100755
Empty file.
Empty file modified bin/vars
100644 → 100755
Empty file.
Empty file modified bin/worker-audits
100644 → 100755
Empty file.
Empty file modified bin/worker-builds
100644 → 100755
Empty file.
Empty file modified bin/worker-databases
100644 → 100755
Empty file.
Empty file modified bin/worker-deletes
100644 → 100755
Empty file.
Empty file modified bin/worker-functions
100644 → 100755
Empty file.
Empty file modified bin/worker-mails
100644 → 100755
Empty file.
Empty file modified bin/worker-messaging
100644 → 100755
Empty file.
Empty file modified bin/worker-webhooks
100644 → 100755
Empty file.
26 changes: 23 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,19 @@
"scripts": {
"test": "vendor/bin/phpunit",
"lint": "vendor/bin/phpcs",
"format": "vendor/bin/phpcbf"
"format": "vendor/bin/phpcbf",
"benchmark": [
"Composer\\Config::disableProcessTimeout",
"vendor/bin/phpbench run --report=appwrite --"
],
"benchmark-tag": [
"Composer\\Config::disableProcessTimeout",
"vendor/bin/phpbench run --report=appwrite --tag=baseline --"
],
"benchmark-compare": [
"Composer\\Config::disableProcessTimeout",
"vendor/bin/phpbench run --report=appwrite --ref=baseline --"
]
},
"autoload": {
"psr-4": {
Expand All @@ -24,11 +36,12 @@
"psr-4": {
"Tests\\E2E\\": "tests/e2e",
"Tests\\Unit\\": "tests/unit",
"Tests\\Benchmarks\\": "tests/benchmarks",
"Appwrite\\Tests\\": "tests/extensions"
}
},
"require": {
"php": ">=8.0.0",
"php": "8.0.*",
"ext-curl": "*",
"ext-imagick": "*",
"ext-mbstring": "*",
Expand Down Expand Up @@ -82,7 +95,14 @@
"phpunit/phpunit": "9.5.20",
"squizlabs/php_codesniffer": "^3.6",
"swoole/ide-helper": "4.8.9",
"textalk/websocket": "1.5.7"
"textalk/websocket": "1.5.7",
"phpbench/phpbench": "^1.2",

"symfony/console": "^5.0",
"symfony/filesystem": "^5.0",
"symfony/finder": "^5.0",
"symfony/options-resolver": "^5.0",
"symfony/process": "^5.0"
Comment on lines +101 to +105
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because phpbench has a transitive dependency on these as version ^4 || ^5 || ^6, and picks v6 by default which requires PHP 8.1, so causes runtime errors as our docker image is PHP 8.0

},
"provide": {
"ext-phpiredis": "*"
Expand Down
Loading