flt.utils.muxer: replace queue with array
authorSimon Marchi <simon.marchi@efficios.com>
Sun, 22 May 2022 19:46:36 +0000 (15:46 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 15 Jun 2022 18:15:50 +0000 (14:15 -0400)
commit30799132cd92de929a90ae6e366bfe5032cfd241
tree53baa57a21b9dadf11c73f3e2967f5fbcb2d3bd4
parent088b0bbe10be6143d390eff198c459cc03333650
flt.utils.muxer: replace queue with array

While profiling, I noticed "a lot" of time spent in g_queue* functions,
in the context of the muxer.  Using a dummy output and an LTTng kernel
trace as input, 2.7% of the time was spent in g_queue_pop_head and
1.92% in g_queue_push_tail.  Under those, most of the time was spent in
memory allocation functions.

For something fast path like the muxer's message queues, I think we
would benefit on reducing the number of allocation/deallocations.

To improve that, replace the queue with a GPtrArray.  Incoming messages
are put in this array, and the index of the next message to be returned
is kept in a separate field.  When a message from that queue is
returned, return the message at that index.  Write NULL at that index
(the ownership of the message is transferred from the queue) and
increment the next message index.  The queue is considered empty when
the next message index is equal to the array length.  At this point, all
entries in the array are expected to be NULL, and more messages need to
be obtained from the upstream message iterator.  The array is resized
(g_ptr_array_set_size) to the size of the new message batch.  In
practice, the message count is always the same, so the size of the array
won't change, and g_ptr_array_set_size just does trivial work.

Performance results I get locally:

Before:

$ time ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy
./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy  3.77s user 0.02s system 99% cpu 3.791 total
$ time ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy
./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy  3.78s user 0.03s system 99% cpu 3.822 total

After:

$ time ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy
./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy  3.52s user 0.06s system 99% cpu 3.577 total
$ time ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy
./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy  3.52s user 0.04s system 99% cpu 3.563 total

This is with Babeltrace configured with:

    --enable-python-bindings --enable-python-plugins --disable-man-pages 'CFLAGS=-gdwarf-5 -g3 -O2' 'CXXFLAGS=-gdwarf-5 -g3 -O2' --prefix=/tmp/babeltrace 'CC=ccache clang' 'CXX=ccache clang++'

Change-Id: I0ce20994981be0479f0529880b4bdbca53a03fd6
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8107
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/plugins/utils/muxer/muxer.c
This page took 0.024878 seconds and 4 git commands to generate.