copr-be-dev: experiment with optimal pipe reader
This commit is contained in:
parent
b3f80c5558
commit
53a79c70d1
1 changed files with 33 additions and 20 deletions
|
@ -1,33 +1,46 @@
|
||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
# Something like 'cat' fucntionality, but automatically re-open the output file
|
# logrotate-friendly-log-pipe <output-log-file>
|
||||||
# upon the SIGHUP signal. We used to use cronolog instead in Copr, but (a) we
|
# https://gist.github.com/praiskup/18f290b549a990c966b64e500797e714
|
||||||
# haven't used it for rotating at all, and (b) that tool doesn't react on
|
|
||||||
# SIGHUP. Long story in: https://pagure.io/copr/copr/issue/2001
|
|
||||||
#
|
#
|
||||||
# One may object this is slow, I tested this locally with throughput about
|
# Pipe logs to the <output-log-file>. Reopen the file upon the SIGHUP signal.
|
||||||
# 12k lines per second:
|
|
||||||
#
|
#
|
||||||
# $ for i in `seq 1000000`; do printf "%79d\n" "0" >> /tmp/test-file; done
|
# This is especially useful when a multi-process Lighttpd server is used (with
|
||||||
# $ time cat /tmp/test-file | /tmp/logger /tmp/output-measured
|
# the 'server.max-workers = N' option), and use of Cronolog is not desirable:
|
||||||
# real 1m24.354s
|
# https://redmine.lighttpd.net/projects/1/wiki/Server_max-workerDetails
|
||||||
# user 0m39.895s
|
|
||||||
# sys 1m6.402s
|
|
||||||
#
|
#
|
||||||
# But we would get much higher throughput if implemented in C.
|
# Background story: https://pagure.io/copr/copr/issue/2001
|
||||||
|
|
||||||
logfile=$1
|
logfile=$1
|
||||||
cmd="$0 $*"
|
|
||||||
|
|
||||||
handler()
|
if test -z "$logfile"; then
|
||||||
|
echo "usage: $0 <logfile>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cmd="$0 $*"
|
||||||
|
shell_pid=$$
|
||||||
|
|
||||||
|
quit()
|
||||||
{
|
{
|
||||||
exec 1>> "$logfile"
|
set -x ; kill "$cat_pid" ; wait ; exit 0
|
||||||
echo "=== start: $cmd ==="
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trap handler SIGHUP
|
trap ':' HUP
|
||||||
handler
|
trap 'quit' INT
|
||||||
|
trap 'quit' TERM
|
||||||
|
trap 'quit' USR1
|
||||||
|
|
||||||
while IFS= read -r line; do
|
# Wait for 'cat' to quit. SIGHUP interrupt keeps cycling.
|
||||||
echo "$line"
|
while :; do
|
||||||
|
exec >> "$logfile"
|
||||||
|
echo "=== start: $cmd ==="
|
||||||
|
cat < /proc/$shell_pid/fd/0 &
|
||||||
|
cat_pid=$!
|
||||||
|
wait
|
||||||
|
status=$?
|
||||||
|
# ksh gives us 257 here
|
||||||
|
test $status -ne 129 && test $status -ne 257 && break
|
||||||
|
kill "$cat_pid"
|
||||||
|
wait
|
||||||
done
|
done
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue