pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Gould <daveg@sonic.net>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #13750: Autovacuum slows down with large numbers of tables. More workers makes it slower.
Date: Fri, 30 Oct 2015 23:41:40 -0700
Message-ID: <20151030234140.282542c3@engels> (raw)
In-Reply-To: <15347.1446223903@sss.pgh.pa.us>
References: <20151030133252.3033.4249@wrigleys.postgresql.org>
	<20151030134646.GE5726@alvherre.pgsql>
	<20151030072704.1a4db344@engels>
	<20151030151711.GF5726@alvherre.pgsql>
	<13594.1446219627@sss.pgh.pa.us>
	<20151030154937.GH5726@alvherre.pgsql>
	<13962.1446220437@sss.pgh.pa.us>
	<20151030161150.GI5726@alvherre.pgsql>
	<15347.1446223903@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

On Fri, 30 Oct 2015 12:51:43 -0400
Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> > Tom Lane wrote:
> >> Good point ... shouldn't we have already checked the stats before ever
> >> deciding to try to claim the table?
> 
> > The second check is there to allow for some other worker (or manual
> > vacuum) having vacuumed it after we first checked, but which had
> > finished before we check the array of current jobs.
> 
> I wonder whether that check costs more than it saves.

It does indeed. It drives the stats collector wild. And of course if there
are lots of tables and indexes the stats temp file gets very large so that
it can take a long time (seconds) to rewrite it. This happens for each
worker for each table that is a candidate for vacuuming.

Since it would not be convenient to provide a copy of the clients 8TB
database I have made a standalone reproduction. The attached files:

 build_test_instance.sh - create a test instance
 datagen.py             - used by above to populate it with lots of tables
 logbyv.awk             - count auto analyze actions in postgres log
 trace.sh               - strace the stats collector and autovacuum workers
 tracereport.sh         - list top 50 calls in strace output

The test process is to run the build_test_instance script to create an
instance with one database with a large number of tiny tables. During the
setup autovacuuming is off. Then make a tarball of the instance for reuse.
For each test case, untar the instance, set the number of workers and start
it. After a short time autovacuum will start workers to analyze the new
tables. Expect to see the stats collector doing lots of writing.

You may want to use tmpfs or a ramdisk for the data dir for building the
test instance. The configuration is sized for reasonable desktop, 8 to 16GB
of memory and an SSD.

-dg

-- 
David Gould              510 282 0869         daveg@sonic.net
If simplicity worked, the world would be overrun with insects.

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

  build_test_instance.sh (application/x-shellscript, 4.2K) download

datagen.py (text/x-python, 2.8K) download #!/usr/bin/env python import sys from math import log10 def arg(n, default=None, func=lambda x: x): return func( len(sys.argv) > n and sys.argv[n] or default ) if len(sys.argv) < 2: print """ Usage: %s ntabs nrows npadcols padlen scalearg batchsize """ % sys.argv[0] sys.exit(1) ntabs = arg(1, '40000', int) # 40k tables nrows = arg(2, '1000', int) # 1k rows npadcols = arg(3, '5', int) # 5 padding columns padlen = arg(4, '20', int) # of 20 bytes each scalearg = arg(5, '10', int) # rowcount scaling, here 10 per decade, ie every 10th # table gets 10x rows, every 100th gets 100x rows batchsize = arg(6, '1', int) # tables per transaction tabname = 't_%%0%dd' % (int(log10(ntabs)+1),) # for generating padding columns padname = 'pad_%%0%dd' % (len(str(npadcols)),) paddecl = ', '.join(( padname % (n,) + ' text' for n in range(npadcols) )) padtarget = ', '.join(( padname % (n,) for n in range(npadcols) )) padvalues = ', '.join(( "'" + chr(ord('0') + n)*padlen + "'" for n in range(npadcols) )) def pglog(msg): return """select '%s' as "Notice";""" % (msg,) def setup(): return """ drop schema if exists avac cascade; create schema avac; create table if not exists avac.t_list ( tabno int primary key, relname text, nrows int ); """ def make_table(tabno, nrows): return """ -- %(table)s insert into avac.t_list(tabno, relname, nrows) values(%(tabno)d, '%(table)s', %(nrows)d); create table avac.%(table)s ( rno int, tabno int default %(tabno)d, revision int default 0, ctime timestamptz default now(), mtime timestamptz default now(), %(paddecl)s ); insert into avac.%(table)s (rno, %(padtarget)s) select rno, %(padvalues)s from generate_series(1, %(nrows)d) rowgen(rno); alter table avac.%(table)s add constraint %(table)s_pkey primary key(rno); -- create unique index %(table)s_rev_idx on -- avac.%(table)s (revision, rno); """ % dict(tabno = tabno, nrows = nrows, table = tabname % (tabno,), paddecl = paddecl, padtarget = padtarget, padvalues = padvalues) def scale(n, factor=1): """Scale by factor for each trailing 0 in n up to 3""" return factor**(n and max(p for p in range(0,4) if n % 10**p == 0 and n >= 10**p) or 0) print pglog('DATAGEN setup start.') print setup() print pglog('DATAGEN setting up: %d tables, %d rows with %d cols of %d chars padding.' % (ntabs, nrows, npadcols, padlen)) txn = False for tno in range(ntabs): if txn and tno % batchsize == 0: print 'commit;' txn = False if not txn: print 'begin;' txn = True n = nrows * scale(tno, scalearg) print make_table(tno, n) if txn: print 'commit;' print pglog('DATAGEN setup done.')
logbyv.awk (application/x-awk, 1.0K) download trace.sh (application/x-shellscript, 531B) download tracereport.sh (application/x-shellscript, 212B) download

view thread (38+ messages)  latest in thread

Message-ID: <20151030234140.282542c3@engels>
Permalink:  ../20151030234140.282542c3@engels/
Also on:    postgresql.org/message-id/20151030234140.282542c3@engels

 · 

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-bugs@postgresql.org
  Cc: daveg@sonic.net, tgl@sss.pgh.pa.us, alvherre@2ndquadrant.com
  Subject: Re: BUG #13750: Autovacuum slows down with large numbers of tables. More workers makes it slower.
  In-Reply-To: <20151030234140.282542c3@engels>
  References: <20151030133252.3033.4249@wrigleys.postgresql.org> <20151030134646.GE5726@alvherre.pgsql> <20151030072704.1a4db344@engels> <20151030151711.GF5726@alvherre.pgsql> <13594.1446219627@sss.pgh.pa.us> <20151030154937.GH5726@alvherre.pgsql> <13962.1446220437@sss.pgh.pa.us> <20151030161150.GI5726@alvherre.pgsql> <15347.1446223903@sss.pgh.pa.us> <20151030234140.282542c3@engels>

* 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