You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/DEPLOYMENT.md
+49Lines changed: 49 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -165,6 +165,55 @@ server {
165
165
166
166
---
167
167
168
+
## Database Connection Pool Tuning
169
+
170
+
The backend uses TypeORM with a MySQL2 connection pool. Two environment variables control pool behavior:
171
+
172
+
| Variable | Default | Description |
173
+
|----------|---------|-------------|
174
+
|`DB_POOL_SIZE`|`20`| Maximum number of simultaneous DB connections |
175
+
|`DB_QUERY_TIMEOUT`|`10000`| Slow query warning threshold (ms). TypeORM logs a warning when exceeded but does **not** kill the query; use DB-level `wait_timeout` for hard kills. |
- A pool that is **too small** causes connection queuing under load, increasing API latency.
188
+
- A pool that is **too large** exhausts MariaDB's `max_connections` (default 151). Leave headroom for admin connections.
189
+
- Rule of thumb: `DB_POOL_SIZE` × number of app replicas < `max_connections − 10`.
190
+
191
+
### Slow query logging
192
+
193
+
In non-production environments (`NODE_ENV !== 'production'`), TypeORM also logs every query. Watch the logs for `[TypeORM] query: SELECT …` lines that take longer than `DB_QUERY_TIMEOUT` — these are candidates for index optimization.
194
+
195
+
To suppress verbose query logs on a staging server while keeping slow-query warnings:
196
+
197
+
```dotenv
198
+
NODE_ENV=production
199
+
DB_QUERY_TIMEOUT=5000
200
+
```
201
+
202
+
### Additional MariaDB server tuning
203
+
204
+
For high-concurrency OJ workloads, also tune the DB server itself:
205
+
206
+
```ini
207
+
# /etc/mysql/mariadb.conf.d/99-oj.cnf
208
+
[mysqld]
209
+
max_connections = 200
210
+
wait_timeout = 30
211
+
interactive_timeout = 30
212
+
innodb_buffer_pool_size = 1G # adjust to available RAM
0 commit comments