]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
speed.cgi: reduce system load by copying two general-functions.
authorArne Fitzenreiter <arne_f@ipfire.org>
Fri, 22 Oct 2021 08:05:32 +0000 (10:05 +0200)
committerArne Fitzenreiter <arne_f@ipfire.org>
Fri, 22 Oct 2021 16:15:34 +0000 (16:15 +0000)
include general-functions.pl load and initialize many subfunctions that are not
needed by speed.cgi which was executed very often.
So this reduce the system load significant if webif was open in browser
and ajax-speed display enabled.

Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
Reviewed-by: Bernhard Bitsch <bbitsch@ipfire.org>
Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
config/cfgroot/general-functions.pl
html/cgi-bin/speed.cgi

index f72d6588cf1358f4bc7fc0ab7402efed9420b187..c10a04faa20ed9db73d7828bf6eff7468f00aba7 100644 (file)
@@ -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";
index b550fda521b2619ba9865c54ef8fbd3ee47bfe52..651c3c0b3137b66b9e285266c2a6abf3b5cb3753 100644 (file)
 #                                                                             #
 ###############################################################################
 
-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 (<OUTPUT>) {
+            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 = <IFACE>;
+     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;