From: Steinar H. Gunderson Date: Fri, 10 Nov 2023 21:51:00 +0000 (+0100) Subject: Add connection keepalive. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=f02c94f4a47fba37add8b245622a5f81969cb8b4;p=skvidarsync Add connection keepalive. --- diff --git a/bin/sync.pl b/bin/sync.pl index 703b0c5..0aea7b9 100644 --- a/bin/sync.pl +++ b/bin/sync.pl @@ -488,14 +488,12 @@ sub db_connect { } sub run { - my $dbh = shift; + my ($dbh, $ua) = @_; my $total_start = [Time::HiRes::gettimeofday]; @log = (); skv_log("Siste sync startet: " . POSIX::ctime(time)); - # Initialize the handles we need for communication. - my $ua = LWP::UserAgent->new('SKVidarLang/1.0'); my $token = get_oauth_bearer_token($dbh, $ua); # Find the newest message, what it is linked to, and what was the one before it (for group diffing). @@ -805,10 +803,12 @@ sub run { printf "Tok %.0f ms.\n", 1e3 * $elapsed; } +# Initialize the handles we need for communication. my $dbh = db_connect() or die; +my $ua = LWP::UserAgent->new(agent => 'SKVidarLang/1.0', keep_alive => 50); if ($#ARGV >= 0 && $ARGV[0] eq '--daemon') { # Start with a single, forced run. - run($dbh); + run($dbh, $ua); while (1) { while (!defined($dbh)) { @@ -828,7 +828,7 @@ if ($#ARGV >= 0 && $ARGV[0] eq '--daemon') { if (scalar @ready > 0) { eval { $dbh->{AutoCommit} = 1; - run($dbh); + run($dbh, $ua); $dbh->commit; }; if ($@) { @@ -840,9 +840,9 @@ if ($#ARGV >= 0 && $ARGV[0] eq '--daemon') { } elsif ($#ARGV >= 0 && $ARGV[0] eq '--benchmark') { for my $i (0..9) { $dbh->{AutoCommit} = 1; - run($dbh); + run($dbh, $ua); $dbh->commit; } } else { - run($dbh); + run($dbh, $ua); }