pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: Mindaugas Riauba <mind@bi.lt>
To: pgsql-performance@postgresql.org
Subject: Re: Need advice about triggers
Date: Tue, 9 Sep 2003 15:40:51 +0100
Message-ID: <200309091540.51382.dev@archonet.com> (raw)
In-Reply-To: <00dc01c376d6$f9f99c30$f20214ac@bite.lt>
References: <00be01c376cf$91510620$f20214ac@bite.lt>
	<200309091414.23458.dev@archonet.com>
	<00dc01c376d6$f9f99c30$f20214ac@bite.lt>

On Tuesday 09 September 2003 14:33, Mindaugas Riauba wrote:
> > Well, try it without the trigger. If performance improves markedly, it
> might
> > be worth rewriting in C.
>
>   Nope. Execution time is practically the same without trigger.

OK - no point in rewriting it then.

> > If not, you're probably saturating the disk I/O - using iostat/vmstat
> > will
>
> let
>
> > you see what's happening. If it is your disks, you might see if moving
> > the WAL onto a separate drive would help, or check the archives for
> > plenty of discussion about raid setups.
>
>   Bottleneck in this case is CPU. postmaster process uses almost 100% of
> CPU.

>   Disk I/O should not be a problem in this case. vmstat shows ~300kb/s
> write activity.

Hmm - I must admit I wasn't expecting that. Closest I can get on my test 
machine here: AMD 400MHz / 256MB / IDE disk / other stuff running is about 20 
secs.

I've attached the perl script I used - what sort of timings does it give you?

-- 
  Richard Huxton
  Archonet Ltd

Attachments:

big_update_test.pl (text/x-perl, 1.3K) download #!/usr/bin/perl -w use DBI; use Benchmark; # How many clients, how many inserts each my $num_upd = 10000; my $num_rows = 1000; my $dbname = "richardh"; my $dbh = DBI->connect("dbi:Pg:dbname=$dbname", "", ""); # Comment out create_table after the first run. create_table($dbh, $num_rows); my $t0 = new Benchmark; run_updates($dbh, $num_rows, $num_upd); my $t1 = new Benchmark; $td = timediff($t1, $t0); print "the code took:",timestr($td),"\n"; $dbh->disconnect; exit; sub create_table { my $dbh = shift; my $num_rows = shift; my $sth = $dbh->prepare("CREATE TABLE foo (a int4, v varchar(100), t timestamp with time zone, PRIMARY KEY (a))"); $sth->execute or die $dbh->errstr; $sth = $dbh->prepare("INSERT INTO foo (a,v,t) VALUES (?,?,now())"); my $vartext = 'AAAAAAAA'; for (my $i=0; $i<$num_rows; $i++) { $sth->execute($i,$vartext) or die $dbh->errstr; $vartext++; } } sub run_updates { my $dbh = shift; my $num_rows = shift; my $num_upd = shift; my $batchsize = 500; my $sth = $dbh->prepare("UPDATE foo SET t=now() WHERE a=?"); for (my $i=0; $i<$num_upd; $i++) { if ($i % $batchsize==0) { $dbh->begin_work; } if ($i % $batchsize==499) { $dbh->commit; print "update $i\n"; $dbh->do("VACUUM foo;"); } $sth->execute() or die $dbh->errstr; } }

view thread (10+ messages)  latest in thread

Message-ID: <200309091540.51382.dev@archonet.com>
Permalink:  ../200309091540.51382.dev@archonet.com/
Also on:    postgresql.org/message-id/200309091540.51382.dev@archonet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: dev@archonet.com, mind@bi.lt
  Subject: Re: Need advice about triggers
  In-Reply-To: <200309091540.51382.dev@archonet.com>
  References: <00be01c376cf$91510620$f20214ac@bite.lt> <200309091414.23458.dev@archonet.com> <00dc01c376d6$f9f99c30$f20214ac@bite.lt> <200309091540.51382.dev@archonet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox