Re: [SQL] inserts/updates problem under stressing !

Поиск
Список
Период
Сортировка
От Oleg Bartunov
Тема Re: [SQL] inserts/updates problem under stressing !
Дата
Msg-id Pine.GSO.3.96.SK.990726103105.10884D-100000@ra
обсуждение исходный текст
Ответ на Re: [SQL] inserts/updates problem under stressing !  (Vadim Mikheev <vadim@krs.ru>)
Список pgsql-hackers
On Mon, 26 Jul 1999, Vadim Mikheev wrote:

> Date: Mon, 26 Jul 1999 14:26:06 +0800
> From: Vadim Mikheev <vadim@krs.ru>
> To: Oleg Bartunov <oleg@sai.msu.su>
> Cc: Tom Lane <tgl@sss.pgh.pa.us>, pgsql-hackers@postgreSQL.org,
>     pgsql-sql@postgreSQL.org
> Subject: Re: [SQL] inserts/updates problem under stressing !
> 
> Oleg Bartunov wrote:
> > 
> > >
> > > SELECT FOR UPDATE will not help: if there was no record for
> > > particular key then nothing will be locked and two records with
> > > the same key will be inserted.
> > >
> > > Oleg, use LOCK IN SHARE ROW EXCLUSIVE MODE.
> > 
> > Thanks Vadim. Just tried this, but still I see a difference between
> > count hits (accumulated) from db and access_log. In my test these numbers are:
> > 95 and 109. So I lost 14 hits ! And no errors !
> > In my handler I have now:
> > 
> > my $sth = $dbh->do("LOCK TABLE hits IN SHARE ROW EXCLUSIVE MODE");
> > my $sth = $dbh->do("SELECT acc_hits($1)") || die $dbh->errstr;
> > 
> > am I right ?
> 
> You should run LOCK and SELECT inside BEGIN/END (i.e. in
> the same transaction), do you?

Good question.

I use perl DBI interface to work with postgres and I supposed it does
transaction automatically.  Will check it.
Aha, got the problem. Now everything works !!!
Tnanks again,
    Oleg

So, here is a working handler to *accumulate* hit statistics.

package Apache::HitsDBI;
use Apache::Constants qw(:common);

use strict;
# preloaded in startup.pl
#use DBI ();

sub handler {   my $orig = shift;   my $url  = $orig->uri;   if ( $orig->args() =~ /msg_id=(\d+)/ ) {     my $dbh =
DBI->connect("dbi:Pg:dbname=discovery")|| die DBI->errstr;     $dbh->{AutoCommit} = 0;     my $sth = $dbh->do("LOCK
TABLEhits IN SHARE ROW EXCLUSIVE MODE") || die $dbh->errstr;     my $sth = $dbh->do("SELECT acc_hits($1)") || die
$dbh->errstr;    my $rc  = $dbh->commit     || die $dbh->errstr;   }   return OK;
 
}

1;
__END__


Oleg
> 
> Vadim
> 

_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Oleg Bartunov
Дата:
Сообщение: Re: [HACKERS] Re: [SQL] inserts/updates problem understressing !
Следующее
От: Adriaan Joubert
Дата:
Сообщение: Re: [HACKERS] Re: [SQL] inserts/updates problem under stressing !