Skip to content

Commit

Permalink
Merge pull request #1846 from OriginTrail/v6/bugfix/busyness-check
Browse files Browse the repository at this point in the history
fix select query and busyness check
  • Loading branch information
kotlarmilos authored Mar 24, 2022
2 parents a9562af + eb8f384 commit 968a20e
Show file tree
Hide file tree
Showing 5 changed files with 1,319 additions and 13 deletions.
2 changes: 2 additions & 0 deletions external/libp2p-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ class Libp2pService {
[preparedBlockedResponse],
stream
);
requestBlocked = true;
this.logger.info(`Blocking request from ${handlerProps.connection.remotePeer._idB58String}. Max number of requests exceeded.`);
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ exports.NETWORK_API_RATE_LIMIT_TIME_WINDOW_MILLS = 1 * 60 * 1000;
* @constant {number} NETWORK_API_RATE_LIMIT_MAX_NUMBER
* - Network (Libp2p) rate limit max number of requests allowed in the specified time window
*/
exports.NETWORK_API_RATE_LIMIT_MAX_NUMBER = 20;
exports.NETWORK_API_RATE_LIMIT_MAX_NUMBER = 10;

/**
* @constant {number} DID_PREFIX
Expand Down
14 changes: 11 additions & 3 deletions modules/service/data-service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { v1: uuidv1 } = require('uuid');
const N3 = require('n3');
const toobusy = require('toobusy-js');
const constants = require('../constants');
const GraphDB = require('../../external/graphdb-service');
const Blazegraph = require('../../external/blazegraph-service');
Expand Down Expand Up @@ -407,7 +408,6 @@ class DataService {
switch (type) {
case 'SELECT':
result = await this.tripleStoreQueue.push({ operation: 'select', query });
result = result.toString();
break;
case 'CONSTRUCT':
result = await this.tripleStoreQueue.push({ operation: 'construct', query });
Expand Down Expand Up @@ -643,7 +643,7 @@ class DataService {
}

async handleTripleStoreRequest(args) {
if (this.tripleStoreQueue.length() > constants.TRIPLE_STORE_QUEUE_LIMIT) {
if (this.getTripleStoreQueueLength() > constants.TRIPLE_STORE_QUEUE_LIMIT) {
throw new Error('Triple store queue is full');
}
const { operation } = args;
Expand Down Expand Up @@ -703,7 +703,15 @@ class DataService {
}

isNodeBusy(busynessLimit) {
return this.tripleStoreQueue.length > busynessLimit;
const isTripleStoreBusy = this.getTripleStoreQueueLength() > busynessLimit;
const isToobusy = toobusy();
if (isTripleStoreBusy) {
this.logger.info('TripleStore is busy.');
}
if (isToobusy) {
this.logger.info('TripleStore is busy.');
}
return isToobusy || isTripleStoreBusy;
}
}

Expand Down
Loading

0 comments on commit 968a20e

Please sign in to comment.