Skip to content

Commit 59b4a37

Browse files
fmastemgmeier
authored andcommitted
wb | add optional cgroup memory workload
1 parent 8122755 commit 59b4a37

File tree

8 files changed

+184
-22
lines changed

8 files changed

+184
-22
lines changed

bench/cardano-profile/cardano-profile.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ library
7070
, Cardano.Benchmarking.Profile.Primitives
7171
, Cardano.Benchmarking.Profile.Vocabulary
7272
, Cardano.Benchmarking.Profile.Types
73+
, Cardano.Benchmarking.Profile.Workload.CGroupMemory
7374
, Cardano.Benchmarking.Profile.Workload.Latency
7475
, Cardano.Benchmarking.Profile.Workload.Voting
7576
build-depends: base >=4.12 && <5

bench/cardano-profile/src/Cardano/Benchmarking/Profile/Builtin/Cloud.hs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ profilesNoEraCloud =
145145
-- The name of the defined volume in the Nomad Client config and
146146
-- where to mount it inside the isolated chroot.
147147
-- If the volume is not present the deployment will fail!
148-
. P.nomadHostVolume (Types.ByNodeType {
148+
. P.appendNomadHostVolume (Types.ByNodeType {
149149
Types.producer = [Types.HostVolume "/ephemeral" False "ephemeral"]
150150
, Types.explorer = Nothing
151151
})
@@ -293,8 +293,8 @@ profilesNoEraCloud =
293293

294294
--------------------------------------------------------------------------------
295295

296-
nomadPerf :: Types.Profile -> Types.Profile
297-
nomadPerf =
296+
nomadPerfBase :: Types.Profile -> Types.Profile
297+
nomadPerfBase =
298298
-- Exact regions with availability zone (AZ) to match.
299299
P.regions
300300
[
@@ -306,20 +306,6 @@ nomadPerf =
306306
-- Logical cluster separation. To avoid conflicts with same-server machines.
307307
P.nomadNamespace "perf" . P.nomadClass "perf"
308308
.
309-
-- This will be used as constraints at the Task level.
310-
P.nomadResources (Types.ByNodeType {
311-
Types.producer = Types.Resources {
312-
Types.cores = 8
313-
, Types.memory = 15400
314-
, Types.memory_max = 16000
315-
}
316-
, Types.explorer = Just $ Types.Resources {
317-
Types.cores = 16
318-
, Types.memory = 32000
319-
, Types.memory_max = 64000
320-
}
321-
})
322-
.
323309
-- Instance types will be used as Group "constraints".
324310
P.awsInstanceTypes (Types.ByNodeType {
325311
Types.producer = "c5d.2xlarge"
@@ -340,3 +326,28 @@ nomadPerf =
340326
.
341327
-- Don't stop the Nomad Job when finished.
342328
P.clusterKeepRunningOn
329+
330+
nomadPerf :: Types.Profile -> Types.Profile
331+
nomadPerf =
332+
nomadPerfBase . nomadPerfResourcesAll
333+
334+
nomadPerfResourcesAll :: Types.Profile -> Types.Profile
335+
nomadPerfResourcesAll =
336+
-- This will be used as constraints at the Task level.
337+
P.nomadResources (Types.ByNodeType {
338+
Types.producer = Types.Resources {
339+
Types.cores = 8
340+
, Types.memory = 15400
341+
, Types.memory_max = 16000
342+
}
343+
-- Explorer is unchanged between cloud profiles.
344+
, Types.explorer = Just resourcesExplorer
345+
})
346+
347+
resourcesExplorer :: Types.Resources
348+
resourcesExplorer =
349+
Types.Resources {
350+
Types.cores = 16
351+
, Types.memory = 32000
352+
, Types.memory_max = 64000
353+
}

bench/cardano-profile/src/Cardano/Benchmarking/Profile/Extra/Scaling.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ clusterNomadSsdNoRegions =
100100
, Types.explorer = Just $ Types.Resources 16 120000 124000
101101
})
102102
.
103-
P.nomadHostVolume (
103+
P.appendNomadHostVolume (
104104
let hostVolumes =
105105
[ Types.HostVolume "/ssd1" False "ssd1"
106106
, Types.HostVolume "/ssd2" False "ssd2"

bench/cardano-profile/src/Cardano/Benchmarking/Profile/Primitives.hs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ module Cardano.Benchmarking.Profile.Primitives (
9999

100100
-- Cluster params.
101101
, clusterMinimunStorage, ssdDirectory, clusterKeepRunningOn
102-
, nomadNamespace, nomadClass, nomadResources, nomadHostVolume, nomadSSHLogsOn
103-
, awsInstanceTypes, usePublicRouting
102+
, nomadNamespace, nomadClass, nomadResources, appendNomadHostVolume
103+
, nomadSSHLogsOn, awsInstanceTypes, usePublicRouting
104104

105105
-- Analysis params.
106106
, analysisOff, analysisStandard, analysisPerformance
@@ -877,8 +877,12 @@ nomadClass nc = nomad (\n -> n {Types.nomad_class = nc})
877877
nomadResources :: Types.ByNodeType Types.Resources -> Types.Profile -> Types.Profile
878878
nomadResources r = nomad (\n -> n {Types.resources = r})
879879

880-
nomadHostVolume :: Types.ByNodeType [Types.HostVolume] -> Types.Profile -> Types.Profile
881-
nomadHostVolume h = nomad (\n -> n {Types.host_volumes = Just h})
880+
appendNomadHostVolume :: Types.ByNodeType [Types.HostVolume] -> Types.Profile -> Types.Profile
881+
appendNomadHostVolume h = nomad (\n -> n {Types.host_volumes = Just $
882+
case Types.host_volumes n of
883+
Nothing -> h
884+
(Just bnt) -> bnt <> h
885+
})
882886

883887
nomadSSHLogsOn :: Types.Profile -> Types.Profile
884888
nomadSSHLogsOn = nomad (\n -> n {Types.fetch_logs_ssh = True})

bench/cardano-profile/src/Cardano/Benchmarking/Profile/Types.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,12 @@ data ByNodeType a = ByNodeType
670670
}
671671
deriving (Eq, Show, Generic)
672672

673+
instance Semigroup a => Semigroup (ByNodeType a) where
674+
(ByNodeType p me) <> (ByNodeType p' me') = ByNodeType (p <> p') (me <> me')
675+
676+
instance Monoid a => Monoid (ByNodeType a) where
677+
mempty = ByNodeType mempty Nothing
678+
673679
instance Aeson.ToJSON a => Aeson.ToJSON (ByNodeType a)
674680

675681
instance Aeson.FromJSON a => Aeson.FromJSON (ByNodeType a)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{-# LANGUAGE Trustworthy #-}
2+
{-# LANGUAGE OverloadedStrings #-}
3+
4+
--------------------------------------------------------------------------------
5+
6+
module Cardano.Benchmarking.Profile.Workload.CGroupMemory (
7+
cgroupMemoryWorkload
8+
) where
9+
10+
--------------------------------------------------------------------------------
11+
12+
import Prelude
13+
-- Package: self.
14+
import qualified Cardano.Benchmarking.Profile.Types as Types
15+
16+
--------------------------------------------------------------------------------
17+
18+
cgroupMemoryWorkload :: Types.Workload
19+
cgroupMemoryWorkload = Types.Workload {
20+
Types.workloadName = "cgroup_memory"
21+
, Types.parameters = mempty
22+
, Types.entrypoints = Types.Entrypoints {
23+
Types.pre_generator = Nothing
24+
, Types.producers = "cgroup_memory"
25+
}
26+
, Types.wait_pools = True
27+
}

nix/workbench/backend/nomad.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3904,6 +3904,12 @@ client {
39043904
disable_file_sandbox = false
39053905
}
39063906
3907+
# Feature parity with the "nomadperf" cloud cluster.
3908+
host_volume "cgroup" {
3909+
path = "/sys/fs/cgroup"
3910+
read_only = true
3911+
}
3912+
39073913
# To use when resolving IPs.
39083914
#meta {
39093915
# my_ip = "${addr}"
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
{ pkgs
2+
, profile
3+
, nodeSpecs
4+
, workload
5+
}:
6+
7+
with pkgs.lib;
8+
9+
let
10+
bashInteractive = pkgs.bashInteractive;
11+
coreutils = pkgs.coreutils;
12+
jq = pkgs.jq;
13+
# Assumptions:
14+
# - Command `date` and node's log use the same timezone!
15+
in ''
16+
#!${bashInteractive}/bin/sh
17+
18+
######################################################################
19+
# Set script globals #################################################
20+
######################################################################
21+
22+
# Strict runtime
23+
################
24+
25+
# e: Immediately exit if any command has a non-zero exit status
26+
# u: Reference to non previously defined variables is an error
27+
# pipefail: Any failed command in a pipeline is used as return code
28+
set -euo pipefail
29+
30+
# Fetch all defined node names (Including "explorer" nodes)
31+
###########################################################
32+
33+
node_specs_nodes=$(${jq}/bin/jq --raw-output \
34+
"keys | join (\" \")" \
35+
../../node-specs.json \
36+
)
37+
node_specs_pools=$(${jq}/bin/jq \
38+
'map(select(.kind == "pool")) | length' \
39+
../../node-specs.json \
40+
)
41+
${coreutils}/bin/echo "node-specs.json:"
42+
${coreutils}/bin/echo "- Nodes: [''${node_specs_nodes[*]}]"
43+
${coreutils}/bin/echo "- Pools: ''${node_specs_pools}"
44+
45+
# Look for locally deployed nodes and save starting time
46+
########################################################
47+
48+
nodes=()
49+
started_time=$(${coreutils}/bin/date +%s)
50+
for node in ''${node_specs_nodes[*]}
51+
do
52+
if test -d "../../''${node}"
53+
then
54+
nodes+=("''${node}")
55+
# Save the starting time
56+
${coreutils}/bin/echo "''${started_time}" > "./start_time_''${node}"
57+
fi
58+
done
59+
${coreutils}/bin/echo "Found deployed nodes:"
60+
${coreutils}/bin/echo "- Nodes: [''${nodes[*]}]"
61+
62+
######################################################################
63+
# Main ###############################################################
64+
######################################################################
65+
66+
# The entrypoint function.
67+
function cgroup_memory() {
68+
69+
msg "Started!"
70+
71+
local jobs_array=()
72+
for node in ''${nodes[*]}
73+
do
74+
cgroup_memory_deployed "''${node}" &
75+
jobs_array+=("$!")
76+
done
77+
wait "''${jobs_array[@]}"
78+
}
79+
80+
function cgroup_memory_deployed() {
81+
local node=$1
82+
83+
msg "Starting node: ''${node}"
84+
85+
local cgroup
86+
cgroup="$(${coreutils}/bin/cat /proc/self/cgroup | ${coreutils}/bin/cut -d: -f3)"
87+
msg "CGroup found for \"''${node}\": ''${cgroup}"
88+
89+
while true
90+
do
91+
${coreutils}/bin/cat /sys/fs/cgroup"''${cgroup}"/memory.stat \
92+
> "./memory.stat_''${node}-''$(${coreutils}/bin/date +"%Y-%m-%d-%H-%M-%S-%3N")"
93+
${coreutils}/bin/sleep 60
94+
done
95+
}
96+
97+
######################################################################
98+
# Utils ##############################################################
99+
######################################################################
100+
101+
function msg {
102+
# Outputs to stdout, unbuffered if not the message may be lost!
103+
${coreutils}/bin/stdbuf -o0 \
104+
${bashInteractive}/bin/sh -c \
105+
"${coreutils}/bin/echo -e \"$(${coreutils}/bin/date --rfc-3339=seconds): $1\""
106+
}
107+
''

0 commit comments

Comments
 (0)