Re: How many tables is too many tables?

From: John A Meinel <john(at)arbash-meinel(dot)com>
To: "cydatamatt(at)gmail(dot)com" <cydatamatt(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: How many tables is too many tables?
Date: 2005-09-20 04:22:20
Message-ID: 432F8E7C.4080704@arbash-meinel.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

cydatamatt(at)gmail(dot)com wrote:
> I have a database of hundreds of millions of web links (between sites)
> in Postgres. For each link, we record the url, the referer, and the
> most recent date the link exists. I'm having some serious performance
> issues when it comes to writing new data into the database.
>
> One machine is simply not going to be able to scale with the quantities
> of links we hope to store information about and we want to move to some
> kind of cluster. Because of the quantities of data, it seems to make
> sense to go for a cluster setup such that in a 4 machine cluster, each
> machine has a quarter of the data (is this "Share nothing," or, "Share
> everything"?). To that end, we figured a good first step was to
> partition the data on one machine into multiple tables defining the
> logic which would find the appropriate table given a piece of data.
> Then, we assumed, adding the logic to find the appropriate machine and
> database in our cluster would only be an incremental upgrade.

In a database app, you generally don't win by going to a cluster,
because you are almost always bound by your I/O. Which means that a
single machine, just with more disks, is going to outperform a group of
machines.

As Tom mentioned, your schema is not very good. So lets discuss what a
better schema would be, and also how you might be able to get decent
performance with a cluster.

First, 200rows * 400,000 tables = 80M rows. Postgres can handle this in
a single table without too much difficulty. It all depends on the
selectivity of your indexes, etc.

I'm not sure how you are trying to normalize your data, but it sounds
like having a url table so that each entry can be a simple integer,
rather than the full path, considering that you are likely to have a
bunch of repeated information.

This makes your main table something like 2 integers, plus the
interesting stuff (from url, to url, data).

If you are finding you are running into I/O problems, you probably could
use this layout to move your indexes off onto their own spindles, and
maybe separate the main table from the url tables.

What is your hardware? What are you trying to do that you don't think
will scale?

If you were SELECT bound, then maybe a cluster would help you, because
you could off-load the SELECTs onto slave machines, and leave your
primary machine available for INSERTs and replication.

>
...

>
> At this point, the primary performance bottleneck is in adding
> additional data to the database. Our loader program (we load text
> files of link information) is currently getting about 40 rows a second,
> which is nowhere near the performance we need to be seeing. In theory,
> we want to be able to re-write our entire archive of data within on a
> 1-2 month cycle, so this is a very heavy write application (though
> we're also constantly generating reports from the data, so its not
> write only).

Are you VACUUMing enough? If you are rewriting all of the data, postgres
needs you to clean up afterwards. It is pessimistic, and leaves old rows
in their place.

>
> Is the total number of tables prohibitively affecting our write speed
> or is that an IO problem that can only be addressed by better drive
> partitioning (all data is on one drive, which I've already read is a
> problem)? Is this approach to data partitioning one which makes any
> sense for performance, or should we move to a more normal distribution
> of links across fewer tables which house more rows each?

If all data is on a single drive, you are nowhere near needing a cluster
to improve your database. What you need is a 14-drive RAID array. It's
probably cheaper than 4x powerful machines, and will provide you with
much better performance. And put all of your tables back into one.

John
=:->

>
> Thanks in advance for your advice.
>
> -matt
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
> choose an index scan if your joining column's datatypes do not
> match
>

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message John A Meinel 2005-09-20 04:24:59 Re: RAID Stripe size
Previous Message Tom Lane 2005-09-20 03:21:23 Re: How many tables is too many tables?