Run Bisq block parse in separate Worker Thread.
This commit is contained in:
parent
2715d02cf9
commit
7bf9810c48
5
backend/package-lock.json
generated
5
backend/package-lock.json
generated
@ -881,6 +881,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
|
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
|
||||||
"integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw=="
|
"integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw=="
|
||||||
},
|
},
|
||||||
|
"node-worker-threads-pool": {
|
||||||
|
"version": "1.4.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/node-worker-threads-pool/-/node-worker-threads-pool-1.4.2.tgz",
|
||||||
|
"integrity": "sha512-jU4NKLJacA8nfoYz1Uey18z3gqDfR/CX3PEqlNagtbTR+08pFQiB/ZyvpdDRkvgBrYz5yFCStCQYX659YCqrkg=="
|
||||||
|
},
|
||||||
"oauth-sign": {
|
"oauth-sign": {
|
||||||
"version": "0.9.0",
|
"version": "0.9.0",
|
||||||
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz",
|
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz",
|
||||||
|
@ -27,9 +27,10 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"compression": "^1.7.4",
|
"compression": "^1.7.4",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"mysql2": "^1.6.1",
|
|
||||||
"request": "^2.88.2",
|
|
||||||
"locutus": "^2.0.12",
|
"locutus": "^2.0.12",
|
||||||
|
"mysql2": "^1.6.1",
|
||||||
|
"node-worker-threads-pool": "^1.4.2",
|
||||||
|
"request": "^2.88.2",
|
||||||
"ws": "^7.3.1"
|
"ws": "^7.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -4,7 +4,9 @@ import * as request from 'request';
|
|||||||
import { BisqBlocks, BisqBlock, BisqTransaction, BisqStats, BisqTrade } from './interfaces';
|
import { BisqBlocks, BisqBlock, BisqTransaction, BisqStats, BisqTrade } from './interfaces';
|
||||||
import { Common } from '../common';
|
import { Common } from '../common';
|
||||||
import { Block } from '../../interfaces';
|
import { Block } from '../../interfaces';
|
||||||
|
import { StaticPool } from 'node-worker-threads-pool';
|
||||||
import logger from '../../logger';
|
import logger from '../../logger';
|
||||||
|
|
||||||
class Bisq {
|
class Bisq {
|
||||||
private static BLOCKS_JSON_FILE_PATH = '/all/blocks.json';
|
private static BLOCKS_JSON_FILE_PATH = '/all/blocks.json';
|
||||||
private latestBlockHeight = 0;
|
private latestBlockHeight = 0;
|
||||||
@ -24,6 +26,10 @@ class Bisq {
|
|||||||
private priceUpdateCallbackFunction: ((price: number) => void) | undefined;
|
private priceUpdateCallbackFunction: ((price: number) => void) | undefined;
|
||||||
private topDirectoryWatcher: fs.FSWatcher | undefined;
|
private topDirectoryWatcher: fs.FSWatcher | undefined;
|
||||||
private subdirectoryWatcher: fs.FSWatcher | undefined;
|
private subdirectoryWatcher: fs.FSWatcher | undefined;
|
||||||
|
private jsonParsePool = new StaticPool({
|
||||||
|
size: 4,
|
||||||
|
task: (blob: string) => JSON.parse(blob),
|
||||||
|
});
|
||||||
|
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
@ -237,7 +243,7 @@ class Bisq {
|
|||||||
const start = new Date().getTime();
|
const start = new Date().getTime();
|
||||||
if (cacheData && cacheData.length !== 0) {
|
if (cacheData && cacheData.length !== 0) {
|
||||||
logger.debug('Processing Bisq data dump...');
|
logger.debug('Processing Bisq data dump...');
|
||||||
const data: BisqBlocks = JSON.parse(cacheData);
|
const data: BisqBlocks = await this.jsonParsePool.exec(cacheData);
|
||||||
if (data.blocks && data.blocks.length !== this.blocks.length) {
|
if (data.blocks && data.blocks.length !== this.blocks.length) {
|
||||||
this.blocks = data.blocks.filter((block) => block.txs.length > 0);
|
this.blocks = data.blocks.filter((block) => block.txs.length > 0);
|
||||||
this.blocks.reverse();
|
this.blocks.reverse();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user