Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id C57789FB324 for ; Fri, 3 Nov 2006 08:55:56 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 34665-06 for ; Fri, 3 Nov 2006 12:55:51 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id B9F8F9FA27F for ; Fri, 3 Nov 2006 08:55:51 -0400 (AST) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id E0CBC75698; Fri, 3 Nov 2006 12:50:29 +0000 (GMT) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 1283815EAB; Fri, 3 Nov 2006 12:50:29 +0000 (GMT) Message-ID: <454B3B75.6@archonet.com> Date: Fri, 03 Nov 2006 12:52:05 +0000 From: Richard Huxton User-Agent: Thunderbird 1.5.0.7 (X11/20060918) MIME-Version: 1.0 To: creimer@brturbo.com.br Cc: pgsql-performance@postgresql.org Subject: Re: Context switch storm References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/40 X-Sequence-Number: 21810 creimer@brturbo.com.br wrote: > Hi, > > We've migrated one of our servers from pg 7.4 to 8.1 and from times > to times (4 hours) the server start doing a lot of context switching > and all transactions become very slow. > > The average context switching for this server as vmstat shows is 1 > but when the problem occurs it goes to 250000. > > CPU and memory usage are ok. > > What is producing this context switching storms? > > It is a box with 16GB RAM and 4 XEON processors running RedHat > Enterprise Linux AS. It's memory bandwidth issues on the older Xeons. If you search the archives you'll see a lot of discussion of this. I'd have thought 8.1 would be better than 7.4 though. You'll tend to see it when you have multiple clients and most queries can use RAM rather than disk I/O. My understanding of what happens is that PG requests data from RAM - it's not in cache so the process gets suspended to wait. The next process does the same, with the same result. You end up with lots of processes all fighting over what data is in the cache and no-one gets much work done. > Should I disable Hyperthreading? I seem to remember that helps, but do check the mailing list archives for discussion on this. If you can keep your numbers of clients down below the critical level, you should find the overall workload is fine. The problem is of course that as the context-switching increases, each query takes longer which means more clients connect, which increases the context-swtching, which means... HTH -- Richard Huxton Archonet Ltd