Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 0C0061337B43 for ; Sat, 30 Apr 2011 22:06:09 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 13480-08 for ; Sun, 1 May 2011 01:05:51 +0000 (UTC) X-Greylist: delayed 00:05:16.030136 by SQLgrey-1.7.6 Received: from mail-pw0-f46.google.com (mail-pw0-f46.google.com [209.85.160.46]) by mail.postgresql.org (Postfix) with ESMTP id 9C37E133798E for ; Sat, 30 Apr 2011 22:05:50 -0300 (ADT) Received: by pwi15 with SMTP id 15so2251203pwi.19 for ; Sat, 30 Apr 2011 18:05:50 -0700 (PDT) MIME-Version: 1.0 Received: by 10.68.22.1 with SMTP id z1mr7199990pbe.36.1304211634099; Sat, 30 Apr 2011 18:00:34 -0700 (PDT) Received: by 10.68.48.68 with HTTP; Sat, 30 Apr 2011 18:00:34 -0700 (PDT) X-Originating-IP: [66.215.95.51] In-Reply-To: References: <4DBC004C020000250003D099@gw.wicourts.gov> <4881277622113933088@unknownmsgid> <4DBC0D7C020000250003D09E@gw.wicourts.gov> <76A45DA2-2AC3-4F58-933B-D4DCD61B8DCE@gmail.com> Date: Sat, 30 Apr 2011 18:00:34 -0700 Message-ID: Subject: Re: stored proc and inserting hundreds of thousands of rows From: Samuel Gendler To: Joel Reymont Cc: "pgsql-performance@postgresql.org" Content-Type: multipart/alternative; boundary=bcaec521635929963104a22c6ff6 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-10 required=5 tests=BAYES_00=-1.9, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 201104/447 X-Sequence-Number: 43509 --bcaec521635929963104a22c6ff6 Content-Type: text/plain; charset=ISO-8859-1 On Sat, Apr 30, 2011 at 5:12 PM, Jeff Janes wrote: > > > gist indices are designed to make this type of thing fast, by using > techniques to rule out most of those comparisons without actually > performing them. I don't know enough about the > guts of either your distance function or the gist indexes to know if > you can do it this way, but if you can it would certainly be the way > to go. > It is definitely a good idea to consider a gist index for eliminating most of a large dataset, if applicable. Do a little reading on the topic and, hopefully, it's applicability (or not) will become apparent. However, as someone who has built a number of ad servers over the years, for several of the larger ad networks, the first thing I'd do is separate your ad serving from real-time interaction with your database, no matter what the underlying technology. If you ad serving is dependent on your database, it means that hiccups in the database will have an impact on ad serving, which is rarely tolerable. And god forbid you should need to take the db down for a period of maintenance. The reliability and performance required of most ad servers is often greater than what should reasonably be expected of a relational database, particularly if there are other processes accessing the database, as is the case with your system. The first rule of ad serving is that no outage of backend systems should ever be able to prevent or impact front end ad serving. Some kind of in-memory cache of doc/ad mappings which the ad server interacts with will serve you in good stead and will be much easier to scale horizontally than most relational db architectures lend themselves to. If you have an ever increasing set of documents and ads, you'll inevitably wind up 'sharding' your dataset across multiple db hosts in order to maintain performance - which creates a number of maintenance complexities. Easier to maintain a single database and do analytics over a single data source, but insulate it from the real-time performance requirements of your ad serving. Even something as simple as a process that pushes the most recent doc/ad mappings into a memcache instance could be sufficient - and you can scale your memcache across as many hosts as is necessary to deliver the lookup latencies that you require no matter how large the dataset. Similarly, if you are updating the database from the ad server with each ad served in order to record an impression or click, you'll be far better off logging those and then processing the logs in bulk on a periodic basis. If subsequent impressions are dependent upon what has already been served historically, then use your memcache instance (or whatever structure you eventually choose to utilize) to handle those lookups. This gives you the convenience and flexibility of a relational system with SQL for access, but without the constraints of the capabilities of a single host limiting real-time performance of the system as a whole. --bcaec521635929963104a22c6ff6 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Sat, Apr 30, 2011 at 5:12 PM, Jeff Ja= nes <jeff.jane= s@gmail.com> wrote:


gist indices are designed to make this type of thing fast, by using techniques to rule out most of those comparisons without actually
performing them. =A0I don't know enough about the
guts of either your distance function or the gist indexes to know if
you can do it this way, but if you can it would certainly be the way
to go.

It is definitely a good idea to = consider a gist index for eliminating most of a large dataset, if applicabl= e. =A0Do a little reading on the topic and, hopefully, it's applicabili= ty (or not) will become apparent.

However, as someone who has built a number of ad server= s over the years, for several of the larger ad networks, the first thing I&= #39;d do is separate your ad serving from real-time interaction with your d= atabase, no matter what the underlying technology. =A0If you ad serving is = dependent on your database, it means that hiccups in the database will have= an impact on ad serving, which is rarely tolerable. =A0And god forbid you = should need to take the db down for a period of maintenance. The reliabilit= y and performance required of most ad servers is often greater than what sh= ould reasonably be expected of a relational database, particularly if there= are other processes accessing the database, as is the case with your syste= m. The first rule of ad serving is that no outage of backend systems should= ever be able to prevent or impact front end ad serving. Some kind of in-me= mory cache of doc/ad mappings which the ad server interacts with will serve= you in good stead and will be much easier to scale horizontally than most = relational db architectures lend themselves to. =A0If you have an ever incr= easing set of documents and ads, you'll inevitably wind up 'shardin= g' your dataset across multiple db hosts in order to maintain performan= ce - which creates a number of maintenance complexities. Easier to maintain= a single database and do analytics over a single data source, but insulate= it from the real-time performance requirements of your ad serving. Even so= mething as simple as a process that pushes the most recent doc/ad mappings = into a memcache instance could be sufficient - and you can scale your memca= che across as many hosts as is necessary to deliver the lookup latencies th= at you require no matter how large the dataset. =A0Similarly, if you are up= dating the database from the ad server with each ad served in order to reco= rd an impression or click, you'll be far better off logging those and t= hen processing the logs in bulk on a periodic basis. =A0If subsequent impre= ssions are dependent upon what has already been served historically, then u= se your memcache instance (or whatever structure you eventually choose to u= tilize) to handle those lookups. =A0This gives you the convenience and flex= ibility of a relational system with SQL for access, but without the constra= ints of the capabilities of a single host limiting real-time performance of= the system as a whole.


--bcaec521635929963104a22c6ff6--