Skip to content
Open
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
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**/node_modules/
**/dist
.git
npm-debug.log
.coverage
.coverage.*
.env
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ jobs:

matrix:
node:
- 16.x
- 18.x
- 20.x

Expand All @@ -52,9 +51,9 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Execute lint & build
- name: Perform build with Aegir
run: |
npm run lint
npm run npm:install
npm run build

- name: Execute tests
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ jobs:
run: |
npm ci

- name: Execute lint & build
- name: Perform build with Aegir
run: |
npm run lint
npm run npm:install
npm run build

- name: Cleanup
Expand Down
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
coverage/
.coverage/
.docs/
build/
dist/
node_modules/
package-lock.json
yarn.lock

# IDE
.DS_Store
.wakatime-project
.vscode
12 changes: 12 additions & 0 deletions .release-please.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"plugins": ["node-workspace"],
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": true,
"group-pull-request-title-pattern": "chore: release ${component}",
"packages": {
"packages/impl": {},
"packages/interfaces": {},
"packages/pusher": {},
"packages/servers": {}
}
}
43 changes: 43 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
ARG VERSION=lts

FROM --platform=$BUILDPLATFORM node:$VERSION-bullseye as build

ENV PYTHONUNBUFFERED=1
ENV NODE_OPTIONS="--es-module-specifier-resolution=node"

COPY . /tmp/build

WORKDIR /tmp/build

RUN apt-get update -y ; \
apt-get upgrade -y ; \
apt-get install -y git python3 gcc wget ; \
npm ci ; \
npm run npm:install ; \
npm run build ; \
npm ci --omit=dev --ignore-scripts ; \
npm prune --production ; \
rm -rf node_modules/*/test/ node_modules/*/tests/ ; \
npm install -g modclean ; \
modclean -n default:safe --run ; \
mkdir -p /app ; \
cp -r bin/ dist/ node_modules/ LICENSE package.json package-lock.json README.md /app/

FROM --platform=$TARGETPLATFORM node:$VERSION-bullseye-slim

LABEL org.opencontainers.image.authors="Soketi <open-source@soketi.app>"
LABEL org.opencontainers.image.source="https://github.com/soketi/impl"
LABEL org.opencontainers.image.url="https://soketi.app"
LABEL org.opencontainers.image.documentation="https://docs.soketi.app"
LABEL org.opencontainers.image.vendor="Soketi"
LABEL org.opencontainers.image.licenses="AGPL-3.0"

ENV NODE_OPTIONS="--es-module-specifier-resolution=node"

COPY --from=build /app /app

WORKDIR /app

EXPOSE 6001

ENTRYPOINT ["node", "/app/bin/server.js", "start"]
13 changes: 13 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM --platform=$TARGETPLATFORM node:18-bullseye-slim

ENV PYTHONUNBUFFERED=1

WORKDIR /app

COPY . /app

RUN npm ci ; \
npm run clean ; \
npm run build

ENV NODE_OPTIONS="--es-module-specifier-resolution=node --experimental-vm-modules"
102 changes: 102 additions & 0 deletions benchmark/ci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { Trend } from 'k6/metrics';
import ws from 'k6/ws';

/**
* 1. Run the PHP senders based on the amount of messages per second you want to receive.
* The sending rate influences the final benchmark.
*
* Low, 1 message per second:
* php send --interval 1 --port 6001
*
* Mild, 2 messages per second:
* php send --interval 0.5 --port 6002
*
* Overkill, 10 messages per second:
* php send --interval 0.1 --port 6003
*/

const delayTrend = new Trend('message_delay_ms');

export const options = {
thresholds: {
message_delay_ms: [
{ threshold: `p(95)<100`, abortOnFail: false },
{ threshold: `avg<100`, abortOnFail: false },
],
},

scenarios: {
// Keep connected many users users at the same time.
soakTraffic: {
executor: 'ramping-vus',
startVUs: 0,
startTime: '0s',
stages: [
{ duration: '50s', target: 250 },
{ duration: '110s', target: 250 },
],
env: {
SLEEP_FOR: '160',
WS_HOST: __ENV.WS_HOST || 'ws://127.0.0.1:6001/app/app-key',
},
},

// Having high amount of connections and disconnections
// representing active traffic that starts after 5 seconds
// from the soakTraffic scenario.
highTraffic: {
executor: 'ramping-vus',
startVUs: 0,
startTime: '50s',
stages: [
{ duration: '50s', target: 250 },
{ duration: '30s', target: 250 },
{ duration: '10s', target: 100 },
{ duration: '10s', target: 50 },
{ duration: '10s', target: 100 },
],
gracefulRampDown: '20s',
env: {
SLEEP_FOR: '160',
WS_HOST: __ENV.WS_HOST || 'ws://127.0.0.1:6001/app/app-key',
},
},
},
};

export default () => {
ws.connect(__ENV.WS_HOST, null, (socket) => {
socket.setTimeout(() => {
socket.close();
}, __ENV.SLEEP_FOR * 1000);

socket.on('open', () => {
// Keep connection alive with pusher:ping
socket.setInterval(() => {
socket.send(JSON.stringify({
event: 'pusher:ping',
data: JSON.stringify({}),
}));
}, 30000);

socket.on('message', message => {
let receivedTime = Date.now();

message = JSON.parse(message);

if (message.event === 'pusher:connection_established') {
socket.send(JSON.stringify({
event: 'pusher:subscribe',
data: { channel: 'benchmark' },
}));
}

if (message.event === 'timed-message') {
let data = JSON.parse(message.data);

delayTrend.add(receivedTime - data.time);
}
});
});
});
}
12 changes: 12 additions & 0 deletions benchmark/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "soketi/soketi-benchmark",
"type": "package",
"license": "MIT",
"minimum-stability": "dev",
"require": {
"pusher/pusher-php-server": "^7.0",
"nesbot/carbon": "^2.0",
"ratchet/pawl": "dev-master",
"toolkit/pflag": "dev-main"
}
}
Loading