Skip to content
Merged
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
155 changes: 155 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
name: "Benchmark"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read
pull-requests: write

env:
IMAGE: async-dev
CACHE_KEY: async-dev-${{ github.event.pull_request.head.sha }}

on: [pull_request]

jobs:
setup:
name: Setup & Build Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker Image
uses: docker/build-push-action@v3
with:
context: .
push: false
tags: ${{ env.IMAGE }}
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=docker,dest=/tmp/${{ env.IMAGE }}.tar

- name: Cache Docker Image
uses: actions/cache@v3
with:
key: ${{ env.CACHE_KEY }}
path: /tmp/${{ env.IMAGE }}.tar

benchmark:
name: Run Benchmarks
runs-on: ubuntu-latest
needs: setup

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Load Cache
uses: actions/cache@v3
with:
key: ${{ env.CACHE_KEY }}
path: /tmp/${{ env.IMAGE }}.tar
fail-on-cache-miss: true

- name: Load and Start Services
run: |
docker load --input /tmp/${{ env.IMAGE }}.tar
docker compose up -d
sleep 10

- name: Run Swoole Benchmark
id: benchmark-swoole
timeout-minutes: 30
run: |
echo "### Swoole Adapters" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
docker compose exec -T tests php /usr/src/code/benchmarks/Benchmark.php --iterations=10 2>&1 | tee benchmark_swoole.txt
cat benchmark_swoole.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY

- name: Run ext-parallel Benchmark
id: benchmark-parallel
timeout-minutes: 30
run: |
echo "### ext-parallel Adapter" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
docker compose exec -T tests php -n -d extension=parallel.so -d extension=sockets.so /usr/src/code/benchmarks/Benchmark.php --iterations=10 2>&1 | tee benchmark_parallel.txt
cat benchmark_parallel.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY

- name: Combine Results
run: |
echo "## Benchmark Results" > benchmark_output.txt
echo "" >> benchmark_output.txt
echo "### Swoole Adapters" >> benchmark_output.txt
cat benchmark_swoole.txt >> benchmark_output.txt
echo "" >> benchmark_output.txt
echo "### ext-parallel Adapter" >> benchmark_output.txt
cat benchmark_parallel.txt >> benchmark_output.txt

- name: Post Benchmark Results as Comment
continue-on-error: true
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const swooleOutput = fs.readFileSync('benchmark_swoole.txt', 'utf8');
const parallelOutput = fs.readFileSync('benchmark_parallel.txt', 'utf8');

const body = `## Benchmark Results

<details>
<summary>Swoole Adapters (Sync, Swoole Thread, Swoole Process, Amp, React)</summary>

\`\`\`
${swooleOutput}
\`\`\`

</details>

<details>
<summary>ext-parallel Adapter (Sync, Amp, React, ext-parallel)</summary>

\`\`\`
${parallelOutput}
\`\`\`

</details>

> Benchmarks run with 10 iterations on GitHub Actions runner`;

// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});

const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('## Benchmark Results')
);

if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}
51 changes: 31 additions & 20 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ jobs:
path: /tmp/${{ env.IMAGE }}.tar

unit_test:
name: Unit Test
name: Unit Tests
runs-on: ubuntu-latest
needs: setup

steps:
- name: checkout
- name: Checkout
uses: actions/checkout@v4

- name: Load Cache
Expand All @@ -61,23 +61,27 @@ jobs:
sleep 10

- name: Run Unit Tests
run: docker compose exec -T tests vendor/bin/phpunit /usr/src/code/tests/unit
run: docker compose exec -T tests composer test-unit

promise_adapter_test:
name: Promise Adapter Tests
name: Promise ${{ matrix.name }}
runs-on: ubuntu-latest
needs: setup
strategy:
fail-fast: false
matrix:
adapter:
- Sync
- Swoole/Coroutine
- Amp/Amp
- React/React
include:
- name: Sync
script: test-promise-sync
- name: Swoole
script: test-promise-swoole
- name: Amp
script: test-promise-amp
- name: React
script: test-promise-react

steps:
- name: checkout
- name: Checkout
uses: actions/checkout@v4

- name: Load Cache
Expand All @@ -94,24 +98,31 @@ jobs:
sleep 10

- name: Run Tests
run: docker compose exec -T tests vendor/bin/phpunit /usr/src/code/tests/E2e/Promise/${{matrix.adapter}}Test.php --debug
run: docker compose exec -T tests composer ${{ matrix.script }}

parallel_adapter_test:
name: Parallel Adapter Tests
name: Parallel ${{ matrix.name }}
runs-on: ubuntu-latest
needs: setup
strategy:
fail-fast: false
matrix:
adapter:
- Swoole/Process
- Swoole/Thread
- Amp/Amp
- React/React
- Parallel/Parallel
include:
- name: Sync
script: test-parallel-sync
- name: Swoole Thread
script: test-parallel-swoole-thread
- name: Swoole Process
script: test-parallel-swoole-process
- name: Amp
script: test-parallel-amp
- name: React
script: test-parallel-react
- name: ext-parallel
script: test-parallel-ext

steps:
- name: checkout
- name: Checkout
uses: actions/checkout@v4

- name: Load Cache
Expand All @@ -128,4 +139,4 @@ jobs:
sleep 10

- name: Run Tests
run: docker compose exec -T tests vendor/bin/phpunit /usr/src/code/tests/E2e/Parallel/${{matrix.adapter}}Test.php --debug
run: docker compose exec -T tests composer ${{ matrix.script }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ composer.phar
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
.phpunit.result.cache
.idea
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

66 changes: 0 additions & 66 deletions .idea/async.iml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/copilot.data.migration.agent.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/copilot.data.migration.ask.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/copilot.data.migration.ask2agent.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/copilot.data.migration.edit.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

Loading