X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id DB4AD5282E for ; Tue, 28 Jun 2005 18:55:53 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 63963-01 for ; Tue, 28 Jun 2005 21:55:43 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.198]) by svr1.postgresql.org (Postfix) with ESMTP id 22F5F52825 for ; Tue, 28 Jun 2005 18:55:42 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id i21so693554wra for ; Tue, 28 Jun 2005 14:55:44 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=MvLZkIXz26X+EMjiK59NTDVFmUiX1zPAfx+m/tWREI1BUxBwXwUBPT7kBrhbQymA2nMZf69kZeVGIyza6w2+VCRVsfoNBqNOrh4HPk8d6r45sW3Je4yougIkKci6w8qvo2mjsytz6ObGG4FYtW2PhyMDE8Lq238+hTptETnIq5M= Received: by 10.54.40.48 with SMTP id n48mr2150wrn; Tue, 28 Jun 2005 14:55:44 -0700 (PDT) Received: by 10.54.22.15 with HTTP; Tue, 28 Jun 2005 14:55:44 -0700 (PDT) Message-ID: Date: Tue, 28 Jun 2005 16:55:44 -0500 From: Matthew Nuzum Reply-To: newz@bearfruit.org To: Billy extyeightysix Subject: Re: optimized counting of web statistics Cc: Postgresql Performance list In-Reply-To: <22455e7050628133978b17cd4@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <6EE64EF3AB31D5448D0007DD34EEB3415C2C08@Herge.rcsinc.local> <22455e7050628133978b17cd4@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.079 tagged_above=0 required=5 tests=AWL, RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200506/580 X-Sequence-Number: 13217 On 6/28/05, Billy extyeightysix wrote: > Hola folks, >=20 > I have a web statistics Pg database (user agent, urls, referrer, etc) > that is part of an online web survey system. All of the data derived > from analyzing web server logs is stored in one large table with each > record representing an analyzed webserver log entry. >=20 > Currently all reports are generated when the logs are being analyzed > and before the data ever goes into the large table I mention above. > Well, the time has come to build an interface that will allow a user > to make ad-hoc queries against the stats and that is why I am emailing > the performance list. Load your data into a big table, then pre-process into additional tables that have data better organized for running your reports. For example, you may want a table that shows a sum of all hits for each site, for each hour of the day. You may want an additional table that shows the sum of all page views, or maybe sessions for each site for each hour of the day. So, if you manage a single site, each day you will add 24 new records to the sum table. You may want the following fields: site (string) atime (timestamptz) hour_of_day (int) day_of_week (int) total_hits (int8) A record may look like this: site | atime | hour_of_day | day_of_week | total_hits 'www.yoursite.com' '2005-06-28 16:00:00 -0400' 18 2 350 Index all of the fields except total_hits (unless you want a report that shows all hours where hits were greater than x or less than x). Doing: select sum(total_hits) as total_hits from summary_table where atime between now() and (now() - '7 days'::interval); should be pretty fast. You can also normalize your data such as referrers, user agents, etc and create similar tables to the above. In case you haven't guessed, I've already done this very thing. I do my batch processing daily using a python script I've written. I found that trying to do it with pl/pgsql took more than 24 hours to process 24 hours worth of logs. I then used C# and in memory hash tables to drop the time to 2 hours, but I couldn't get mono installed on some of my older servers. Python proved the fastest and I can process 24 hours worth of logs in about 15 minutes. Common reports run in < 1 sec and custom reports run in < 15 seconds (usually). --=20 Matthew Nuzum www.bearfruit.org