Skip to content

Commit

Permalink
perf(mtda): reduce costly calls to storage.status
Browse files Browse the repository at this point in the history
The calls to storage.status are costly, as every time the device state
is queried via an external process invocation. This patch optimizes this
by:

1. not calling the GUI callback on each chunk, but only every 0.5s
2. in case we are in writing mode, the storage is always connected to
   the host. Hence, do not query the status from the driver.

These improvements speedup writes and seeks by 2-3 times.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
  • Loading branch information
fmoessbauer authored and chombourger committed Sep 17, 2023
1 parent 3bc8a19 commit fbc4caf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion mtda/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,15 @@ def _storage_write(self, image, imgname,
data = image.read(self._agent.blksz)
dataread = len(data)
totalread = 0
lastreport = time.time()
while totalread < inputsize:
totalread += dataread

# Report progress via callback
if callback is not None:
if callback is not None and time.time() - lastreport > 0.5:
_, _, written = self._impl.storage_status(self._session)
callback(imgname, totalread, inputsize, written, imagesize)
lastreport = time.time()

# Write block to shared storage device
bytes_wanted = self._impl.storage_write(data, self._session)
Expand Down
4 changes: 3 additions & 1 deletion mtda/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,9 @@ def storage_status(self, session=None):
self.mtda.debug(4, "storage_status(): no shared storage device")
result = CONSTS.STORAGE.UNKNOWN, False, 0
else:
status = self.storage_controller.status()
# avoid costly query of storage state when we know it anyways
status = CONSTS.STORAGE.ON_HOST \
if self._writer.writing else self.storage_controller.status()
result = status, self._writer.writing, self._writer.written

self.mtda.debug(3, "main.storage_status(): %s" % str(result))
Expand Down

0 comments on commit fbc4caf

Please sign in to comment.