Mintrawa | hive-fr.com avatar

HIVE Nodes Checker (Backend & Frontend)

mintrawa

Published: 02 Jan 2022 › Updated: 02 Jan 2022HIVE Nodes Checker (Backend & Frontend)

HIVE Nodes Checker (Backend & Frontend)

hive_nodes_checker.jpg


Following a conversation, last week, started about the implementation of the load balancing of HIVE nodes depending on the user's geolocation, I thought it would be nice to share with the HIVE developer community a Typescript service I made and use in some of my applications (Backend & Frontend).

After a few days to extract my service and transform it into an installable package (what I am not used to) I can finally give you the HIVE Nodes Checker.


HIVE nodes checker

Regularly checks availability and performance of HIVE blockchain RPC nodes asynchronously, stores/updates the result in an in-memory array, and sends the result through a subscription (RxJS).

Two modes

Lightweight mode

In this mode, only one call to the condenser_api.get_config method is made on each node, The version executed on the node is retrieved and the response time is calculated by hrtime.

The message sent by RxJS is:

[{
  "url": string
  "nb_ok": number
  "nb_error": number
  "error"?: string
  "last_check": number
  "status": "unkown"|"online"|"degraded"|"error"
  "duration"?: number
  "average_time"?: number
  "version"?: string
  "deactivated"?: boolean

  "test_result":   []
}]

nb_ok and nb_error are incremented each time, allowing you to calculate an efficiency rate.

Full mode

In this case the methods below are checked:

condenser_api.get_config
condenser_api.get_dynamic_global_properties
condenser_api.get_block
condenser_api.get_accounts
condenser_api.get_account_history
bridge.get_post
bridge.get_account_posts

The version executed on the node is retrieved, the response time is calculated by hrtime and an average answer time is calculated.

The message sent by RxJS is:

[{
  "url": string
  "nb_ok": number
  "nb_error": number
  "error"?: string
  "last_check": number
  "status": "unkown"|"online"|"degraded"|"error"
  "duration"?: number
  "average_time"?: number
  "version"?: string
  "deactivated"?: boolean

  "test_result":   [{
    "name": string
    "description": string
    "method": string
    "success": boolean
    "duration": number
    "error"?: string
    "last_check": number
  }]
}]

Params

  • url: array of node url to check
  • options (optional):
    • full (boolean): if false perform only a get_config with response time (default: false)
    • interval (seconds): delay in seconds between each execution (default: 900 seconds)
    • timeout (seconds): timeout in seconds for node request (default: 3 seconds)

Example usage

Performing a full checking:

import { HiveNodesChecker } from '@mintrawa/hive-nodes-checker'

/** HIVE nodes url to check */
const nodes = [
  "https://api.hive.blog",
  "https://api.openhive.network",
  "https://api.deathwing.me",
  "https://rpc.ausbit.dev",
  "https://rpc.ecency.com",
  "https://hive-api.arcange.eu",
]

/** Options */
const options = {
  full: true,
  interval: 600 // 10 minutes
}
/** Init the checker */
const nodesChecker = new HiveNodesChecker(nodes, options)
/** Start the checker */
nodesChecker.start()
/** Subscribe results */
nodesChecker.message.subscribe({
  next: async m => {
    console.log('=====> NEW MESSAGE', m)
    console.log()
  },
  error: error => {
    console.log('=====> ERROR MESSAGE')
    console.log(error)
    console.log()
  }
})  

Github: https://github.com/Mintrawa/hive-nodes-checker
NPM: https://www.npmjs.com/package/@mintrawa/hive-nodes-checker


Tested in NodeJS v16.13.1 with a Raspberry PI3 1Gb
Tested in Angular v13.1.1
Tested in Chrome browser (HTML with the minified version)


Original photo by Lars Kienle on Unsplash


My HIVE witness servers

PRINCIPAL
BACKUP/SEED
CPU:Intel Xeon E3-1270v6CPU: Intel Xeon E3-1230v6
4 Cores/8 Threads 3.5 GHz/3.9 GHz4 Cores/8 Threads 3.8 GHz/4.2 GHz
RAM: 32GB DDR4 ECC 2133MHzRAM: 32GB DDR4 ECC 2133MHz
HDD: 1 To SSD NVMeHDD: 1 To SSD NVMe


Vote for my HIVE witness: click here (via HiveSigner)

Leave HIVE Nodes Checker (Backend & Frontend) to:

Written by

Witness FR - Hive FR | Gen X - Geek 🤓 Gamer 🎮 traveler ⛩️

Read more #hive-139531 posts


Best Posts From Mintrawa | hive-fr.com

We have not curated any of mintrawa's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Mintrawa | hive-fr.com