Skip to content

tetragon: Add bench application #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 20, 2022
Merged

tetragon: Add bench application #261

merged 9 commits into from
Sep 20, 2022

Conversation

olsajiri
Copy link
Contributor

@olsajiri olsajiri commented Jul 26, 2022

Adding benchmark application to measure tracing workloads.

The tetragon-bench application starts tetragon (or not for -baseline option)
for given CRD file and runs workload.

At the end it displays some stats, like:

Benchmark summary
-----------------
Test started:      2022-09-08 15:04:28.04513503 +0200 CEST m=+0.016539427
Test ended:        2022-09-08 15:04:38.268072909 +0200 CEST m=+10.239477312
Workload start:    2022-09-08 15:04:38.268072909 +0200 CEST m=+10.239477312
Arguments:         
Total duration:    10.222937885s
Setup duration:    1.743823005s
Workload duration: 8.479094472s
Test duration:     10.222937885s
Export duration:   0s
Export stats:      bytes=0, writes=0
FGS cpu usage:     system=15.170223s, user=17.522276s, rss=230504, ctxsw=1231909
Ring buffer:       received=3958406, lost=41842, errors=0
BPF statistics:
  event_execve                   [tracepoint/212]   :   8.89µs (2)
  event_wake_up_new_task         [kprobe/211]       :   1.41µs (6)
  generic_kprobe_event           [kprobe/205]       :   1.54µs (4001580)
  restrict_filesystems           [lsm/58]           :   0.13µs (1569)
  event_exit                     [tracepoint/210]   :   0.49µs (32)

It's possible to run predefined workloads with builtin CRD files,
or run specific custom benchmark.

The predefined benchmarks are rw and open and can be run with:

# ./tetragon-bench -trace rw
# ./tetragon-bench -trace open

They do and monitor some simple read/write open operations and they are there
mainly to show the possibility of builtin benchmark if we think it's good idea ;-)

The custom benchmark is what I'm using most at the moment and
it allows to pass CRD file to start tetragon with and specify workload, like:

# ./tetragon-bench -crd crds/examples/names.yaml  -- perf bench sched pipe

I'm doing perf profiles to check on CRD stuff with:

# perf record -g -e cycles:k ./tetragon-bench -crd ./read_write.yaml -json-encode -- perf bench sched pipe

Signed-off-by: Jiri Olsa [email protected]

@olsajiri olsajiri force-pushed the bench branch 4 times, most recently from 1730ea3 to c4394ab Compare September 8, 2022 13:05
@olsajiri olsajiri marked this pull request as ready for review September 8, 2022 13:55
@olsajiri olsajiri requested a review from a team as a code owner September 8, 2022 13:55
@olsajiri olsajiri requested a review from jrfastab September 8, 2022 13:55

if _, err := os.Stat(option.Config.HubbleLib); err != nil {
// Running outside the source tree, fall back to default location.
option.Config.HubbleLib = "/var/lib/hubble-fgs"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, will use that one, thanks

)

func EnableBpfStats() {
err := os.WriteFile("/proc/sys/kernel/bpf_stats_enabled", []byte("1"), 0666)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the perm mode ok? maybe restrict it a bit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that permission will be used only if the file does not exist and needs to be created, so we are fine here

func CPUUsageFromCPUAcct(containerID string) CPUUsage {

rss := int64(0)
memStatFilename := fmt.Sprintf("/sys/fs/cgroup/memory/docker/%s/memory.stat", containerID)
Copy link
Member

@tixxdz tixxdz Sep 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this seems cgroupv1 hierarchy, I assume that this could also run in cgroupv2 the path would be /sys/fs/cgroup/$path/%s/memory.stat in that case where $path does not container the 'memory' directory or controller as it is unified.

You could use this new helper:
https://github.com/cilium/tetragon/blob/main/pkg/cgroups/cgroups.go#L567 if it returns CGROUP_UNIFIED then you are in pure cgroupv2 and you have to fix that path without 'memory' directory, for everything else you can assume cgroupv1 that is the one that is used to track resources. Hybrid cgroupv2 is only used to organize processes together but resources tracking at cgroupv1.

It would be cool if we can standardize on those ;-) !

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw where this is called?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full cgroup path may not container docker directory at all or another container runtime, I'm missing context, but if you could read /proc/self/cgroups and adapt according to cgroup version and the controllers you are interested in to get right working paths without hardcoding it here. There is some logic in that cgroups.go package

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, I'll remove it for now, because it's not used and check on that more, thanks

Copy link
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Some minor requests / suggestions.

Leftover changes from 'make generate'.

Signed-off-by: Jiri Olsa <[email protected]>
Adding summary object to carry all the measured data
and doing the results output.

Signed-off-by: Jiri Olsa <[email protected]>
Adding base of the bench package, that allows to run observer
with custom configuration and provides generic arguments.

Signed-off-by: Jiri Olsa <[email protected]>
Adding interface to quesry bpfstats data from bpf programs.

Signed-off-by: Jiri Olsa <[email protected]>
Adding util object that carries some other helper objects.

Signed-off-by: Jiri Olsa <[email protected]>
Adding tetragon-bench application to meassure tracing workloads.

It runs benchmark specified with -trace option. At the moment there
is no benchmark defined, they are coming in following changes.

Signed-off-by: Jiri Olsa <[email protected]>
Adding benchmark that does many read and writes in multiple threads
and monitors all this data in tetragon.

Could be run with:
  # ./tetragon-bench -trace rw

And configured with extra options:

  -bench-rw-count uint
        bench rw read/write count (default 100)
  -bench-rw-loops uint
        bench rw number of loops (default 100)
  -bench-rw-size uint
        bench rw buffer size (default 1024)
  -bench-rw-threads uint
        bench rw number of threads (default 4)
  -bench-rw-sleep uint
        bench rw sleep in ms (default 1)

Signed-off-by: Jiri Olsa <[email protected]>
Adding benchmark that does many failed open syscalls
and monitors them in tetragon.

Could be run with:
  # ./tetragon-bench -trace open

And configured with extra options:

  -bench-open-loops uint
        bench open number of loops (default 1000000)
  -bench-open-sleep uint
        bench open sleep between open syscalls (us) (default 1)
  -bench-open-threads uint
        bench open number of threads (default 4)

Signed-off-by: Jiri Olsa <[email protected]>
Allows to run custom benchmark with specific crd file, like:

  # ./tetragon-bench -crd crds/examples/names.yaml  -- perf bench sched pipe

Or with perf sampling:

  # perf record -g -e cycles:k ./tetragon-bench -crd ./read_write.yaml -json-encode -- perf bench sched pipe

Arguments after '--' will be executed as workload. When workload
is finished the bench will exit.

Signed-off-by: Jiri Olsa <[email protected]>
Copy link
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@kkourt kkourt merged commit 0d408db into cilium:main Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants