From patchwork Fri Oct 22 08:05:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Fitzenreiter X-Patchwork-Id: 4807 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4HbH3W3djTz3wd1 for ; Fri, 22 Oct 2021 08:05:59 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4HbH3V0W5Vz2cK; Fri, 22 Oct 2021 08:05:58 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4HbH3T5jT8z2yXQ; Fri, 22 Oct 2021 08:05:57 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4HbH3R6SHxz2xCY for ; Fri, 22 Oct 2021 08:05:55 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4HbH3R038pzlP; Fri, 22 Oct 2021 08:05:54 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1634889955; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=CazcGBpY0teVzXYgBqsxcMAjFD5wc9QU8F9w2mIm6J0=; b=1/lRlGhP3VtLl4MkVemfMombkITBh0nNQRPKbydbJMYJlyWOPg90PPjFxB/OI4CLh2QoAN 2mwra93q/RuDJpBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1634889955; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=CazcGBpY0teVzXYgBqsxcMAjFD5wc9QU8F9w2mIm6J0=; b=e2fT4uOdhLZ/I9cdjchkmz+5BSdCgvXcC4WCFVLQgIKfSjNjM4GpNOwjVLc4+vOAe19Mlf IbCYAXcQHjWLV6YiNkt8BFf284qlXFcgkryPjBalFbt7PtbWVtAwkoE5j9ThKZEKRiHmVr oSLAVQ8MVLhSZr+Xcda2GDQKaSYfgCYRGrGgzrn6sw/3u6bOwdsQDE8Hh3kGDQ9ke+UtJw pKHCmO2csmRRseS6d4qkmfgmWVWml8U82RjT9MC3OtVJC+RncUUszf/iEDeFDzYu8GghvN e+VAiQjjEwUm07t8gBJSoQ83kCQ+MpybEMMqPM6xgaRcM7P2CCwnOWvAeLgarA== From: Arne Fitzenreiter To: development@lists.ipfire.org Subject: [PATCH] speed.cgi: reduce system load by copying two general-functions. Date: Fri, 22 Oct 2021 10:05:32 +0200 Message-Id: <20211022080532.3195-1-arne_f@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Arne Fitzenreiter Errors-To: development-bounces@lists.ipfire.org Sender: "Development" include general-functions.pl load and initialize many subfunctions that are not needed by speed.cgi which was executed very ofthen. So this reduce the system load significant if webif was open in browser and ajax-speed display enabled. Signed-off-by: Arne Fitzenreiter Reviewed-by: Bernhard Bitsch --- config/cfgroot/general-functions.pl | 2 ++ html/cgi-bin/speed.cgi | 46 +++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/config/cfgroot/general-functions.pl b/config/cfgroot/general-functions.pl index f72d6588c..c10a04faa 100644 --- a/config/cfgroot/general-functions.pl +++ b/config/cfgroot/general-functions.pl @@ -53,6 +53,7 @@ sub system_background($) { } # Returns the output of a shell command +# if you change this also check speed.cgi that include a local copy for systemload reasons sub system_output($) { my @command = @_; my $pid; @@ -1227,6 +1228,7 @@ sub firewall_reload() { } # Function which will return the used interface for the red network zone (red0, ppp0, etc). +# if you change this also check speed.cgi that include a local copy for systemload reasons sub get_red_interface() { open(IFACE, "${General::swroot}/red/iface") or die "Could not open /var/ipfire/red/iface"; diff --git a/html/cgi-bin/speed.cgi b/html/cgi-bin/speed.cgi index b550fda52..651c3c0b3 100644 --- a/html/cgi-bin/speed.cgi +++ b/html/cgi-bin/speed.cgi @@ -19,7 +19,47 @@ # # ############################################################################### -require '/var/ipfire/general-functions.pl'; +############################################################################### +# functions copied from general-functions.pl for speed improvement because # +# loading and initializing the whole general-functions.pl every second create # +# high system load # +###########################################OA################################## +# +# Returns the output of a shell command +sub General__system_output($) { + my @command = @_; + my $pid; + my @output = (); + + unless ($pid = open(OUTPUT, "-|")) { + open(STDERR, ">&STDOUT"); + exec { ${command[0]} } @command; + die "Could not execute @command: $!"; + } + + waitpid($pid, 0); + + while () { + push(@output, $_); + } + + close(OUTPUT); + return @output; +} +# +# Function which will return the used interface for the red network zone (red0, ppp0, etc). +sub General__get_red_interface() { + + open(IFACE, "/var/ipfire/red/iface") or die "Could not open /var/ipfire/red/iface"; + + my $interface = ; + close(IFACE); + chomp $interface; + + return $interface; +} +# +############################################################################### my $data_last = $ENV{'QUERY_STRING'}; my $rxb_last = 0; @@ -38,8 +78,8 @@ foreach $field (@fields) { } } -my $interface = &General::get_red_interface(); -my @data_now = &General::system_output("ip", "-s", "link", "show", "$interface"); +my $interface = &General__get_red_interface(); +my @data_now = &General__system_output("ip", "-s", "link", "show", "$interface"); my $lastline; my $rxb_now = 0;