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 checkoptions
(optional):full
(boolean): if false perform only aget_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)
My HIVE witness servers
CPU:Intel Xeon E3-1270v6 | CPU: Intel Xeon E3-1230v6 |
4 Cores/8 Threads 3.5 GHz/3.9 GHz | 4 Cores/8 Threads 3.8 GHz/4.2 GHz |
RAM: 32GB DDR4 ECC 2133MHz | RAM: 32GB DDR4 ECC 2133MHz |
HDD: 1 To SSD NVMe | HDD: 1 To SSD NVMe |
Vote for my HIVE witness: click here (via HiveSigner)
The rewards earned on this comment will go directly to the person sharing the post on Twitter as long as they are registered with @poshtoken. Sign up at https://hiveposh.com.
Congratulations @mintrawa! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s):
Your next target is to reach 400 replies.
You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
Check out the last post from @hivebuzz: