Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e21pB-0006cU-7m for pgsql-general@arkaria.postgresql.org; Tue, 10 Oct 2017 21:12:25 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e21pA-00055a-Fi for pgsql-general@arkaria.postgresql.org; Tue, 10 Oct 2017 21:12:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e21p9-000545-9K for pgsql-general@postgresql.org; Tue, 10 Oct 2017 21:12:23 +0000 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1e21p5-0005TP-AF for pgsql-general@postgresql.org; Tue, 10 Oct 2017 21:12:22 +0000 Received: by mail-wm0-x22b.google.com with SMTP id t69so642753wmt.2 for ; Tue, 10 Oct 2017 14:12:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=k+Fv2Ki0cPBtJ/Sz+ok8uiH/WfF/BYKbmh7wl3oDC9k=; b=QjV0+aiov6x1oJ6T0il/d80DyQVMnPefIgr/ebq/8xlhZdh8bDCZY31USjjSpGobnJ Sdy8NfCy29MgH4g2bNHjUbmH0zJzH0bwlm7FaOhdQTMOsGC0qlO9yD6dFtH1C2keA4zL VDTEFj+QISyx4Qf3PVWZJkp/C/JOPc0ibGMa6tPOfXsrSTgzElaEGgMEtIUwJFAPtyvP WQ4hqreDwZsYAb9fNgIlZLSy9dl91yLpZcdFynBfZCrn/Ea8G47scaiShf08R+ju9rGJ UhZZC5bTHeGPfcxx9nYObKzcFqbYx2/C/J8TOwxE26G6NykxGf1csxPPnwCsb0hQqgpd E1dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=k+Fv2Ki0cPBtJ/Sz+ok8uiH/WfF/BYKbmh7wl3oDC9k=; b=UG48RrYM7y/sFiAnHKNTik7pKX04hlQvzFTdmM/tNLl/j18o8eppre9OQ/Q1umV9FW wd/+itlY3xEhv1tVHZRTyzFkB0YKH6pIfnZa0ChRjJGQou+ccBh0MwArbj3h5EoM/rb9 3Sv5tPJTIwWhnqyjsTTBIyRj7F1IARpNa/RDqRF6UU7uwCZ8aLbuLGffw9BLsoFQS6r/ fhEtLpRqBGaYY5RKVPNWjFm5Dt4WVaGLsJZV/yxgN2+EX+F62LQbJXj43jXF6Z9vtshk h0GrIRBWDkJ7bBecSHYhW0NldHat1U7rKWO+MztzRt8vLw3bDwwFlGQ21bvvKMyuBIB6 Dcxw== X-Gm-Message-State: AMCzsaVKacQcJ25fTm0hWTBaYvUZJlw6by5wztME5xOka55VUmk+DqER bAM6c1dlsx9kbzRkEQokiqrByu8uEG6151GJ7Cr0qZ12L9gTEsG65f33YIkXNh4qGJaVt5bCDqd J5Ryko5vKMtmKrY0zf5SY0NgWtvBkxHl2KXCbgTaeRNkXBateY4iMYxUiXqhTwoLeWjReZ0jPkp WOtqGIt+oW X-Google-Smtp-Source: AOwi7QAXO8OR0Gohsoz1zgPL0Jo4pOGrpDHtYyoXmbWVfnx5sbyBVGXNvMvZz47UD6co/S8CjpCjoA== X-Received: by 10.28.1.199 with SMTP id 190mr1688369wmb.51.1507669937882; Tue, 10 Oct 2017 14:12:17 -0700 (PDT) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id a34sm26145563wra.64.2017.10.10.14.12.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Oct 2017 14:12:17 -0700 (PDT) Subject: Re: core system is getting unresponsive because over 300 cpu load To: pinker , pgsql-general@postgresql.org References: <1507668007464-0.post@n3.nabble.com> From: Tomas Vondra Message-ID: <4da39f8e-39b9-b4af-d879-72a44dde5fbd@2ndquadrant.com> Date: Tue, 10 Oct 2017 23:12:13 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <1507668007464-0.post@n3.nabble.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org On 10/10/2017 10:40 PM, pinker wrote: > Hi to all! > > We've got problem with a very serious repetitive incident on our core > system. Namely, cpu load spikes to 300-400 and the whole db becomes What is "CPU load"? Perhaps you mean "load average"? Also, what are the basic system parameters (number of cores, RAM), it's difficult to help without knowing that. > unresponsive. From db point of view nothing special is happening, memory > looks fine, disks io's are ok and the only problem is huge cpu load. Kernel > parameters that are increasing with load are always the same: > > * page tables size > * Committed_AS > * Active anon > > > > and the total number of connections are increasing very fast (but I suppose > it's the symptom not the root cause of cpu load) and exceed max_connections > (1000). > I doubt you have 1000 cores in your system, so 1000 connections active at the same time is guaranteed to cause issues. What we see quite often is a minor hiccup (occasional slow query) snowballing into much more serious trouble exactly because of this. Queries get slower for some reason, application starts opening more connections (through a built-in connection pool) to run more queries, that further increases pressure, slows the queries even more, ... As Scott suggested, you should consider using a connection pool. > System: > * CentOS Linux release 7.2.1511 (Core) > * Linux 3.10.0-327.36.3.el7.x86_64 #1 SMP Mon Oct 24 16:09:20 UTC 2016 > x86_64 x86_64 x86_64 GNU/Linux > * postgresql95-9.5.5-1PGDG.rhel7.x86_64 > * postgresql95-contrib-9.5.5-1PGDG.rhel7.x86_64 > * postgresql95-docs-9.5.5-1PGDG.rhel7.x86_64 > * postgresql95-libs-9.5.5-1PGDG.rhel7.x86_64 > * postgresql95-server-9.5.5-1PGDG.rhel7.x86_64 > > * 4 sockets/80 cores > * vm.dirty_background_bytes = 0 > * vm.dirty_background_ratio = 2 > * vm.dirty_bytes = 0 > * vm.dirty_expire_centisecs = 3000 > * vm.dirty_ratio = 20 > * vm.dirty_writeback_centisecs = 500 > > after the first incident we have changed: > * increased shared_buffers to 16GB (completely on huge pages. previously > 2GB) > * adjusted vm.nr_hugepages to 8000 (we've got 2mb pages) > * changed vm.overcommit_memory = 2 and vm.overcommit_ratio = 99 > * disabled transparent huge pages (they were set before unfortunately to > 'always') > > > It's a highly transactional db. Today I've run: > select now(), txid_current(); > and the results: > 3 339 351 transactions between 2017-10-10 14:42 and 2017-10-10 16:24 > Well, 3M transactions over ~2h period is just ~450tps, so nothing extreme. Not sure how large the transactions are, of course. > ... snip ... > > So, from the kernel stats we know that the failure happens when db is trying > to alocate some huge amount of pages (page tables size, anons, commited_as). > But what is triggering this situation? > Something gets executed on the database. We have no idea what it is, but it should be in the system logs. And you should see the process in 'top' with large amounts of virtual memory ... > I suppose it could be lazy autovacuum (just standard settings). So > autovacuum had to read whole 369gb yesterday to clean xids. today did the > same on some other tables. Possible, but it shouldn't allocate more than maintenance_work_mem. So I don't why it would allocate so much virtual memory. Another possibility is a run-away query that consumes a lot of work_mem. > Another idea is too small shared buffers setting. ... snip ... > bgwriter stats: > > Yes, this suggests you probably have shared_buffers set too low, but it's impossible to say if increasing the size will help - perhaps your active set (part of DB you regularly access) is way too big. Measure cache hit ratio (see pg_stat_database.blks_hit and blks_read), and then you can decide. You may also make the bgwriter more aggressive - that won't really improve the hit ratio, it will only make enough room for the backends. But I don't quite see how this could cause the severe problems you have, as I assume this is kinda regular behavior on that system. Hard to say without more data. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general