Skip to content

Commit

Permalink
rpc connections and machine type changes (#333)
Browse files Browse the repository at this point in the history
* reduce rpc connections

reduce rpc connections to 6000

change machine types

* add rate-limit to RPCs traefik

* add RPC nginx configs

* add 429 status code and error page

* increase rpc connections more

* fix typo

* increase keepaliverequest

* reduce substrate peers and increase DSN peers

* increase domain rpc connections
  • Loading branch information
DaMandal0rian authored Aug 27, 2024
1 parent c190aac commit 40e9d57
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 30 deletions.
9 changes: 6 additions & 3 deletions ansible/network/files/docker-compose-autoid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ services:
"--listen-on", "/ip4/0.0.0.0/tcp/30333",
"--listen-on", "/ip6/::/tcp/30333",
"--node-key", "${NODE_KEY}",
"--in-peers", "500",
"--out-peers", "250",
"--rpc-max-connections", "10000",
"--dsn-in-connections", "500",
"--dsn-out-connections", "250",
"--in-peers", "250",
"--out-peers", "150",
"--rpc-max-connections", "1000",
"--rpc-cors", "all",
"--rpc-listen-on", "0.0.0.0:9944",
"--rpc-methods", "safe",
Expand All @@ -135,6 +137,7 @@ services:
"--rpc-cors", "all",
"--rpc-listen-on", "0.0.0.0:8944",
"--rpc-methods", "safe",
"--rpc-max-connections", "10000",
"--operator-id", "0",
"--reserved-nodes", "/dns/bootstrap-0.autoid.${NETWORK_NAME}.subspace.network/tcp/30334/p2p/${NODE_0_OPERATOR_AUTO_PEER_ID}",
"--bootstrap-nodes", "/dns/bootstrap-0.autoid.${NETWORK_NAME}.subspace.network/tcp/30334/p2p/${NODE_0_OPERATOR_AUTO_PEER_ID}",
Expand Down
9 changes: 6 additions & 3 deletions ansible/network/files/docker-compose-domain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ services:
"--listen-on", "/ip4/0.0.0.0/tcp/30333",
"--listen-on", "/ip6/::/tcp/30333",
"--node-key", "${NODE_KEY}",
"--in-peers", "500",
"--out-peers", "250",
"--rpc-max-connections", "10000",
"--dsn-in-connections", "500",
"--dsn-out-connections", "250",
"--in-peers", "250",
"--out-peers", "150",
"--rpc-max-connections", "1000",
"--rpc-cors", "all",
"--rpc-listen-on", "0.0.0.0:9944",
"--rpc-methods", "safe",
Expand All @@ -136,6 +138,7 @@ services:
"--rpc-cors", "all",
"--rpc-listen-on", "0.0.0.0:8944",
"--rpc-methods", "safe",
"--rpc-max-connections", "10000",
"--operator-id", "0",
"--reserved-nodes", "/dns/bootstrap-0.nova.${NETWORK_NAME}.subspace.network/tcp/30334/p2p/${NODE_0_OPERATOR_PEER_ID}",
"--bootstrap-nodes", "/dns/bootstrap-0.nova.${NETWORK_NAME}.subspace.network/tcp/30334/p2p/${NODE_0_OPERATOR_PEER_ID}",
Expand Down
8 changes: 5 additions & 3 deletions ansible/network/files/docker-compose-rpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ services:
"--dsn-external-address", "/ip6/${EXTERNAL_IP_V6}/udp/30433/quic-v1",
"--dsn-external-address", "/ip6/${EXTERNAL_IP_V6}/tcp/30433",
"--node-key", "${NODE_KEY}",
"--in-peers", "500",
"--out-peers", "250",
"--rpc-max-connections", "10000",
"--dsn-in-connections", "500",
"--dsn-out-connections", "250",
"--in-peers", "250",
"--out-peers", "150",
"--rpc-max-connections", "20000",
"--rpc-cors", "all",
"--rpc-listen-on", "0.0.0.0:9944",
"--rpc-methods", "safe",
Expand Down
6 changes: 3 additions & 3 deletions resources/gemini-3h/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ variable "domain_labels" {
variable "instance_type" {
type = map(string)
default = {
bootstrap = "c7a.4xlarge"
rpc = "m6a.xlarge"
domain = "m6a.xlarge"
bootstrap = "c7a.2xlarge"
rpc = "m7a.xlarge"
domain = "m7a.xlarge"
rpc-squid = "c7a.2xlarge"
nova-squid = "c7a.2xlarge"
farmer = "c7a.2xlarge"
Expand Down
46 changes: 46 additions & 0 deletions templates/configs/rpcs/backend.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Define a zone for rate limiting
limit_req_zone $binary_remote_addr zone=rpc-limt:10m rate=200r/s;
limit_req_status 429;

map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

server {
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;

# Apply rate limiting to all locations
limit_req zone=rpc-limt burst=300 nodelay;

# Custom error page for 429
error_page 429 /rate_limit.html;
location = /rate_limit.html {
internal;
return 429 '{"error": "Too Many Requests", "message": "Rate limit exceeded. Please slow down."}';
}

location / {
proxy_buffering off;
proxy_pass http://127.0.0.1:9944;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
}

location /ws {
proxy_pass http://127.0.0.1:9944;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_buffers 16 16k;
proxy_buffer_size 16k;
proxy_set_header Upgrade "$http_upgrade";
proxy_set_header Connection $connection_upgrade;
proxy_cache_bypass $http_upgrade;
}
}
108 changes: 108 additions & 0 deletions templates/configs/rpcs/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
user www-data;
worker_processes auto;
worker_rlimit_nofile 32000;
pid /run/nginx.pid;
#include /etc/nginx/modules-enabled/*.conf;
#load_module modules/ngx_http_modsecurity_module.so;

events {
worker_connections 4096;
multi_accept on;
use epoll;
}

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 120;
send_timeout 120;
keepalive_requests 50000;
keepalive_disable none;
reset_timedout_connection on;
proxy_ignore_client_abort on;
client_body_timeout 120;
client_header_timeout 120;
types_hash_max_size 2048;
underscores_in_headers on;
# server_tokens off;

server_names_hash_bucket_size 128;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/json;

# Buffers
client_body_buffer_size 128K;
client_header_buffer_size 1k;
client_max_body_size 1m;
large_client_header_buffers 4 64k;

##
# SSL Settings
##
ssl_protocols TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE and TLS 1.1, ref: BEAST/CRIME
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:20m;
ssl_session_timeout 10m;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
ssl_stapling on;
ssl_stapling_verify on;

# Security
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload";
add_header X-XSS-Protection "1; mode=block";
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options nosniff;


# Add CORS for Explorer
#add_header Access-Control-Allow-Origin *;
#add_header Access-Control-Max-Age 3600;
#add_header Access-Control-Expose-Headers Content-Length;


# Proxy settings
proxy_read_timeout 120;
proxy_connect_timeout 75;
proxy_send_timeout 120;
proxy_intercept_errors on;

##
# Logging Settings
##

log_format compression '$remote_addr - [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $gzip_ratio';

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;

gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_comp_level 2;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/backend.conf;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
9 changes: 7 additions & 2 deletions templates/scripts/create_domain_node_compose_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,14 @@ services:
- "traefik.http.routers.archival-node.tls=true"
- "traefik.http.routers.archival-node.tls.certresolver=le"
- "traefik.http.routers.archival-node.entrypoints=websecure"
- "traefik.http.routers.archival-node.middlewares=redirect-https"
- "traefik.http.routers.archival-node.middlewares=redirect-https,rate-limit"
- "traefik.http.middlewares.redirect-https.redirectscheme.scheme=https"
- "traefik.http.middlewares.redirect-https.redirectscheme.permanent=true"
- "traefik.docker.network=traefik-proxy"
# Rate limiting configuration
- "traefik.http.middlewares.rate-limit.ratelimit.average=200"
- "traefik.http.middlewares.rate-limit.ratelimit.burst=300"
- "traefik.http.middlewares.rate-limit.ratelimit.period=1s"
networks:
- traefik-proxy
logging:
Expand All @@ -116,7 +120,7 @@ services:
"--node-key", "\${NODE_KEY}",
"--in-peers", "500",
"--out-peers", "250",
"--rpc-max-connections", "15000",
"--rpc-max-connections", "1000",
"--rpc-cors", "all",
"--rpc-listen-on", "0.0.0.0:9944",
"--rpc-methods", "safe",
Expand Down Expand Up @@ -168,6 +172,7 @@ if [ "${enable_domains}" == "true" ]; then
echo ' "--rpc-cors", "all",'
echo ' "--rpc-methods", "safe",'
echo ' "--rpc-listen-on", "0.0.0.0:8944",'
echo ' "--rpc-max-connections", "10000",'

for (( i = 0; i < bootstrap_node_evm_count; i++ )); do
addr=$(sed -nr "s/NODE_${i}_MULTI_ADDR_TCP=//p" ~/subspace/bootstrap_node_evm_keys.txt)
Expand Down
8 changes: 6 additions & 2 deletions templates/scripts/create_rpc_node_compose_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ services:
- "traefik.http.routers.archival-node.tls=true"
- "traefik.http.routers.archival-node.tls.certresolver=le"
- "traefik.http.routers.archival-node.entrypoints=websecure"
- "traefik.http.routers.archival-node.middlewares=redirect-https"
- "traefik.http.routers.archival-node.middlewares=redirect-https,rate-limit"
- "traefik.http.middlewares.redirect-https.redirectscheme.scheme=https"
- "traefik.http.middlewares.redirect-https.redirectscheme.permanent=true"
- "traefik.docker.network=traefik-proxy"
# Rate limiting configuration
- "traefik.http.middlewares.rate-limit.ratelimit.average=200"
- "traefik.http.middlewares.rate-limit.ratelimit.burst=300"
- "traefik.http.middlewares.rate-limit.ratelimit.period=1s"
ports:
- "9615:9615"
networks:
Expand All @@ -113,7 +117,7 @@ services:
"--node-key", "\${NODE_KEY}",
"--in-peers", "500",
"--out-peers", "250",
"--rpc-max-connections", "15000",
"--rpc-max-connections", "20000",
"--rpc-cors", "all",
"--rpc-listen-on", "0.0.0.0:9944",
"--rpc-methods", "safe",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ services:
"--listen-on", "/ip4/0.0.0.0/tcp/30333",
"--listen-on", "/ip6/::/tcp/30333",
"--node-key", "\${NODE_KEY}",
"--in-peers", "500",
"--out-peers", "250",
"--rpc-max-connections", "10000",
"--dsn-in-connections", "500",
"--dsn-out-connections", "250",
"--in-peers", "250",
"--out-peers", "150",
"--rpc-max-connections", "1000",
"--rpc-cors", "all",
"--rpc-listen-on", "0.0.0.0:9944",
"--rpc-methods", "safe",
Expand Down Expand Up @@ -138,6 +140,7 @@ if [ "${enable_domains}" == "true" ]; then
echo ' "--rpc-cors", "all",'
echo ' "--rpc-methods", "safe",'
echo ' "--rpc-listen-on", "0.0.0.0:8944",'
echo ' "--rpc-max-connections", "10000",'

for (( i = 0; i < bootstrap_node_autoid_count; i++ )); do
addr=$(sed -nr "s/NODE_${i}_MULTI_ADDR_TCP=//p" ~/subspace/bootstrap_node_autoid_keys.txt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ services:
"--listen-on", "/ip4/0.0.0.0/tcp/30333",
"--listen-on", "/ip6/::/tcp/30333",
"--node-key", "\${NODE_KEY}",
"--in-peers", "500",
"--out-peers", "250",
"--rpc-max-connections", "10000",
"--dsn-in-connections", "500",
"--dsn-out-connections", "250",
"--in-peers", "250",
"--out-peers", "150",
"--rpc-max-connections", "1000",
"--rpc-cors", "all",
"--rpc-listen-on", "0.0.0.0:9944",
"--rpc-methods", "safe",
Expand Down Expand Up @@ -138,6 +140,7 @@ if [ "${enable_domains}" == "true" ]; then
echo ' "--rpc-cors", "all",'
echo ' "--rpc-methods", "safe",'
echo ' "--rpc-listen-on", "0.0.0.0:8944",'
echo ' "--rpc-max-connections", "10000",'

for (( i = 0; i < bootstrap_node_evm_count; i++ )); do
addr=$(sed -nr "s/NODE_${i}_MULTI_ADDR_TCP=//p" ~/subspace/bootstrap_node_evm_keys.txt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ services:
"--dsn-external-address", "/ip6/$EXTERNAL_IP_V6/udp/30433/quic-v1",
"--dsn-external-address", "/ip6/$EXTERNAL_IP_V6/tcp/30433",
"--node-key", "\${NODE_KEY}",
"--in-peers", "500",
"--out-peers", "250",
"--rpc-max-connections", "10000",
"--dsn-in-connections", "500",
"--dsn-out-connections", "250",
"--in-peers", "250",
"--out-peers", "150",
"--rpc-max-connections", "20000",
"--rpc-cors", "all",
"--rpc-listen-on", "0.0.0.0:9944",
"--rpc-methods", "safe",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ services:
# "--dsn-external-address", "/ip4/$EXTERNAL_IP/udp/30433/quic-v1",
# "--dsn-external-address", "/ip4/$EXTERNAL_IP/tcp/30433",
"--node-key", "\${NODE_KEY}",
"--in-peers", "500",
"--out-peers", "250",
"--rpc-max-connections", "10000",
"--dsn-in-connections", "500",
"--dsn-out-connections", "250",
"--in-peers", "250",
"--out-peers", "150",
"--rpc-max-connections", "1000",
"--rpc-cors", "all",
"--rpc-listen-on", "0.0.0.0:9944",
"--rpc-methods", "safe",
Expand Down Expand Up @@ -91,6 +93,7 @@ if [ "${enable_domains}" == "true" ]; then
echo ' "--rpc-cors", "all",'
echo ' "--rpc-methods", "safe",'
echo ' "--rpc-listen-on", "0.0.0.0:8944",'
echo ' "--rpc-max-connections", "10000",'

for (( i = 0; i < bootstrap_node_evm_count; i++ )); do
addr=$(sed -nr "s/NODE_${i}_MULTI_ADDR=//p" ~/subspace/bootstrap_node_evm_keys.txt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ services:
"--dsn-external-address", "/ip4/$EXTERNAL_IP/udp/30433/quic-v1",
"--dsn-external-address", "/ip4/$EXTERNAL_IP/tcp/30433",
"--node-key", "\${NODE_KEY}",
"--in-peers", "500",
"--out-peers", "250",
"--dsn-in-connections", "500",
"--dsn-out-connections", "250",
"--in-peers", "250",
"--out-peers", "150",
"--rpc-max-connections", "10000",
"--rpc-cors", "all",
"--rpc-listen-on", "0.0.0.0:9944",
Expand Down

0 comments on commit 40e9d57

Please sign in to comment.