feat: add WORKER_COUNT env var

Signed-off-by: Ricardo Arturo Cabral Mejía <me@ricardocabral.io>
This commit is contained in:
Ricardo Arturo Cabral Mejía
2022-12-28 21:45:20 -05:00
parent 71301ae166
commit a1b83b7c56
4 changed files with 18 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ The following environment variables can be set:
| Name | Description | Default |
|------------------|--------------------------------|------------------------|
| RELAY_PORT | Relay's server port | 8008 |
| WORKER_COUNT | Number of workers override | No. of available CPUs |
| DB_HOST | PostgresSQL Hostname | |
| DB_PORT | PostgreSQL Port | 5432 |
| DB_USER | PostgreSQL Username | nostr_ts_relay |

View File

@@ -41,6 +41,8 @@ ARG REDISHOST
ARG REDISUSER
ARG REDISPORT
ARG REDISPASSWORD
ARG DEBUG
ARG WORKER_COUNT
ENV RELAY_PORT=$PORT
ENV DB_HOST=$PGHOST

View File

@@ -18,7 +18,8 @@ export class WebServerAdapter extends EventEmitter implements IWebServerAdapter
super()
this.webServer
.on('request', this.onRequest.bind(this))
.on('clientError', this.onError.bind(this))
.on('error', this.onError.bind(this))
.on('clientError', this.onClientError.bind(this))
.once('close', this.onClose.bind(this))
.once('listening', this.onListening.bind(this))
}
@@ -59,7 +60,13 @@ export class WebServerAdapter extends EventEmitter implements IWebServerAdapter
}
}
private onError(error: Error, socket: Duplex) {
private onError(error: Error) {
debug('error: %o', error)
throw error
}
private onClientError(error: Error, socket: Duplex) {
debug('socket error: %o', error)
if (error['code'] === 'ECONNRESET' || !socket.writable) {
return

View File

@@ -46,7 +46,11 @@ export class App implements IRunnable {
logCentered(`v${packageJson.version} by Cameri`, width)
logCentered(`NIPs implemented: ${packageJson.supportedNips}`, width)
const workerCount = this.settingsFactory().workers?.count || cpus().length
const workerCount = process.env.WORKER_COUNT
? Number(process.env.WORKER_COUNT)
: this.settingsFactory().workers?.count || cpus().length
debug('env: %O', process.env)
for (let i = 0; i < workerCount; i++) {
debug('starting worker')
@@ -81,7 +85,7 @@ export class App implements IRunnable {
}
private onExit() {
debug('exiting')
console.log('exiting')
this.process.exit(0)
}
}