projects
/
freeside.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
optimize torrus-srvderive, RT#10574
[freeside.git]
/
FS
/
bin
/
freeside-torrus-srvderive
diff --git
a/FS/bin/freeside-torrus-srvderive
b/FS/bin/freeside-torrus-srvderive
index
f95029a
..
525d6ce
100644
(file)
--- a/
FS/bin/freeside-torrus-srvderive
+++ b/
FS/bin/freeside-torrus-srvderive
@@
-6,12
+6,13
@@
use Sys::SigAction qw( set_sig_handler );
use Date::Parse;
use Date::Format;
use FS::Daemon ':all'; #daemonize1 drop_root daemonize2 myexit logfile sig*
use Date::Parse;
use Date::Format;
use FS::Daemon ':all'; #daemonize1 drop_root daemonize2 myexit logfile sig*
-use FS::UID qw( adminsuidsetup dbh driver_name );
+use FS::UID qw( adminsuidsetup
forksuidsetup
dbh driver_name );
use FS::Record qw( qsearch str2time_sql str2time_sql_closing concat_sql );
use FS::torrus_srvderive;
our $DEBUG = 2;
use FS::Record qw( qsearch str2time_sql str2time_sql_closing concat_sql );
use FS::torrus_srvderive;
our $DEBUG = 2;
-our $max_kids = 3;
+our $max_kids = 6;
+our $search_timeout = 30*60; # 15*60 5*60; #$torrus_srvderive->last_srv_date ? 5*60 : 15*60);
our %kids;
my $user = shift or die &usage;
our %kids;
my $user = shift or die &usage;
@@
-62,17
+63,25
@@
my $orderlimit = "
LIMIT 50
";
LIMIT 50
";
+if ( driver_name eq 'mysql' ) {
+ dbh->do('SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED');
+ dbh->commit or die dbh->errstr;
+}
+
our $kids = 0;
our $kids = 0;
-MAIN: while (1) {
+#MAIN: while (1) {
+while (1) {
my $found = 0;
my $found = 0;
- SERVICEID: foreach my $torrus_srvderive ( qsearch('torrus_srvderive', {}) ) {
+ #SERVICEID: foreach my $torrus_srvderive ( qsearch('torrus_srvderive', {}) ) {
+ foreach my $torrus_srvderive ( qsearch('torrus_srvderive', {}) ) {
&reap_kids;
if ( $kids >= $max_kids ) {
&reap_kids;
if ( $kids >= $max_kids ) {
- sleep 10;
+ sleep 5;
+ myexit() if sigterm() || sigint();
redo;
}
redo;
}
@@
-95,7
+104,13
@@
MAIN: while (1) {
my $serviceid = $torrus_srvderive->serviceid;
my @serviceids = $torrus_srvderive->component_serviceids;
my $serviceid = $torrus_srvderive->serviceid;
my @serviceids = $torrus_srvderive->component_serviceids;
- next unless @serviceids; #don't try to search for empty virtual ports
+ exit unless @serviceids; #don't try to search for empty virtual ports
+
+ #nonlocking select statements; rows in this table never change
+ if ( driver_name eq 'mysql' ) {
+ dbh->do('SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED');
+ dbh->commit or die dbh->errstr;
+ }
my @in = ();
for my $dir ('_IN', '_OUT') {
my @in = ();
for my $dir ('_IN', '_OUT') {
@@
-118,7
+133,7
@@
MAIN: while (1) {
die $error if $error;
} else {
warn "no initial last_srv_date for $serviceid; skipping\n" if $DEBUG;
die $error if $error;
} else {
warn "no initial last_srv_date for $serviceid; skipping\n" if $DEBUG;
-
nex
t;
+
exi
t;
}
}
}
}
@@
-142,24
+157,26
@@
MAIN: while (1) {
eval {
my $h = set_sig_handler( 'ALRM', sub { die "_timeout\n"; } );
eval {
my $h = set_sig_handler( 'ALRM', sub { die "_timeout\n"; } );
- alarm(
10*60); #5*60); #$torrus_srvderive->last_srv_date ? 5*60 : 15*60
);
+ alarm(
$search_timeout
);
$sth->execute($serviceid, $serviceid) or die $sth->errstr;
alarm(0);
};
alarm(0);
if ( $@ && $@ eq "_timeout\n" ) {
$sth->execute($serviceid, $serviceid) or die $sth->errstr;
alarm(0);
};
alarm(0);
if ( $@ && $@ eq "_timeout\n" ) {
- warn "search timed out; reconnecting and restarting\n";
+ #warn "search timed out; reconnecting and restarting\n";
+ warn "search timed out\n";
dbh->clone()->do("KILL QUERY ". dbh->{"mysql_thread_id"})
if driver_name eq 'mysql';
dbh->rollback; #or die dbh->errstr;
dbh->clone()->do("KILL QUERY ". dbh->{"mysql_thread_id"})
if driver_name eq 'mysql';
dbh->rollback; #or die dbh->errstr;
- adminsuidsetup($user);
- next SERVICEID; #MAIN;
+ #adminsuidsetup($user);
+ #next SERVICEID; #MAIN;
+ exit;
} elsif ( $@ ) {
die $@;
}
} elsif ( $@ ) {
die $@;
}
- warn "search finished; checking results\n" if $DEBUG;
+ warn "search f
or $serviceid f
inished; checking results\n" if $DEBUG;
my $prev = 0;
while ( my $row = $sth->fetchrow_arrayref ) {
my $prev = 0;
while ( my $row = $sth->fetchrow_arrayref ) {
@@
-178,9
+195,12
@@
MAIN: while (1) {
my $sin = join(',', map dbh->quote("$_$dir"), @serviceids);
my $sin = join(',', map dbh->quote("$_$dir"), @serviceids);
+ my $srv_date = time2str('%Y-%m-%d', $cur);
+
my $sum = "
SELECT COALESCE(SUM(value),0) FROM srvexport AS other
WHERE other.serviceid IN ($sin)
my $sum = "
SELECT COALESCE(SUM(value),0) FROM srvexport AS other
WHERE other.serviceid IN ($sin)
+ AND other.srv_date = '$srv_date'
AND ABS( $cur - $other_date ) <= 60
";
AND ABS( $cur - $other_date ) <= 60
";
@@
-188,10
+208,10
@@
MAIN: while (1) {
INSERT INTO srvexport ( srv_date, srv_time, serviceid, value, intvl )
VALUES ( ?, ?, ?, ($sum), ? )
";
INSERT INTO srvexport ( srv_date, srv_time, serviceid, value, intvl )
VALUES ( ?, ?, ?, ($sum), ? )
";
- my @param = (
time2str('%Y-%m-%d', $cur), #srv_date
- time2str('%X', $cur),
#srv_time
- "$serviceid$dir",
- 300, #intvl ...
+ my @param = (
$srv_date,
+ time2str('%X', $cur), #srv_time
+ "$serviceid$dir",
#serviceid
+ 300,
#intvl ...
);
warn $isql. ' with param '. join(',',@param). "\n"
if $DEBUG > 2;
);
warn $isql. ' with param '. join(',',@param). "\n"
if $DEBUG > 2;
@@
-200,11
+220,13
@@
MAIN: while (1) {
#stupid mysql deadlocks all the time on insert, so we need to recover
unless ( $isth->execute(@param) ) {
#stupid mysql deadlocks all the time on insert, so we need to recover
unless ( $isth->execute(@param) ) {
- warn "Error inserting data for $serviceid$dir (restarting): ".
- $isth->errstr;
+ #warn "Error inserting data for $serviceid$dir (restarting): ".
+ # $isth->errstr;
+ warn "Error inserting data for $serviceid$dir: ". $isth->errstr;
dbh->rollback; #or die dbh->errstr;
dbh->rollback; #or die dbh->errstr;
- sleep 5;
- next SERVICEID; #MAIN;
+ #sleep 5;
+ #next SERVICEID; #MAIN;
+ exit;
}
}
}
}
@@
-230,7
+252,7
@@
MAIN: while (1) {
myexit() if sigterm() || sigint();
warn "restarting main loop\n" if $DEBUG > 1;
myexit() if sigterm() || sigint();
warn "restarting main loop\n" if $DEBUG > 1;
- sleep 60 unless $found;
+
#
sleep 60 unless $found;
}
sub _shouldrun {
}
sub _shouldrun {