Ottimizzazione thread conntrack
This commit is contained in:
@@ -24,6 +24,12 @@ my $dbmysql = DBI->connect("DBI:mysql:;host=$DBhost", $DBuser, $DBpass) or die (
|
||||
$sts = $dbmysql->prepare("use $DBname");
|
||||
$sts->execute ();
|
||||
|
||||
$query = "SELECT valore FROM conf WHERE variabile = 'lthread'";
|
||||
$sts = $dbmysql->prepare($query);
|
||||
$sts->execute ();
|
||||
$ref = $sts->fetchrow_hashref;
|
||||
our $limit_thread = $$ref{'valore'};
|
||||
|
||||
$query = "SELECT ip FROM proxy_pool GROUP BY ip";
|
||||
$sts = $dbmysql->prepare($query);
|
||||
$sts->execute ();
|
||||
@@ -66,10 +72,13 @@ while ( $ref = $sts->fetchrow_hashref ) {
|
||||
|
||||
while (1) {
|
||||
sleep 30;
|
||||
while (my ($variabile, $puntatore) = each %proc) {
|
||||
|
||||
foreach my $variabile (keys %proc) {
|
||||
$puntatore = $proc{$variabile};
|
||||
if(!$puntatore or !$puntatore->is_running ) {
|
||||
print "Rilevato termine processo $variabile\n" if ($verbose);
|
||||
#$puntatore->detach();
|
||||
delete $proc{$variabile};
|
||||
#$puntatore->join();
|
||||
|
||||
if ($variabile eq "database") {
|
||||
$proc{'database'} = threads->create(\&database);
|
||||
@@ -81,7 +90,7 @@ while (1) {
|
||||
my $id = $$ref{'id'};
|
||||
my $ip = $$ref{'ip'};
|
||||
my $port = $$ref{'port'};
|
||||
$proc{$$variabile} = threads->create(\&conntrack, $id, $ip, $port);
|
||||
$proc{$variabile} = threads->create(\&conntrack, $id, $ip, $port);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,6 +102,8 @@ sub conntrack {
|
||||
my $proxy_IP = shift;
|
||||
my $proxy_PORT = shift;
|
||||
|
||||
my $conta = 0;
|
||||
|
||||
print "Attivato agente $sess_id su $proxy_IP:$proxy_PORT\n" if ($verbose);
|
||||
|
||||
open CT, "/usr/sbin/conntrack -E -eNEW,DESTROY -otimestamp,id -p tcp -d $proxy_IP --dport $proxy_PORT |" or die "non va\n";
|
||||
@@ -137,7 +148,8 @@ sub conntrack {
|
||||
my $remote_RECEIVE = $6;
|
||||
my $thread_ID = $7;
|
||||
|
||||
printf ("$sess_id - IP: %-15s - ID: %-12s - Inviati: %10d - Ricevuti: %10d\n", $remote_IP, $thread_ID, $remote_SEND, $remote_RECEIVE) if ($verbose);
|
||||
$conta++;
|
||||
printf ("$conta/$limit_thread - $sess_id - IP: %-15s - ID: %-12s - Inviati: %10d - Ricevuti: %10d\n", $remote_IP, $thread_ID, $remote_SEND, $remote_RECEIVE) if ($verbose);
|
||||
|
||||
my $query = " UPDATE
|
||||
proxy_dati
|
||||
@@ -161,6 +173,7 @@ sub conntrack {
|
||||
$sem2->up();
|
||||
print "Invio query UPDATE\n" if ($verbose > 1);
|
||||
}
|
||||
return if ($conta >= $limit_thread);
|
||||
}
|
||||
close CT;
|
||||
}
|
||||
@@ -185,7 +198,6 @@ sub database {
|
||||
$sts->finish;
|
||||
$sem1->up();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub DBConn {
|
||||
|
||||
Reference in New Issue
Block a user