Skip to content

Commit

Permalink
Update progress bar only once every 100ms
Browse files Browse the repository at this point in the history
To help with CPU usage

Signed-off-by: Eric Curtin <[email protected]>
Signed-off-by: Charro Gruver <[email protected]>
  • Loading branch information
ericcurtin authored and cgruver committed Feb 7, 2025
1 parent 317f308 commit 97a18c7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ramalama/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def configure_arguments(parser):
dest="ngl",
type=int,
default=config.get("ngl", -1),
help="Number of layers to offload to the gpu, if available"
help="Number of layers to offload to the gpu, if available",
)
parser.add_argument(
"--keep-groups",
Expand Down
3 changes: 2 additions & 1 deletion ramalama/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
MNT_FILE = f"{MNT_DIR}/model.file"
HTTP_RANGE_NOT_SATISFIABLE = 416

DEFAULT_IMAGE="quay.io/ramalama/ramalama"
DEFAULT_IMAGE = "quay.io/ramalama/ramalama"


def container_manager():
engine = os.getenv("RAMALAMA_CONTAINER_ENGINE")
Expand Down
9 changes: 8 additions & 1 deletion ramalama/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,21 @@ def perform_download(self, file, progress):
self.total_to_download += self.file_size
self.now_downloaded = 0
self.start_time = time.time()
accumulated_size = 0
last_update_time = time.time()
while True:
data = self.response.read(1024)
if not data:
break

size = file.write(data)
if progress:
self.update_progress(size)
accumulated_size += size
if time.time() - last_update_time >= 0.1:
self.now_downloaded += accumulated_size
self.update_progress(self.now_downloaded, self.total_to_download)
accumulated_size = 0
last_update_time = time.time()

def human_readable_time(self, seconds):
hrs = int(seconds) // 3600
Expand Down

0 comments on commit 97a18c7

Please sign in to comment.