bitbake-worker: Improve bytearray truncation performance
PATCH 1/2 bitbake-worker: Improve bytearray truncation performance
If there are large amounts of data being transferred to the cooker from the worker, recreating the bytearray becomes inefficient as it happens for every pipesize block of data, defaulting to 64kb.
Instead we can use the deletion API for bytearrays to make this more efficient and avoid the object recreation.
We noticed this with a strace ptest image taking days to complete the build after having 6GB of data in the testimage log. Whilst there are other issues there, making this code more efficient doesn't hurt.
--- bin/bitbake-worker | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
bin/bitbake-worker +1 -1
@@ -105,7 +105,7 @@ def worker_flush(worker_queue): if not worker_queue.empty(): worker_queue_int.extend(worker_queue.get()) written = os.write(worker_pipe, worker_queue_int) - worker_queue_int = worker_queue_int[written:] + del worker_queue_int[0:written] except (IOError, OSError) as e: if e.errno != errno.EAGAIN and e.errno != errno.EPIPE: raise
PATCH 2/2 bitbake-worker/cooker: Increase default pipe size
The default pipe size is 64kb on builds, which can be inefficient for larger log files from workers. Increase the pipe size to 512kb since build systems have decent amounts of memory and this is a more efficient way of batching the data.
Tweak the default read sizes to match the pipe size for efficiency.
--- bin/bitbake-worker | 4 +++- lib/bb/runqueue.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-)
bin/bitbake-worker +3 -1
@@ -21,6 +21,7 @@ import traceback import queue import shlex import subprocess +import fcntl from multiprocessing import Lock from threading import Thread
@@ -56,6 +57,7 @@ logger = logging.getLogger("BitBake") worker_pipe = sys.stdout.fileno() bb.utils.nonblockingfd(worker_pipe) +fcntl.fcntl(worker_pipe, fcntl.F_SETPIPE_SZ, 512 * 1024) # Need to guard against multiprocessing being used in child processes # and multiple processes trying to write to the parent at the same time worker_pipe_lock = None
@@ -357,7 +359,7 @@ class runQueueWorkerPipe(): def read(self): start = len(self.queue) try: - self.queue.extend(self.input.read(102400) or b"") + self.queue.extend(self.input.read(512*1024) or b"") except (OSError, IOError) as e: if e.errno != errno.EAGAIN: raise
lib/bb/runqueue.py +1 -1
@@ -3318,7 +3318,7 @@ class runQueuePipe(): start = len(self.queue) try: - self.queue.extend(self.input.read(102400) or b"") + self.queue.extend(self.input.read(512 * 1024) or b"") except (OSError, IOError) as e: if e.errno != errno.EAGAIN: raise