#relay #nostr #benchmark #events #connect #connection #url

bin+lib nostr-bench

Nostr relay benchmarking tool

6 releases (3 breaking)

0.4.0 Jul 4, 2023
0.3.0 Mar 22, 2023
0.2.1 Mar 21, 2023
0.1.1 Feb 26, 2023

#303 in WebSocket

31 downloads per month

MIT license

34KB
763 lines

Nostr relay benchmaker


cargo install nostr-bench
nostr-bench --help

# Usage: nostr-bench <COMMAND>
# 
# Commands:
#   connect  Benchmark create websocket connections
#   echo     Benchmark send websocket message, the server should send back the message
#   event    Benchmark publish nostr event
#   req      Benchmark request nostr event
#   help     Print this message or the help of the given subcommand(s)


nostr-bench connect --help

# Usage: nostr-bench connect [OPTIONS] <URL>
# 
# Arguments:
#   <URL>  Nostr relay host url
# 
# Options:
#   -c, --count <NUM>      Max count of clients [default: 100]
#   -r, --rate <NUM>       Start open connection rate every second [default: 50]
#   -k, --keepalive <NUM>  Close connection after second, ignore when set to 0 [default: 0]
#   -t, --threads <NUM>    Set the amount of threads, default 0 will use all system available cores [default: 0]
#   -i, --interface <IP>   Network interface address list
#       --json             Display stats information as json, time format as milli seconds
#   -h, --help             Print help

Get more connections

Since the system limits a network interface to connect up to 64k, you can set --interface to bind more interface to increase the number of connections

nostr-bench connect 'ws://127.0.0.1:8080' --interface 192.168.0.2 --interface 192.168.0.3

Increase resource usage limits

Linux

ulimit -n 1000000
sudo sysctl -w net.ipv4.ip_local_port_range="1025 65534"

Mac OS


ulimit -n 1000000
# sysctl net.inet.ip.portrange
sudo sysctl -w net.inet.ip.portrange.first=1025
sudo sysctl -w net.inet.ip.portrange.last=65534

Dependencies

~20–32MB
~526K SLoC