[perf] fix url download performance

This commit is contained in:
Timothy Stack 2022-06-03 21:41:21 -07:00
parent dfaeee7f44
commit f01564fea4
3 changed files with 15 additions and 21 deletions

View File

@ -78,7 +78,7 @@ public:
safe::WriteAccess<safe_message_list, std::unique_lock>
writable_msgs(this->mp_messages);
if (writable_msgs->empty()) {
if (writable_msgs->empty() && rel_time.count() > 0) {
this->sp_cond.template wait_for(writable_msgs.lock, rel_time);
}

View File

@ -46,13 +46,13 @@ struct curl_request_eq {
bool operator()(const std::shared_ptr<curl_request>& cr) const
{
return this->cre_name == cr->get_name();
};
}
bool operator()(
const std::pair<mstime_t, std::shared_ptr<curl_request>>& pair) const
{
return this->cre_name == pair.second->get_name();
};
}
const std::string& cre_name;
};
@ -127,6 +127,9 @@ curl_looper::perform_io()
auto timeout = this->compute_timeout(current_time);
int running_handles;
if (timeout < 1ms) {
timeout = 5ms;
}
curl_multi_wait(this->cl_curl_multi, nullptr, 0, timeout.count(), nullptr);
curl_multi_perform(this->cl_curl_multi, &running_handles);
}
@ -211,10 +214,8 @@ curl_looper::check_for_finished_requests()
curl_multi_remove_handle(this->cl_curl_multi, easy);
if (iter != this->cl_handle_to_request.end()) {
auto cr = iter->second;
long delay_ms;
this->cl_handle_to_request.erase(iter);
delay_ms = cr->complete(msg->data.result);
auto delay_ms = cr->complete(msg->data.result);
if (delay_ms < 0) {
log_info("%s:curl_request %p finished, deleting...",
cr->get_name().c_str(),
@ -243,7 +244,7 @@ curl_looper::compute_timeout(mstime_t current_time) const
std::chrono::milliseconds retval = 1s;
if (!this->cl_handle_to_request.empty()) {
retval = 1ms;
retval = 0ms;
} else if (!this->cl_poll_queue.empty()) {
retval
= std::max(1ms,
@ -251,8 +252,6 @@ curl_looper::compute_timeout(mstime_t current_time) const
this->cl_poll_queue.front().first - current_time));
}
ensure(retval.count() > 0);
return retval;
}

View File

@ -41,7 +41,7 @@
class url_loader : public curl_request {
public:
url_loader(const std::string& url) : curl_request(url), ul_resume_offset(0)
url_loader(const std::string& url) : curl_request(url)
{
auto tmp_res = lnav::filesystem::open_temp_file(
ghc::filesystem::temp_directory_path() / "lnav.url.XXXXXX");
@ -57,17 +57,12 @@ public:
curl_easy_setopt(this->cr_handle, CURLOPT_WRITEFUNCTION, write_cb);
curl_easy_setopt(this->cr_handle, CURLOPT_WRITEDATA, this);
curl_easy_setopt(this->cr_handle, CURLOPT_FILETIME, 1);
};
curl_easy_setopt(this->cr_handle, CURLOPT_BUFFERSIZE, 128L * 1024L);
}
int get_fd() const
{
return this->ul_fd.get();
};
int get_fd() const { return this->ul_fd.get(); }
auto_fd copy_fd() const
{
return this->ul_fd.dup();
};
auto_fd copy_fd() const { return this->ul_fd.dup(); }
long complete(CURLcode result)
{
@ -125,7 +120,7 @@ public:
}
return -1;
};
}
private:
static const long FOLLOW_IF_MODIFIED_SINCE = 60 * 60;
@ -148,7 +143,7 @@ private:
}
auto_fd ul_fd;
off_t ul_resume_offset;
off_t ul_resume_offset{0};
};
#endif