fixes for worker process profiling

Signed-off-by: Ava Hahn <a.hahn@f5.com>
This commit is contained in:
Ava Hahn 2025-09-18 00:04:23 +00:00
parent 71990d3988
commit 78baa850a8
7 changed files with 46 additions and 25 deletions

View file

@ -59,6 +59,8 @@ services:
- linux/x86_64 - linux/x86_64
platform: linux/x86_64 platform: linux/x86_64
privileged: true privileged: true
cap_add:
- SYS_PTRACE
ports: ports:
- 8079:8080 - 8079:8080
networks: networks:

View file

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
N=$(nproc --all)
function log_request_to () { function log_request_to () {
return_code=$(curl -Sikl -o /dev/null -w "%{http_code}" $1 2>/dev/null) return_code=$(curl -Sikl -o /dev/null -w "%{http_code}" $1 2>/dev/null)
case ${return_code:0:1} in case ${return_code:0:1} in
@ -13,10 +15,6 @@ function log_request_to () {
esac esac
} }
function do_wrk_on () {
/wrk/wrk -t1 -c10 $1 &
}
function sigint_handler() { function sigint_handler() {
jobs -p | xargs kill -9 jobs -p | xargs kill -9
exit exit
@ -26,10 +24,13 @@ trap 'sigint_handler' INT
# TODO: make this a more elegant item # TODO: make this a more elegant item
# maybe a while loop with curl # maybe a while loop with curl
sleep 0.5 sleep 2
for iter in {0.999}; do echo "[+] client making request loop"
do_wrk_on "https://kaproxy:8080/$iter" for iter in {0..999}; do
((i=i%N)); ((i++==0)) && wait
echo "request to $iter"
log_request_to "https://kaproxy:8080/$iter" &
done done
wait $(jobs -p) wait $(jobs -p)

View file

@ -6,8 +6,8 @@ RUN echo "deb http://deb.debian.org/debian-debug/ bookworm-proposed-updates-debu
RUN apt update -y RUN apt update -y
RUN apt install libssl3 libssl3-dbgsym openssl openssl-dbgsym libssl-dev zlib1g-dev \ RUN apt install libssl3 libssl3-dbgsym openssl openssl-dbgsym libssl-dev zlib1g-dev \
libc6-dbg gcc make mk-configure valgrind libpcre2-dev libgcrypt20-dbgsym \ libc6-dbg gcc make mk-configure valgrind libpcre2-dev libgcrypt20-dbgsym strace \
--allow-downgrades -y procps --allow-downgrades -y
COPY nginx.conf / COPY nginx.conf /
WORKDIR / WORKDIR /
@ -24,8 +24,9 @@ WORKDIR /nginx
RUN auto/configure \ RUN auto/configure \
--with-debug \ --with-debug \
--with-http_ssl_module \ --with-http_ssl_module \
--with-file-aio \
--with-cc-opt="-gdwarf-4 -fno-omit-frame-pointer" --with-cc-opt="-gdwarf-4 -fno-omit-frame-pointer"
RUN make RUN make -j $(nproc --all)
RUN make install RUN make install
COPY run.sh / COPY run.sh /

View file

@ -1,6 +1,8 @@
#!/bin/bash #!/bin/bash
N=$(nproc --all)
for iter in {0..999}; do for iter in {0..999}; do
((i=i%N)); ((i++==0)) && wait
echo "minting cert $iter" echo "minting cert $iter"
openssl req -x509 \ openssl req -x509 \
-newkey rsa:4096 \ -newkey rsa:4096 \
@ -8,17 +10,19 @@ for iter in {0..999}; do
-out cert$iter.pem \ -out cert$iter.pem \
-sha256 -nodes \ -sha256 -nodes \
-days 3650 \ -days 3650 \
-quiet \ -subj "/C=XX/ST=StateName/L=CityName/O=CompanyName/OU=CompanySectionName/CN=kaproxy-$iter" &
-subj "/C=XX/ST=StateName/L=CityName/O=CompanyName/OU=CompanySectionName/CN=kaproxy-$iter" done
for iter in {0..999}; do
upstr=$(($iter%10)) upstr=$(($iter%10))
echo ' echo "
location /$iter { location /$iter {
proxy_ssl_certificate /cert$iter.pem; proxy_ssl_certificate /cert$iter.pem;
proxy_ssl_certificate_key /key$iter.pem; proxy_ssl_certificate_key /key$iter.pem;
proxy_pass http://kasvc-$upstr:8080; proxy_pass http://kasvc-$upstr:8080;
}' >> /nginx.conf }" >> /nginx.conf
done done
echo ' echo '
} }
} }

View file

