Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TeEwf-0000rH-V2 for pgsql-performance@arkaria.postgresql.org; Fri, 30 Nov 2012 00:59:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TeEwf-0004lC-FG for pgsql-performance@arkaria.postgresql.org; Fri, 30 Nov 2012 00:59:09 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TeEwd-0004jx-Pj for pgsql-performance@postgresql.org; Fri, 30 Nov 2012 00:59:08 +0000 Received: from mail-lb0-f174.google.com ([209.85.217.174]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TeEwb-0001ZU-OA for pgsql-performance@postgresql.org; Fri, 30 Nov 2012 00:59:07 +0000 Received: by mail-lb0-f174.google.com with SMTP id gi11so64354lbb.19 for ; Thu, 29 Nov 2012 16:59:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer :x-gm-message-state; bh=gH7rA5mInqetMAljzC7rTZvg5Bt+YVqg24YoHBHHEkg=; b=mft7kiTC8XXGGK0inCn/Y8yudVqD6x+4ZGiKQWAnQEIGWEovCt6PD6hh5Zvc1Ijwap Z6xMndYinclhdGJPrJEW2xx0xrHV8bosEr4scQXmzavtoyjxINqXdmsGaxJpvTSwbGz6 lnpYRFiAXtiCRokSVeCwkaYnvzGD7iAYaW9YxsModJoyKJQhHbCj28gslkUOgT/Cv+IV YM/CjNrgY2Y22W1WjHrcNn1IEbR5nqHZGHJRw1tPrkj602eAXumKnb3INk1/YMki/Kmt jJKPjyyEJUW0AVksvfOm55YYyNNC37MdGDgxDVk+5ro1S7WLosSckzIaGgqjk4/HsZEf fRQg== Received: by 10.152.106.4 with SMTP id gq4mr23063966lab.44.1354237143496; Thu, 29 Nov 2012 16:59:03 -0800 (PST) Received: from [192.168.0.14] (x1-6-84-1b-5e-20-07-92.k404.webspeed.dk. [80.167.117.15]) by mx.google.com with ESMTPS id oz12sm1276551lab.17.2012.11.29.16.59.01 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 29 Nov 2012 16:59:02 -0800 (PST) Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) Subject: Re: Optimize update query From: =?iso-8859-1?Q?Niels_Kristian_Schj=F8dt?= In-Reply-To: <50B641AD.3020204@optionshouse.com> Date: Fri, 30 Nov 2012 01:59:00 +0100 Cc: Willem Leenen , Content-Transfer-Encoding: quoted-printable Message-Id: References: <1C199C0D-13DF-47B3-944A-B0560C6D2E5A@autouncle.com> <50B61ABF.4070000@optionshouse.com>, <50B6223B.6000100@mejor.pl> <50B641AD.3020204@optionshouse.com> To: X-Mailer: Apple Mail (2.1499) X-Gm-Message-State: ALoCoQmcCHuru9exV3sAbvkih2zV2WGynZZdPS+2gI802LyyNHojRKJQzYPPiRyW1FzH1inhSnog X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Den 28/11/2012 kl. 17.54 skrev Shaun Thomas : > On 11/28/2012 10:19 AM, Niels Kristian Schj=F8dt wrote: >=20 >> https://rpm.newrelic.com/public/charts/h2dtedghfsv >=20 > Doesn't this answer your question? >=20 > That iowait is crushing your server into the ground. It's no surprise upd= ates are taking several seconds. That update you sent us *should* execute o= n the order of only a few milliseconds. >=20 > So I'll reiterate that you *must* move your pg_xlog location elsewhere. Y= ou've got row lookup bandwidth conflicting with writes. There are a couple = other changes you should probably make to your config: >=20 >> checkpoint_segments =3D 16 >=20 > This is not enough for the workload you describe. Every time the database= checkpoints, all of those changes in pg_xlog are applied to the backend da= ta files. You should set these values: >=20 > checkpoint_segments =3D 100 > checkpoint_timeout =3D 10m > checkpoint_completion_target =3D 0.9 >=20 > This will reduce your overall write workload, and make it less active. To= o many checkpoints massively reduce write throughput. With the settings you= have, it's probably checkpointing constantly while your load runs. Start w= ith this, but experiment with increasing checkpoint_segments further. >=20 > If you check your logs now, you probably see a ton of "checkpoint startin= g: xlog" in there. That's very bad. It should say "checkpoint starting: tim= e" meaning it's keeping up with your writes naturally. >=20 >> work_mem =3D 160MB >=20 > This is probably way too high. work_mem is used every sort operation in a= query. So each connection could have several of these allocated, thus star= ting your system of memory which will reduce that available for page cache.= Change it to 8mb, and increase it in small increments if necessary. >=20 >> So correct me if I'm wrong here: my theory is, that I have too many >> too slow update queries, that then often end up in a situation, where >> they "wait" for each other to finish, hence the sometimes VERY long >> execution times. >=20 > Sometimes this is the case, but for you, you're running into IO contentio= n, not lock contention. Your 3TB RAID-1 is simply insufficient for this wor= kload. >=20 > If you check your logs after making the changes I've suggested, take a lo= ok at your checkpoint sync times. That will tell you how long it took the k= ernel to physically commit those blocks to disk and get a confirmation back= from the controller. If those take longer than a second or two, you're pro= bably running into controller buffer overflows. You have a large amount of = RAM, so you should also make these two kernel changes to sysctl.conf: >=20 > vm.dirty_ratio =3D 10 > vm.dirty_writeback_ratio =3D 1 >=20 > Then run this: >=20 > sysctl -p >=20 > This will help prevent large IO write spikes caused when the kernel decid= es to write out dirty memory. That can make checkpoints take minutes to com= mit in some cases, which basically stops all write traffic to your database= entirely. >=20 > That should get you going, anyway. You still need more/better disks so yo= u can move your pg_xlog directory. With your write load, that will make a h= uge difference. >=20 > --=20 > Shaun Thomas > OptionsHouse | 141 W. Jackson Blvd. | Suite 500 | Chicago IL, 60604 > 312-444-8534 > sthomas@optionshouse.com >=20 > ______________________________________________ >=20 > See http://www.peak6.com/email_disclaimer/ for terms and conditions relat= ed to this email Okay, now I'm done the updating as described above. I did the postgres.conf= changes. I did the kernel changes, i added two SSD's in a software RAID1 w= here the pg_xlog is now located - unfortunately the the picture is still th= e same :-(=20 When the database is under "heavy" load, there is almost no improvement to = see in the performance compared to before the changes. A lot of both read a= nd writes takes more than a 1000 times as long as they usually do, under "l= ighter" overall load.=20 I added All the overview charts I can get hold on from new relic beneath. W= hat am I overlooking? There must be an obvious bottleneck? Where should I d= ive in? Database server CPU usage https://rpm.newrelic.com/public/charts/cEdIvvoQZCr Database server load average https://rpm.newrelic.com/public/charts/cMNdrYW51QJ Database server physical memory https://rpm.newrelic.com/public/charts/c3dZBntNpa1 Database server disk I/O utulization https://rpm.newrelic.com/public/charts/9YEVw6RekFG Database server network I/O (Mb/s) https://rpm.newrelic.com/public/charts/lKiZ0Szmwe7 Top 5 database operations by wall clock time https://rpm.newrelic.com/public/charts/dCt45YH12FK Database throughput https://rpm.newrelic.com/public/charts/bIbtQ1mDzMI Database response time https://rpm.newrelic.com/public/charts/fPcNL8WA6xx --=20 Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance