mirror of
https://github.com/Cameri/nostream.git
synced 2025-12-05 18:21:31 +01:00
feat: add WORKER_COUNT env var
Signed-off-by: Ricardo Arturo Cabral Mejía <me@ricardocabral.io>
This commit is contained in:
@@ -7,6 +7,7 @@ The following environment variables can be set:
|
|||||||
| Name | Description | Default |
|
| Name | Description | Default |
|
||||||
|------------------|--------------------------------|------------------------|
|
|------------------|--------------------------------|------------------------|
|
||||||
| RELAY_PORT | Relay's server port | 8008 |
|
| RELAY_PORT | Relay's server port | 8008 |
|
||||||
|
| WORKER_COUNT | Number of workers override | No. of available CPUs |
|
||||||
| DB_HOST | PostgresSQL Hostname | |
|
| DB_HOST | PostgresSQL Hostname | |
|
||||||
| DB_PORT | PostgreSQL Port | 5432 |
|
| DB_PORT | PostgreSQL Port | 5432 |
|
||||||
| DB_USER | PostgreSQL Username | nostr_ts_relay |
|
| DB_USER | PostgreSQL Username | nostr_ts_relay |
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ ARG REDISHOST
|
|||||||
ARG REDISUSER
|
ARG REDISUSER
|
||||||
ARG REDISPORT
|
ARG REDISPORT
|
||||||
ARG REDISPASSWORD
|
ARG REDISPASSWORD
|
||||||
|
ARG DEBUG
|
||||||
|
ARG WORKER_COUNT
|
||||||
|
|
||||||
ENV RELAY_PORT=$PORT
|
ENV RELAY_PORT=$PORT
|
||||||
ENV DB_HOST=$PGHOST
|
ENV DB_HOST=$PGHOST
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ export class WebServerAdapter extends EventEmitter implements IWebServerAdapter
|
|||||||
super()
|
super()
|
||||||
this.webServer
|
this.webServer
|
||||||
.on('request', this.onRequest.bind(this))
|
.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('close', this.onClose.bind(this))
|
||||||
.once('listening', this.onListening.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)
|
debug('socket error: %o', error)
|
||||||
if (error['code'] === 'ECONNRESET' || !socket.writable) {
|
if (error['code'] === 'ECONNRESET' || !socket.writable) {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -46,7 +46,11 @@ export class App implements IRunnable {
|
|||||||
logCentered(`v${packageJson.version} by Cameri`, width)
|
logCentered(`v${packageJson.version} by Cameri`, width)
|
||||||
logCentered(`NIPs implemented: ${packageJson.supportedNips}`, 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++) {
|
for (let i = 0; i < workerCount; i++) {
|
||||||
debug('starting worker')
|
debug('starting worker')
|
||||||
@@ -81,7 +85,7 @@ export class App implements IRunnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private onExit() {
|
private onExit() {
|
||||||
debug('exiting')
|
console.log('exiting')
|
||||||
this.process.exit(0)
|
this.process.exit(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user