optimizations

This commit is contained in:
Ben Wilson
2023-08-04 16:34:49 -04:00
parent 6423e2cb67
commit f85967daf8
6 changed files with 55 additions and 17 deletions
+14 -1
View File
@@ -17,8 +17,13 @@ export class AppService implements OnModuleInit {
}
async onModuleInit() {
//https://phiresky.github.io/blog/2020/sqlite-performance-tuning/
//100 MB DB cache
await this.dataSource.query(`PRAGMA cache_size = -100000`);
await this.dataSource.query(`PRAGMA cache_size = -100000;`);
//Normal is still completely corruption safe in WAL mode, and means only WAL checkpoints have to wait for FSYNC.
await this.dataSource.query(`PRAGMA synchronous = normal;`);
//1Gb
await this.dataSource.query(`PRAGMA mmap_size = 1000000000;`);
}
@Cron(CronExpression.EVERY_HOUR)
@@ -30,4 +35,12 @@ export class AppService implements OnModuleInit {
console.log(`Deleted ${deletedClients.affected} old clients`);
}
}
// @Cron(CronExpression.EVERY_10_MINUTES)
// private async killDeadClients() {
// if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
// await this.clientService.killDeadClients();
// }
// }
}
+8 -9
View File
@@ -33,9 +33,9 @@ export class StratumV1Service implements OnModuleInit {
async onModuleInit(): Promise<void> {
//await this.clientStatisticsService.deleteAll();
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
await this.clientService.deleteAll();
}
await this.clientService.deleteAll();
this.startSocketServer();
}
@@ -61,28 +61,27 @@ export class StratumV1Service implements OnModuleInit {
promiseSocket.socket.on('end', async (error: Error) => {
// Handle socket disconnection
client.destroy();
promiseSocket.destroy();
await this.clientService.delete(client.extraNonceAndSessionId);
const clientCount = await this.clientService.connectedClientCount();
console.log(`Client disconnected, ${client.extraNonceAndSessionId}, ${clientCount} total clients`);
promiseSocket.destroy();
});
promiseSocket.socket.on('error', async (error: Error) => {
client.destroy();
promiseSocket.destroy();
await this.clientService.delete(client.extraNonceAndSessionId);
const clientCount = await this.clientService.connectedClientCount();
console.log(`Client disconnected, socket error, ${client.extraNonceAndSessionId}, ${clientCount} total clients`);
console.error(error);
promiseSocket.destroy();
//console.error(error);
});