@ -1,19 +1,26 @@
worker_processes 10; worker_processes 1;
error_log /dev/stdout notice; error_log /dev/stdout notice;
pid /tmp/pid; pid /tmp/pid;
# callgrind in worker processes must be able to do things
user root;
events { events {
worker_connections 10; worker_connections 10;
} }
http { http {
keepalive_timeout 300; keepalive_timeout 300;
aio on; # blocking io blocks tracing
directio 4m;
server { server {
listen 8080 ssl; listen 8080 ssl;
server_name www.example.com; server_name www.example.com;
ssl_certificate /www.example.com.crt; ssl_certificate /www.example.com.crt;
ssl_certificate_key /www.example.com.key; ssl_certificate_key /www.example.com.key;
#ssl_certificate_cache max=1000;
ssl_session_cache shared:SSL:10m;
access_log /tmp/access.log; access_log /tmp/access.log;
proxy_socket_keepalive on; proxy_socket_keepalive on;

View file

@ -3,10 +3,10 @@
function p_invoke() { function p_invoke() {
valgrind --tool=callgrind \ valgrind --tool=callgrind \
--trace-children=yes \ --trace-children=yes \
--callgrind-out-file=/tmp/callgrind.output \ --callgrind-out-file=/tmp/callgrind.out.%p \
--cache-sim=yes \ --cache-sim=yes \
--instr-atstart=no \
/nginx/objs/nginx \ /nginx/objs/nginx \
-p /tmp \
-e /tmp/error.log \ -e /tmp/error.log \
-c /nginx.conf \ -c /nginx.conf \
-g "daemon off;" -g "daemon off;"
@ -14,7 +14,6 @@ function p_invoke() {
function invoke() { function invoke() {
/nginx/objs/nginx \ /nginx/objs/nginx \
-p /tmp \
-e /tmp/error.log \ -e /tmp/error.log \
-c /nginx.conf \ -c /nginx.conf \
-g "daemon off;" \ -g "daemon off;" \
@ -35,7 +34,14 @@ function sigcont_handler() {
trap 'sigint_handler' INT trap 'sigint_handler' INT
trap 'sigcont_handler' CONT trap 'sigcont_handler' CONT
# enable tracing
echo 1 > /proc/sys/kernel/yama/ptrace_scope
p_invoke & p_invoke &
wait wait
echo "NGINX down. waiting until signalled..." echo "NGINX down. waiting to find it again"
sleep 0.5
wait $(cat /tmp/pid)
echo "NGINX is GONE. waiting until signalled"
sleep infinity sleep infinity

12
run.sh
View file

@ -36,24 +36,25 @@ go build keepalive-svc.go
mv keepalive-svc kasvc/ mv keepalive-svc kasvc/
rsync -avz $1 kaproxy/ rsync -avz $1 kaproxy/
sudo docker-compose up --build -d sudo docker-compose up --build -d
sudo docker exec -it $KAPROXY callgrind_control -i off sudo docker exec $KAPROXY callgrind_control -i off
sudo docker wait $KACLIENT sudo docker wait $KACLIENT
echo "[+] client finished, triggering reload" echo "[+] client finished, triggering reload"
sudo docker exec -it $KAPROXY callgrind_control -i on sudo docker exec $KAPROXY callgrind_control -i on
sudo docker kill -s CONT $KAPROXY sudo docker kill -s CONT $KAPROXY
echo "[+] wait five seconds for reload complete" echo "[+] wait five seconds for reload complete"
sleep 5 sleep 5
sudo docker exec -it $KAPROXY callgrind_control -i off
echo " > restarting client" echo " > restarting client"
sudo docker-compose restart kaclient sudo docker-compose restart kaclient
sudo docker wait $KACLIENT sudo docker wait $KACLIENT
echo "[+] client finished again. Killing NGINX and fetching profile data" echo "[+] client finished again. reloading NGINX and fetching profile data"
sudo docker kill -s CONT $KAPROXY
sudo docker exec $KAPROXY callgrind_control -i off
sudo docker kill -s INT $KAPROXY sudo docker kill -s INT $KAPROXY
sudo docker exec -it $KAPROXY callgrind_control -d sleep 10
echo "[+] building profiling report" echo "[+] building profiling report"
sudo docker exec $KAPROXY bash -c "find /tmp -iname \"callgrind.out*\"" | while read file sudo docker exec $KAPROXY bash -c "find /tmp -iname \"callgrind.out*\"" | while read file
@ -64,7 +65,6 @@ do
sudo chmod 777 $F sudo chmod 777 $F
echo "Output file: $F" >> $PROFILE_OUTPUT echo "Output file: $F" >> $PROFILE_OUTPUT
callgrind_annotate \ callgrind_annotate \
--include=kaproxy \
--auto=yes \ --auto=yes \
$F >> $PROFILE_OUTPUT $F >> $PROFILE_OUTPUT
echo "End of profile: $F\n\n\n" >> $PROFILE_OUTPUT echo "End of profile: $F\n\n\n" >> $PROFILE_OUTPUT