From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox Backup Server development discussion
<pbs-devel@lists.proxmox.com>,
Dominik Csapak <d.csapak@proxmox.com>
Subject: Re: [pbs-devel] [RFC PATCH proxmox-backup 1/3] proxmox-rest-server: OutputFormatter: add new format_data_streaming method
Date: Wed, 23 Feb 2022 10:20:48 +0100 [thread overview]
Message-ID: <add8503f-8830-d051-2685-2c12bd4b6811@proxmox.com> (raw)
In-Reply-To: <20220217094041.1632033-6-d.csapak@proxmox.com>
On 17.02.22 10:40, Dominik Csapak wrote:
> +fn start_data_streaming(value: Value, data: Box<dyn SerializableReturn + Send>) -> tokio::sync::mpsc::Receiver<Result<Vec<u8>, Error>> {
> + let (writer, reader) = tokio::sync::mpsc::channel(1);
> +
> + std::thread::spawn(move || {
just for the record, spawning a separate thread for every request isn't
a good idea performance wise, while the cost is lower than say forking,
its still non-negligible and a few users having the gui open will result
in hundreds of threads spawned per minute; iow. system threads should
only be spawned for long running (as in about as long running as the
whole programs lifetime) tasks, not for one-time short lived tasks with
a definite purpose.
Using tokio's spawn_blocking is nicer for such things as while it also
may spawn a thread it lets the thread idle for 10s after last task
completion to wait for new work before exiting again. Having a PBS web
interface dashboard open shows ~8 XHR request in 10s, so it's quite
likely that we'd only ever have one such thread reused constantly per
user-session, reducing costs a lot.
btw., as it was questioned during off-list talk: block_in_place makes
only then sense for blocking code if spawn_blocking cannot be used due
to missing Send + 'static guarantees on the fn to call.
> + let output = proxmox_async::blocking::SenderWriter::from_sender(writer);
> + let mut output = std::io::BufWriter::new(output);
> + let mut serializer = serde_json::Serializer::new(&mut output);
> + let _ = data.sender_serialize(&mut serializer, value);
> + });
> +
> + reader
> +}
> +
next prev parent reply other threads:[~2022-02-23 9:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-17 9:40 [pbs-devel] [RFC PATCH proxmox/proxmox-backup] implement streaming serialization for api calls Dominik Csapak
2022-02-17 9:40 ` [pbs-devel] [RFC PATCH proxmox 1/4] proxmox-async: add SenderWriter helper Dominik Csapak
2022-02-17 9:40 ` [pbs-devel] [RFC PATCH proxmox 2/4] promxox-router: add SerializableReturn Trait Dominik Csapak
2022-02-18 8:21 ` Dietmar Maurer
2022-02-17 9:40 ` [pbs-devel] [RFC PATCH proxmox 3/4] proxmox-router: add new ApiHandler variants for streaming serialization Dominik Csapak
2022-02-17 9:40 ` [pbs-devel] [RFC PATCH proxmox 4/4] proxmox-api-macro: add 'streaming' option Dominik Csapak
2022-02-17 9:40 ` [pbs-devel] [RFC PATCH proxmox-backup 1/3] proxmox-rest-server: OutputFormatter: add new format_data_streaming method Dominik Csapak
2022-02-23 9:20 ` Thomas Lamprecht [this message]
2022-02-17 9:40 ` [pbs-devel] [RFC PATCH proxmox-backup 2/3] adapt to the new ApiHandler variants Dominik Csapak
2022-02-17 9:40 ` [pbs-devel] [RFC PATCH proxmox-backup 3/3] api: admin/datastore: enable streaming for some api calls Dominik Csapak
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=add8503f-8830-d051-2685-2c12bd4b6811@proxmox.com \
--to=t.lamprecht@proxmox.com \
--cc=d.csapak@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