Skip to content
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
31 changes: 31 additions & 0 deletions PROFILING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# CPU Profiling Guide

This guide explains how to profile the ActivityPub server to diagnose CPU spikes and performance issues.

## Quick Start

**Start profiling mode:**
```bash
yarn dev:profile
```

## Profile Files Location

CPU profiles are saved to the `./profiles/` directory with timestamps:
```
profiles/
├── CPU.20240123.142547.001.0.001.cpuprofile
├── CPU.20240123.142612.002.0.001.cpuprofile
└── ...
```

## Analyzing Profiles

### Chrome DevTools

1. Open Chrome and go to `chrome://inspect`
2. Click "Open dedicated DevTools for Node"
3. Go to the **"Performance"** tab (not Profiler tab)
4. Click the "Load profile" button (folder icon)
5. Select your `.cpuprofile` file
6. Analyze the flame graph and call tree
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
- ./src:/opt/activitypub/src
- ./dist:/opt/activitypub/dist
- dev-content:/opt/activitypub/content
- ./profiles:/opt/activitypub/profiles
environment:
- PORT=8080
- MYSQL_USER=ghost
Expand Down Expand Up @@ -34,6 +35,7 @@ services:
- REDIS_HOST=redis
- REDIS_PORT=6379
- FEDIFY_KV_STORE_TYPE=redis
- ENABLE_PROFILING=${ENABLE_PROFILING:-false}
command: yarn build:watch
depends_on:
migrate:
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
"type": "module",
"scripts": {
"build": "esbuild src/app.ts --sourcemap --platform=neutral --bundle --packages=external --outfile=dist/app.js",
"build:watch": "concurrently \"yarn build --watch\" \"node --inspect=0.0.0.0:9229 --watch dist/app.js\"",
"build:watch": "concurrently \"yarn build --watch\" \"yarn _start:dev\"",
"_start:dev": "node --inspect=0.0.0.0:9229 ${ENABLE_PROFILING:+--cpu-prof --cpu-prof-dir=/opt/activitypub/profiles} --watch dist/app.js",
"predev": "docker compose build migrate fake-gcs",
"dev": "docker compose up activitypub nginx -d --build",
"dev:profile": "ENABLE_PROFILING=true docker compose up activitypub nginx -d --build",
"stop": "docker compose stop",
"db": "docker compose exec mysql mysql -uroot -proot activitypub",
"fix": "docker compose down --rmi all activitypub activitypub-testing cucumber-tests nginx",
Expand Down