Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbeb1f0c

Browse files
authored
common : throttle download progress output to reduce IO flush (#17427)
This change limits progress updates to approximately every 0.1% of thefile size to minimize stdio overhead.Also fixes compiler warnings regarding __func__ in lambdas.Signed-off-by: Adrien Gallouët <angt@huggingface.co>
1 parentdef5404 commitbeb1f0c

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

‎common/download.cpp‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,36 +517,43 @@ static bool common_pull_file(httplib::Client & cli,
517517
headers.emplace("Range","bytes=" +std::to_string(existing_size) +"-");
518518
}
519519

520-
std::atomic<size_t> downloaded{existing_size};
520+
constchar * func = __func__;// avoid __func__ inside a lambda
521+
size_t downloaded = existing_size;
522+
size_t progress_step =0;
521523

522524
auto res = cli.Get(resolve_path, headers,
523525
[&](const httplib::Response &response) {
524526
if (existing_size >0 && response.status !=206) {
525-
LOG_WRN("%s: server did not respond with 206 Partial Content for a resume request. Status: %d\n",__func__, response.status);
527+
LOG_WRN("%s: server did not respond with 206 Partial Content for a resume request. Status: %d\n",func, response.status);
526528
returnfalse;
527529
}
528530
if (existing_size ==0 && response.status !=200) {
529-
LOG_WRN("%s: download received non-successful status code: %d\n",__func__, response.status);
531+
LOG_WRN("%s: download received non-successful status code: %d\n",func, response.status);
530532
returnfalse;
531533
}
532534
if (total_size ==0 && response.has_header("Content-Length")) {
533535
try {
534536
size_t content_length =std::stoull(response.get_header_value("Content-Length"));
535537
total_size = existing_size + content_length;
536538
}catch (const std::exception &e) {
537-
LOG_WRN("%s: invalid Content-Length header: %s\n",__func__, e.what());
539+
LOG_WRN("%s: invalid Content-Length header: %s\n",func, e.what());
538540
}
539541
}
540542
returntrue;
541543
},
542544
[&](constchar *data,size_t len) {
543545
ofs.write(data, len);
544546
if (!ofs) {
545-
LOG_ERR("%s: error writing to file: %s\n",__func__, path_tmp.c_str());
547+
LOG_ERR("%s: error writing to file: %s\n",func, path_tmp.c_str());
546548
returnfalse;
547549
}
548550
downloaded += len;
549-
print_progress(downloaded, total_size);
551+
progress_step += len;
552+
553+
if (progress_step >= total_size /1000 || downloaded == total_size) {
554+
print_progress(downloaded, total_size);
555+
progress_step =0;
556+
}
550557
returntrue;
551558
},
552559
nullptr

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp