Skip to content

Commit

Permalink
perf changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Testnet Deployer committed Nov 11, 2019
1 parent 17558ad commit 9271615
Show file tree
Hide file tree
Showing 17 changed files with 271 additions and 137 deletions.
70 changes: 26 additions & 44 deletions clusters/jormungandr-performance.nix
@@ -1,9 +1,23 @@
{ targetEnv, tiny, large }:
{ targetEnv, tiny, medium, large }:
let
mkNodes = import ../nix/mk-nodes.nix { inherit targetEnv; };
pkgs = import ../nix { };
lib = pkgs.lib;

mkStakes = region: amount: {
inherit amount;
imports = [ medium ../roles/jormungandr-stake.nix ];
deployment.ec2.region = region;
node.isStake = true;
};

mkRelays = region: amount: {
inherit amount;
imports = [ medium ../roles/jormungandr-relay.nix ];
deployment.ec2.region = region;
node.isRelay = true;
};

nodes = mkNodes {
monitoring = {
imports = [ large ../roles/monitor.nix ];
Expand All @@ -12,60 +26,28 @@ let
};

explorer = {
imports = [ tiny ../roles/jormungandr-explorer.nix ];
imports = [ medium ../roles/jormungandr-explorer.nix ];
deployment.ec2.region = "eu-central-1";
node.isExplorer = true;
node.isRelay = true;
};

jormungandr-faucet = {
imports = [ tiny ../roles/jormungandr-faucet.nix ];
faucet = {
imports = [ medium ../roles/jormungandr-faucet.nix ];
deployment.ec2.region = "eu-central-1";
node.isFaucet = true;
};

stake-a = {
amount = 13;
imports = [ tiny ../roles/jormungandr-stake.nix ];
deployment.ec2.region = "us-west-1";
node.isStake = true;
};

stake-b = {
amount = 13;
imports = [ tiny ../roles/jormungandr-stake.nix ];
deployment.ec2.region = "ap-northeast-1";
node.isStake = true;
};

stake-c = {
amount = 13;
imports = [ tiny ../roles/jormungandr-stake.nix ];
deployment.ec2.region = "eu-central-1";
node.isStake = true;
};

relay-a = {
amount = 2;
imports = [ tiny ../roles/jormungandr-relay.nix ];
deployment.ec2.region = "us-west-1";
node.isRelay = true;
};

relay-b = {
amount = 2;
imports = [ tiny ../roles/jormungandr-relay.nix ];
deployment.ec2.region = "ap-northeast-1";
node.isRelay = true;
};
stake-a = mkStakes "us-west-1" 333;
stake-b = mkStakes "ap-northeast-1" 333;
stake-c = mkStakes "eu-central-1" 334;

relay-c = {
amount = 2;
imports = [ tiny ../roles/jormungandr-relay.nix ];
deployment.ec2.region = "eu-central-1";
node.isRelay = true;
};
relay-a = mkRelays "us-west-1" 2;
relay-b = mkRelays "ap-northeast-1" 2;
relay-c = mkRelays "eu-central-1" 2;
};
in {
network.description = "jormungandr-performance";
network.description = "Jormungandr Performance";
network.enableRollback = true;
} // nodes
2 changes: 1 addition & 1 deletion deployments/jormungandr-nightly.nix
Expand Up @@ -9,7 +9,7 @@ let

cluster = import ../clusters/jormungandr-testnet2.nix {
targetEnv = "ec2";
tiny = ../physical/aws/t3a.xlarge.nix;
tiny = ../physical/aws/t3a.medium.nix;
large = ../physical/aws/t3.xlarge.nix;
};

Expand Down
10 changes: 6 additions & 4 deletions deployments/jormungandr-performance-aws.nix
Expand Up @@ -9,7 +9,8 @@ let

cluster = import ../clusters/jormungandr-performance.nix {
targetEnv = "ec2";
tiny = ../physical/aws/t3a.medium.nix;
tiny = ../physical/aws/t3a.small.nix;
medium = ../physical/aws/t3a.medium.nix;
large = ../physical/aws/t3.xlarge.nix;
};

Expand All @@ -22,11 +23,12 @@ let

securityGroupFiles = [
../physical/aws/security-groups/allow-all.nix
../physical/aws/security-groups/allow-ssh.nix
../physical/aws/security-groups/allow-deployer-ssh.nix
../physical/aws/security-groups/allow-graylog.nix
../physical/aws/security-groups/allow-jormungandr.nix
../physical/aws/security-groups/allow-monitoring-collection.nix
../physical/aws/security-groups/allow-public-www-https.nix
../physical/aws/security-groups/allow-jormungandr.nix
../physical/aws/security-groups/allow-graylog.nix
../physical/aws/security-groups/allow-ssh.nix
];

importSecurityGroup = region: file:
Expand Down
128 changes: 128 additions & 0 deletions dpl.cr
@@ -0,0 +1,128 @@
#!/usr/bin/env crystal

require "json"

def nixops(args : Array(String))
pretty = (["nixops"] + args.map{|arg|
case arg
when Array(String)
"'#{arg.join(" ")}'"
else
arg
end
}).join(" ")

puts pretty

if system("nixops", args)
puts "ok."
else
STDERR.puts "failed with #{$?.exit_status}"
end
end

def deploy(args)
nixops(["deploy"] + args)
end

def nix_eval(something)
Array(String).from_json(
`nix eval --json '((import ./scripts/nodes.nix).#{something}Names)'`
)
end

def resources
nix_eval("initalResources")
end

def nixops_info
lines = `nixops info --no-eval`.each_line.map do |line|
line.split("|").map{|col| col.strip }
end

i = lines.index([""]) || 0

lines.to_a[(i+4)..-2].map{|line|
{
name: line[1],
status: line[2],
type: line[3],
id: line[4],
ip: line[5]
}
}
end

machines = {
relays: nix_eval("relays"),
stakes: nix_eval("stakes")
}

# puts "initial check..."
# machines.each do |key, all_names|
# (all_names).each_slice(500) do |names|
# nixops(["check", "--include"] + names)
# end
# end

to_deploy = [] of String
to_stop = [] of String

info = nixops_info
info.each do |i|
next unless i[:type].split.first == "ec2"
status = i[:status].split("/").first.strip
name = i[:name]

case status
when "Missing"
to_deploy << name
when "Stopped"
when "Unreachable"
when "Up"
to_stop << name if machines[:stakes].includes?(name)
end
end

if to_stop.any?
puts "stopping #{to_stop.join(' ')}"
nixops(
[ "ssh-for-each", "-p", "--include" ] +
to_stop +
["--", "
if [[ -d /var/lib/jormungandr ]]; then
systemctl stop jormungandr;
rm -rf /var/lib/jormungandr;
systemctl poweroff;
fi
"]
)
exit
end

puts "total #{machines[:relays].size} relays"
puts " #{machines[:stakes].size} stakes"
puts " #{resources.size} resources"
puts "deploying monitoring and initial resources..."

# deploy ["--kill-obsolete", "--include", "monitoring", "monitoring-ip"] + resources

puts "now deploying #{to_deploy.size} machines..."

from_here = false

machines.each do |key, all_names|
all_names.each_slice(25) do |names|
if names.includes?("stake-c-225")
from_here = true
end

next unless from_here

ips = names.map{|name| "#{name}-ip" }
args = ["--include"] + (names + ips).sort
deploy args
end
end

puts "Nothing left to do"
13 changes: 10 additions & 3 deletions genesis-generator/default.nix
@@ -1,8 +1,12 @@
let
ada = n: n * 1000000; # lovelace
in {
stakePoolCount ? 7
, stakePoolBalances ? __genList (_: ada 10000000) stakePoolCount
in
{ stakePoolCount ? 1500
, stakePoolBalances ? __concatLists [
(__genList (_: ada 1000000000) 50)
(__genList (_: ada 30000000 ) 1450)
(__genList (_: ada 6500000000) 1)
]
, inputParams ? {}
}:

Expand All @@ -11,6 +15,7 @@ let
commonLib = import sources.iohk-nix {};
inherit (commonLib.pkgs) lib;
pkgs = import sources.nixpkgs {};

inputConfig = __toFile "input.json" (__toJSON ({
inherit stakePoolBalances stakePoolCount;
inputBlockchainConfig = blockchainConfig;
Expand Down Expand Up @@ -51,6 +56,7 @@ in lib.fix (self: {
mkdir -pv $out/bin/
ghc ./main.hs -o $out/bin/genesis-generator
'';

helper = pkgs.writeShellScript "helper" ''
set -e
export PATH=${lib.makeBinPath [ self.jcli ]}:$PATH
Expand All @@ -60,6 +66,7 @@ in lib.fix (self: {
jcli --version
jcli genesis encode < genesis.yaml > block-0.bin
'';

tester = pkgs.writeShellScript "tester" ''
set -e
export PATH=${lib.makeBinPath [ self.jcli self.jormungandr ]}:$PATH
Expand Down
2 changes: 1 addition & 1 deletion genesis-generator/main.hs
Expand Up @@ -174,7 +174,7 @@ main = do
allFunds :: [Value]
allFunds = map generateFund list2
-- join all stake pool funding and extra funding, then split into chunks of 255
chunkedFunds = chunksOf 255 (allFunds <> extraFunds cfg)
chunkedFunds = chunksOf 254 (allFunds <> extraFunds cfg)
-- split all legacy funds into chunks of 254
legacyChunks = chunksOf 254 (extraLegacyFunds cfg)
-- wrap a legacy fund with {"legacy_fund":[...]}
Expand Down
2 changes: 1 addition & 1 deletion modules/common.nix
Expand Up @@ -100,6 +100,6 @@ in {
}];

deployment.ec2.securityGroups = [
resources.ec2SecurityGroups."allow-graylog-${name}-${config.node.region}"
resources.ec2SecurityGroups."allow-graylog-${config.node.region}"
];
}
31 changes: 31 additions & 0 deletions modules/janalyze.nix
@@ -0,0 +1,31 @@
{ pkgs, config, ... }:
let
janalyzer = pkgs.writeShellScript "janalyzer" ''
mkdir -p /var/lib/janalyze
${pkgs.janalyze}/bin/janalyze -x > /var/lib/janalyze
'';
in {
systemd.services.janalyze = {
after = [ "jormungandr.service" ];

description = ''
Gather statistics using Jormungandr Analyze script
'';

serviceConfig = {
DynamicUser = true;
User = "janalyze";
StateDirectory = "/var/lib/janalyze";
Restart = "always";
ExecStart = janalyzer;
};
};

systemd.timers.janalyze = {
description = ''
Gather statistics using Jormungandr Analyze
'';
wantedBy = [ "timers.target" ];
timerConfig.OnCalendar = "29m";
};
}
10 changes: 5 additions & 5 deletions modules/jormungandr.nix
Expand Up @@ -8,7 +8,7 @@ let

compact = l: filter (e: e != null) l;
peerAddress = nodeName: node:
if node.config.node.isRelay then
if node.config.node.isRelay && (nodeName != name) then
{
address = node.config.services.jormungandr.publicAddress;
id = publicIds.${nodeName};
Expand Down Expand Up @@ -67,10 +67,10 @@ in {

services.jormungandr-monitor = {
enable = true;
genesisYaml =
if (builtins.pathExists ../static/genesis.yaml)
then ../static/genesis.yaml
else null;
# genesisYaml =
# if (builtins.pathExists ../static/genesis.yaml)
# then ../static/genesis.yaml
# else null;
};

services.nginx.enableReload = true;
Expand Down
3 changes: 3 additions & 0 deletions modules/monitoring-services.nix
Expand Up @@ -1004,6 +1004,9 @@ in {
};
mongodb.enable = true;
};

systemd.services.prometheus.serviceConfig.LimitNOFILE = "524288";

systemd.services.graylog-preload = let
graylogConfig = ./graylog/graylogConfig.json;
password = traceValFn (x:
Expand Down

0 comments on commit 9271615

Please sign in to comment.