Introduction
Chainstack offers nodes in geo-diverse locations.
You may want to do a quick latency test to see the speed from from your server to the Chainstack node.
Running a ping, tracert, or a traceroute command will show lost packets and won't produce results.
The utilities ping, tracert, and traceroute rely on ICMP, which is disabled by default on the instances running the nodes for security reasons.
Solution
nmap
Use nmap to check the latency:
nmap -p 80 HOSTNAME
where HOSTNAME is your node's hostname. See View node access and credentials.
Example:
nmap -p 80 nd-123-456-789.p2pify.com
time
You can send an RPC call to the node's endpoint and time the result:
time curl 'HTTPS_ENDPOINT' -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}'
where HTTPS_ENDPOINT is your node's hostname. See View node access and credentials.
Example:
time curl 'https://nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531d' -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}'
Python
If you want to log the latency data into a csv file, using mainly requests library:
import requests
import csv
import time
from datetime import datetime
import os
# Define the node URL
# Define the request payload
payload = {
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": [],
"id": 1
}
csv_file = "gepeto_log.csv"
# Function to initialize the CSV file with headers
def initialize_csv():
if not os.path.exists(csv_file):
with open(csv_file, mode="w", newline='') as file:
writer = csv.writer(file)
writer.writerow(["Timestamp", "Method", "Response Time"])
# Function to log details to CSV
def log_to_csv(method, response_time):
with open(csv_file, mode="a", newline='') as file:
writer = csv.writer(file)
writer.writerow([datetime.now(), method, response_time])
# Function to send request and measure latency
def send_request():
start_time = time.time()
response = requests.post(node_url, json=payload)
end_time = time.time()
latency = end_time - start_time
log_to_csv(payload["method"], latency)
return response.json()
# Initialize the CSV file
initialize_csv()
# Main loop to send requests and log latency
while True:
try:
response = send_request()
print(f"Block Number: {response['result']}")
except Exception as e:
print(f"An error occurred: {e}")
time.sleep(5) # Wait for 5 seconds before sending the next request
Comments
0 comments
Article is closed for comments.