torrust-tracker icon indicating copy to clipboard operation
torrust-tracker copied to clipboard

Profiling for the UDP Tracker

Open josecelano opened this issue 1 year ago • 6 comments

Use valgrind and kcachegrind to do profiling of the UDP tracker.

We've implemented several torrent repository implementations but before continue improving further I would like to have some metrics.

josecelano avatar Mar 20 '24 10:03 josecelano

The main function:

image

josecelano avatar Mar 20 '24 11:03 josecelano

I've added a new binary for profiling. What I'm doing to profile is:

  • Run the tracker for 60 seconds
  • At the same time run the Aquatic UDP load test

The problem is we use threads and functions inside threads don't appear in the kcachegrind graphs. I have not been able to extract interesting conclusions from the report yet.

There are other alternatives for profiling async applications in Rust. There are some ideas in this talk by @bravit:

https://www.youtube.com/watch?v=8FAdY_0DpkM

Some alternatives are:

  1. Just print time in the code in the functions we want to profile.
  2. Use futures_diagnose, a crate to profile async functions.
  3. Use tokio-console, an application to monitor what happens inside tokio-spawned tasks.

I think I'm going to try option 1. I want to confirm that the main bottleneck is the torrust repository.

cc @da2ce7

josecelano avatar Mar 20 '24 15:03 josecelano

Main function

image

image

Process valid request

image

Some potential conclusions (not sure)

From the graphs above it seems:

  • 17.9% of the effective time processing a request is dedicated to allocating and freeing memory.
  • 14.66% if for entry and get BTreeMap functions.
  • The cookie builder for connections takes 11.55% of the time processing requests probably due to the hash algorithm.
  • It's strange that only 54.75% of the time if processing request :-/

josecelano avatar Mar 20 '24 16:03 josecelano

I accidentally changed the number of active requests from 50 to 1000 while I was doing some tests with different parameters:

#[derive(Default)]
struct ActiveRequests {
    rb: StaticRb<AbortHandle, 50>, // the number of requests we handle at the same time.
}

josecelano avatar Mar 20 '24 16:03 josecelano

I'm also using flamegraph.

I think I still have to adjust some OD parameters to get a better graph:

flamegraph

josecelano avatar Mar 21 '24 06:03 josecelano

Zooming in on the part tho handle the announce request:

image

josecelano avatar Mar 21 '24 10:03 josecelano