all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH common] run_command: improve performance for outfunc and long lines
@ 2020-07-28 15:03 Dominik Csapak
  0 siblings, 0 replies; only message in thread
From: Dominik Csapak @ 2020-07-28 15:03 UTC (permalink / raw)
  To: pve-devel

to call outfunc with each line, we search for a newline and call
outfunc/logfunc with everything before that

since we do a select/read (with 4096 size) in a loop, this means
that if we have very long lines, we search for a newline in an
ever growing buffer (for which we know does not contain a newline)

so instead, only search the new data for newlines

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
this reduces a 'pvesm list' for a pbs storage with ~5000 snapshots from 66s to 4.7s

todo: the backspace/\r handling is weird, maybe we should improve that?
for now its compatible

 src/PVE/Tools.pm | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index 4399b2f..350cb27 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -496,12 +496,14 @@ sub run_command {
 		if ($h eq $reader) {
 		    if ($outfunc || $logfunc) {
 			eval {
-			    $outlog .= $buf;
-			    while ($outlog =~ s/^([^\010\r\n]*)(\r|\n|(\010)+|\r\n)//s) {
-				my $line = $1;
+			    while ($buf =~ m/^([^\010\r\n]*)(?:\r|\n|(?:\010)+|\r\n)(.*)$/) {
+				my $line = $outlog . $1;
+				$outlog = "";
+				$buf = $2;
 				&$outfunc($line) if $outfunc;
 				&$logfunc($line) if $logfunc;
 			    }
+			    $outlog .= $buf;
 			};
 			my $err = $@;
 			if ($err) {
-- 
2.20.1





^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-07-28 15:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-28 15:03 [pve-devel] [PATCH common] run_command: improve performance for outfunc and long lines Dominik Csapak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal