Skip to content

Commit d48c439

Browse files
author
Igor Lins e Silva
committed
3.0.1-beta.1
1 parent 1409453 commit d48c439

File tree

10 files changed

+276
-68
lines changed

10 files changed

+276
-68
lines changed

chains/example.config.json

+19-12
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,20 @@
4545
"deltas": []
4646
},
4747
"scaling": {
48-
"batch_size": 10000,
49-
"queue_limit": 50000,
50-
"readers": 1,
51-
"ds_queues": 1,
52-
"ds_threads": 1,
53-
"ds_pool_size": 1,
54-
"indexing_queues": 1,
55-
"ad_idx_queues": 1,
56-
"max_autoscale": 4,
48+
"readers": 1,
49+
"ds_queues": 1,
50+
"ds_threads": 1,
51+
"ds_pool_size": 1,
52+
"indexing_queues": 1,
53+
"ad_idx_queues": 1,
54+
"max_autoscale": 4,
55+
"batch_size": 5000,
56+
"resume_trigger": 5000,
5757
"auto_scale_trigger": 20000,
58-
"routing_mode": "heatmap"
58+
"block_queue_limit": 10000,
59+
"max_queue_limit": 100000,
60+
"routing_mode": "heatmap",
61+
"polling_interval": 10000
5962
},
6063
"indexer": {
6164
"start_on": 0,
@@ -84,8 +87,12 @@
8487
"voters": true
8588
},
8689
"index_deltas": true,
87-
"index_transfer_memo": true,
88-
"index_all_deltas": true
90+
"index_transfer_memo": false,
91+
"index_all_deltas": true,
92+
"deferred_trx": false,
93+
"failed_trx": true,
94+
"resource_limits": false,
95+
"resource_usage": false
8996
},
9097
"prefetch": {
9198
"read": 50,

helpers/common_functions.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import {ApiResponse, Client} from "@elastic/elasticsearch";
22
import {Serialize} from "../addons/eosjs-native";
33

4-
const config = require(`../${process.env.CONFIG_JSON}`);
4+
let config;
5+
try {
6+
config = require(`../${process.env.CONFIG_JSON}`);
7+
} catch (e) {
8+
console.log(`Configuration not found: ${process.env.CONFIG_JSON}`);
9+
process.exit(1);
10+
}
11+
512
const CHAIN = config.settings.chain;
613

714
function getLastResult(results: ApiResponse) {

interfaces/hyperionConfig.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
export interface ScalingConfigs {
2+
polling_interval: number;
3+
resume_trigger: number;
4+
max_queue_limit: number;
5+
block_queue_limit: number;
26
routing_mode: string;
37
batch_size: number;
48
queue_limit: number;
@@ -110,7 +114,11 @@ export interface HyperionConfig {
110114
},
111115
index_deltas: boolean,
112116
index_transfer_memo: boolean,
113-
index_all_deltas: boolean
117+
index_all_deltas: boolean,
118+
deferred_trx: boolean,
119+
failed_trx: boolean,
120+
resource_usage: boolean,
121+
resource_limits: boolean,
114122
};
115123

116124
prefetch: {

modules/loader.ts

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export class HyperionModuleLoader {
1818
constructor(private cm: ConfigurationModule) {
1919
this.conn = cm.connections;
2020
this.config = cm.config;
21+
if (!this.conn.chains[this.config.settings.chain]) {
22+
console.log('Chain ' + this.config.settings.chain + ' not defined on connections.json!');
23+
process.exit(0);
24+
}
2125
this.chainID = this.conn.chains[this.config.settings.chain].chain_id;
2226
this.loadActionHandlers();
2327
this.loadParser().catch((err) => {

modules/master.ts

+92-18
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ import * as cluster from "cluster";
3434
import {Worker} from "cluster";
3535
import {HyperionWorkerDef} from "../interfaces/hyperionWorkerDef";
3636
import {HyperionConfig} from "../interfaces/hyperionConfig";
37-
import moment = require("moment");
38-
import Timeout = NodeJS.Timeout;
3937

4038
import {AsyncQueue, queue} from "async";
39+
import moment = require("moment");
40+
import Timeout = NodeJS.Timeout;
4141

4242
export class HyperionMaster {
4343

@@ -86,7 +86,6 @@ export class HyperionMaster {
8686
private lastProducer: string = null;
8787
private handoffCounter: number = 0;
8888
private missedRounds: object = {};
89-
private blockMsgQueue: any[] = [];
9089

9190
// IPC Messaging
9291
private totalMessages = 0;
@@ -134,6 +133,7 @@ export class HyperionMaster {
134133
private proposedSchedule: any;
135134
private wsRouterWorker: cluster.Worker;
136135
private liveBlockQueue: AsyncQueue<any>;
136+
private readingPaused = false;
137137

138138

139139
constructor() {
@@ -1140,17 +1140,65 @@ export class HyperionMaster {
11401140
}, 5000);
11411141
}
11421142

1143-
private monitorIndexingQueues() {
1144-
const limit = this.conf.scaling.auto_scale_trigger;
1145-
const autoscaleConsumers = {};
1146-
setInterval(async () => {
1147-
const testedQueues = new Set();
1148-
for (const worker of this.workerMap) {
1149-
if (worker.worker_role === 'ingestor') {
1150-
const queue = worker.queue;
1151-
if (!testedQueues.has(queue)) {
1152-
testedQueues.add(queue);
1153-
const size = await this.manager.checkQueueSize(queue);
1143+
private async checkQueues(autoscaleConsumers, limit) {
1144+
const testedQueues = new Set();
1145+
for (const worker of this.workerMap) {
1146+
let queue = worker.queue;
1147+
1148+
if (worker.worker_role === 'ds_pool_worker') {
1149+
queue = `${this.chain}:ds_pool:${worker.local_id}`;
1150+
}
1151+
1152+
if (queue) {
1153+
if (!testedQueues.has(queue)) {
1154+
testedQueues.add(queue);
1155+
const size = await this.manager.checkQueueSize(queue);
1156+
1157+
1158+
// pause readers if queues are above the max_limit
1159+
if (size >= this.conf.scaling.max_queue_limit) {
1160+
this.readingPaused = true;
1161+
for (const worker of this.workerMap) {
1162+
if (worker.worker_role === 'reader') {
1163+
worker.wref.send({event: 'pause'});
1164+
}
1165+
}
1166+
}
1167+
1168+
// resume readers if the queues are below the trigger point
1169+
if ((this.readingPaused && size <= this.conf.scaling.resume_trigger)) {
1170+
this.readingPaused = false;
1171+
for (const worker of this.workerMap) {
1172+
if (worker.worker_role === 'reader') {
1173+
worker.wref.send({event: 'pause'});
1174+
worker.wref.send({
1175+
event: 'set_delay',
1176+
data: {
1177+
state: false,
1178+
delay: 0
1179+
}
1180+
});
1181+
}
1182+
}
1183+
}
1184+
1185+
// apply block processing delay if 20% below max
1186+
if (size >= this.conf.scaling.max_queue_limit * 0.8) {
1187+
for (const worker of this.workerMap) {
1188+
if (worker.worker_role === 'reader') {
1189+
worker.wref.send({
1190+
event: 'set_delay',
1191+
data: {
1192+
state: true,
1193+
delay: 500
1194+
}
1195+
});
1196+
}
1197+
}
1198+
}
1199+
1200+
1201+
if (worker.worker_role === 'ingestor') {
11541202
if (size > limit) {
11551203
if (!autoscaleConsumers[queue]) {
11561204
autoscaleConsumers[queue] = 0;
@@ -1164,14 +1212,24 @@ export class HyperionMaster {
11641212
});
11651213
this.launchWorkers();
11661214
autoscaleConsumers[queue]++;
1167-
} else {
1168-
// hLog(`WARN: Max consumer limit reached on ${queue}!`);
11691215
}
11701216
}
11711217
}
11721218
}
11731219
}
1174-
}, 20000);
1220+
}
1221+
}
1222+
1223+
private monitorIndexingQueues() {
1224+
const limit = this.conf.scaling.auto_scale_trigger;
1225+
const autoscaleConsumers = {};
1226+
this.checkQueues(autoscaleConsumers, limit).catch(console.log);
1227+
if (!this.conf.scaling.polling_interval) {
1228+
this.conf.scaling.polling_interval = 20000;
1229+
}
1230+
setInterval(async () => {
1231+
await this.checkQueues(autoscaleConsumers, limit);
1232+
}, this.conf.scaling.polling_interval);
11751233
}
11761234

11771235
private onPm2Stop() {
@@ -1350,6 +1408,22 @@ export class HyperionMaster {
13501408

13511409
async runMaster() {
13521410

1411+
// config checks
1412+
if (!this.conf.scaling.max_queue_limit) {
1413+
hLog(`scaling.max_queue_limit is not defined!`);
1414+
process.exit(1);
1415+
}
1416+
1417+
if (!this.conf.scaling.resume_trigger) {
1418+
hLog(`scaling.resume_trigger is not defined!`);
1419+
process.exit(1);
1420+
}
1421+
1422+
if (!this.conf.scaling.block_queue_limit) {
1423+
hLog(`scaling.block_queue_limit is not defined!`);
1424+
process.exit(1);
1425+
}
1426+
13531427
this.printMode();
13541428

13551429
// Preview mode - prints only the proposed worker map
@@ -1365,7 +1439,7 @@ export class HyperionMaster {
13651439
this.printActiveProds();
13661440
}
13671441

1368-
// ELasticsearch
1442+
// Elasticsearch
13691443
this.client = this.manager.elasticsearchClient;
13701444
try {
13711445
const esInfo = await this.client.info();

package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hyperion-history",
3-
"version": "3.0.0-beta.4",
3+
"version": "3.0.1-beta.1",
44
"description": "Scalable Full History API Solution for EOSIO based blockchains",
55
"main": "launcher.js",
66
"scripts": {
@@ -55,11 +55,11 @@
5555
"socket.io-redis": "5.2.0",
5656
"ws": "7.3.0",
5757
"yargs": "15.3.1",
58-
"typescript": "3.9.2"
58+
"typescript": "3.9.3"
5959
},
6060
"devDependencies": {
6161
"@types/ioredis": "4.16.2",
62-
"@types/lodash": "4.14.151",
62+
"@types/lodash": "4.14.152",
6363
"@types/amqplib": "0.5.13",
6464
"@types/async": "3.2.3",
6565
"@types/got": "9.6.11",

run.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ echo -e "\n-->> Starting $1..."
1010
echo -e "\n-->> Saving pm2 state..."
1111
(set -x; pm2 save)
1212
echo -e "\n-->> Reading $1 logs..."
13-
(set -x; pm2 logs --raw --lines 0 "$@")
13+
(set -x; pm2 logs --raw --lines 10 "$@")

0 commit comments

Comments
 (0)