From: Stefan Reiter <s.reiter@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 7/9] file-restore-daemon: limit concurrent download calls
Date: Thu, 6 May 2021 17:26:22 +0200 [thread overview]
Message-ID: <20210506152624.12605-8-s.reiter@proxmox.com> (raw)
In-Reply-To: <20210506152624.12605-1-s.reiter@proxmox.com>
While the issue with vsock packets starving kernel memory is mostly
worked around by the '64k -> 4k buffer' patch in
'proxmox-backup-restore-image', let's be safe and also limit the number
of concurrent transfers. 8 downloads per VM seems like a fair value.
Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
---
Mostly optional, included since I had it lying around for a while, but only now
is it useable, since it suffered from the same tokio issue as the watchdog
inhibit.
src/bin/proxmox_restore_daemon/api.rs | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/bin/proxmox_restore_daemon/api.rs b/src/bin/proxmox_restore_daemon/api.rs
index c578b2c0..f2732e64 100644
--- a/src/bin/proxmox_restore_daemon/api.rs
+++ b/src/bin/proxmox_restore_daemon/api.rs
@@ -6,6 +6,7 @@ use hyper::{header, Body, Response, StatusCode};
use log::error;
use pathpatterns::{MatchEntry, MatchPattern, MatchType, Pattern};
use serde_json::Value;
+use tokio::sync::Semaphore;
use std::ffi::OsStr;
use std::fs;
@@ -41,6 +42,8 @@ pub const ROUTER: Router = Router::new()
.get(&list_subdirs_api_method!(SUBDIRS))
.subdirs(SUBDIRS);
+static DOWNLOAD_SEM: Semaphore = Semaphore::const_new(8);
+
fn read_uptime() -> Result<f32, Error> {
let uptime = fs::read_to_string("/proc/uptime")?;
// unwrap the Option, if /proc/uptime is empty we have bigger problems
@@ -252,6 +255,12 @@ fn extract(
let _inhibitor = watchdog_inhibit();
async move {
let _inhibitor = _inhibitor;
+
+ let _permit = match DOWNLOAD_SEM.try_acquire() {
+ Ok(permit) => permit,
+ Err(_) => bail!("maximum concurrent download limit reached, please wait for another restore to finish before attempting a new one"),
+ };
+
let path = tools::required_string_param(¶m, "path")?;
let mut path = base64::decode(path)?;
if let Some(b'/') = path.last() {
@@ -286,6 +295,7 @@ fn extract(
if pxar {
tokio::spawn(async move {
let _inhibitor = _inhibitor;
+ let _permit = _permit;
let result = async move {
// pxar always expects a directory as it's root, so to accommodate files as
// well we encode the parent dir with a filter only matching the target instead
@@ -344,6 +354,7 @@ fn extract(
} else {
tokio::spawn(async move {
let _inhibitor = _inhibitor;
+ let _permit = _permit;
let result = async move {
if vm_path.is_dir() {
zip_directory(&mut writer, &vm_path).await?;
--
2.20.1
next prev parent reply other threads:[~2021-05-06 15:27 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-06 15:26 [pbs-devel] [PATCH 0/9] Debug mode and smaller fixes for single file restore Stefan Reiter
2021-05-06 15:26 ` [pbs-devel] [PATCH proxmox-backup 1/9] file-restore: add debug mode with serial access Stefan Reiter
2021-05-06 15:26 ` [pbs-devel] [PATCH proxmox-backup 2/9] file-restore: try to kill VM when stale Stefan Reiter
2021-05-07 7:04 ` [pbs-devel] applied: " Thomas Lamprecht
2021-05-06 15:26 ` [pbs-devel] [PATCH proxmox-backup 3/9] file-restore: add more RAM for VMs with many drives or debug Stefan Reiter
2021-05-07 7:04 ` [pbs-devel] applied: " Thomas Lamprecht
2021-05-06 15:26 ` [pbs-devel] [PATCH proxmox-backup 4/9] file-restore: support more drives Stefan Reiter
2021-05-07 7:04 ` [pbs-devel] applied: " Thomas Lamprecht
2021-05-06 15:26 ` [pbs-devel] [PATCH proxmox-backup 5/9] file-restore-daemon: work around tokio DuplexStream bug Stefan Reiter
2021-05-06 18:12 ` Thomas Lamprecht
2021-05-07 7:26 ` Fabian Grünbichler
2021-05-06 15:26 ` [pbs-devel] [PATCH proxmox-backup 6/9] file-restore-daemon: watchdog: add inhibit for long downloads Stefan Reiter
2021-05-06 15:26 ` Stefan Reiter [this message]
2021-05-06 15:26 ` [pbs-devel] [PATCH proxmox-backup-restore-image 8/9] kernel: power off on panic Stefan Reiter
2021-05-06 15:26 ` [pbs-devel] [PATCH proxmox-backup-restore-image 9/9] add debug initramfs as seperate package Stefan Reiter
2021-05-06 18:07 ` Thomas Lamprecht
2021-05-25 11:50 ` [pbs-devel] applied-series: [PATCH 0/9] Debug mode and smaller fixes for single file restore Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210506152624.12605-8-s.reiter@proxmox.com \
--to=s.reiter@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox