Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WZjxZ-0001Jp-En for pgsql-performance@arkaria.postgresql.org; Mon, 14 Apr 2014 16:42:18 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WZjxY-0006JD-N0 for pgsql-performance@arkaria.postgresql.org; Mon, 14 Apr 2014 16:42:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WZjxX-0006J7-D6 for pgsql-performance@postgresql.org; Mon, 14 Apr 2014 16:42:15 +0000 Received: from forward1l.mail.yandex.net ([2a02:6b8:0:1819::1]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WZjxU-0004by-QI for pgsql-performance@postgresql.org; Mon, 14 Apr 2014 16:42:15 +0000 Received: from smtp2o.mail.yandex.net (smtp2o.mail.yandex.net [37.140.190.27]) by forward1l.mail.yandex.net (Yandex) with ESMTP id 1BAE21520FD4; Mon, 14 Apr 2014 20:42:10 +0400 (MSK) Received: from smtp2o.mail.yandex.net (localhost [127.0.0.1]) by smtp2o.mail.yandex.net (Yandex) with ESMTP id ACBBE36A1937; Mon, 14 Apr 2014 20:42:09 +0400 (MSK) Received: from 37.140.175.168-red3.dhcp.yndx.net (37.140.175.168-red3.dhcp.yndx.net [37.140.175.168]) by smtp2o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id Khk7o0BkmN-g9AqQONF; Mon, 14 Apr 2014 20:42:09 +0400 (using TLSv1 with cipher AES128-SHA (128/128 bits)) (Client certificate not present) X-Yandex-Uniq: 602fbd61-3506-4c54-a584-e507ccc670e9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=simply.name; s=mail; t=1397493729; bh=OO/Hr7t31gZ1r9NdV7nuBOEIf2126dSixrzA7S6D4qk=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To:X-Mailer; b=YCr1fONxwfz+zq9QmWkANKeDRkM/XhsWNFhk3+3fiZ8B5kpIewJU6hzt30qyQgyvl oWRiGIG+R0xeF47+EN5SlZmnWT9xCeZMai+vKs7l4JrbMv9CUhk1jxj8vdB6R120Zo saRGJwQ/lXWdoTZkFkCmsKQU30P4lbig3CFK/AKg= Authentication-Results: smtp2o.mail.yandex.net; dkim=pass header.i=@simply.name Content-Type: multipart/alternative; boundary="Apple-Mail=_398CD3AA-4FFE-45B8-B812-996AD7B39782" Mime-Version: 1.0 (Mac OS X Mail 7.2 \(1874\)) Subject: Re: Checkpoint distribution From: Borodin Vladimir In-Reply-To: Date: Mon, 14 Apr 2014 20:42:08 +0400 Cc: "pgsql-performance@postgresql.org" Message-Id: References: <4AF2BEEF-5BB5-4155-BF70-D3E877914061@simply.name> To: Jeff Janes X-Mailer: Apple Mail (2.1874) X-Pg-Spam-Score: -2.0 (--) 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 --Apple-Mail=_398CD3AA-4FFE-45B8-B812-996AD7B39782 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1251 14 =E0=EF=F0. 2014 =E3., =E2 19:11, Jeff Janes = =ED=E0=EF=E8=F1=E0=EB(=E0): > On Mon, Apr 14, 2014 at 2:46 AM, Borodin Vladimir = wrote: > Hi all. >=20 > I=92m running PostgreSQL 9.3.4 and doing stress test of the database = with writing only load. The test plan does 1000 transactions per second = (each of them does several updates/inserts). The problem is that = checkpoint is not distributed over time well. When the checkpoint = finishes, the db gets lots of I/O operations and response timings grows = strongly. >=20 > My checkpoint settings looks like that: >=20 > postgres=3D# select name, setting from pg_catalog.pg_settings where = name like 'checkpoint%' and boot_val !=3D reset_val; > name | setting=20 > ------------------------------+--------- > checkpoint_completion_target | 0.9 > checkpoint_segments | 100500 > checkpoint_timeout | 600 > (3 rows) >=20 > postgres=3D# >=20 > But in the log I see that checkpoint continues less than 600*0.9 =3D = 540 seconds: >=20 > 2014-04-14 12:54:41.479 MSK,,,10517,,53468da6.2915,433,,2014-04-10 = 16:25:10 MSK,,0,LOG,00000,"checkpoint starting: time",,,,,,,,,"" > 2014-04-14 12:57:06.107 MSK,,,10517,,53468da6.2915,434,,2014-04-10 = 16:25:10 MSK,,0,LOG,00000,"checkpoint complete: wrote 65140 buffers = (24.8%); 0 transaction log file(s) added, 0 removed, 327 recycled; = write=3D134.217 s, sync=3D10.292 s, total=3D144.627 s; sync files=3D31, = longest=3D3.332 s, average=3D0.331 s",,,,,,,,,=BB" >=20 > When a checkpoint starts, the checkpointer process counts up all the = buffers that need to be written. Then it goes through and writes them. = It paces itself by comparing how many buffers it itself has written to = how many need to be written. But if a buffer that needs to be = checkpointed happens to get written by some other process (the = background writer, or a backend, because they need a clean buffer to = read different data into), the checkpointer is not notified of this and = doesn't count that buffer as being written when it computes whether it = is on track. This causes it to finish early. This can be confusing, = but probably doesn't cause any real problems. The reason for = checkpoint_completion_target is to spread the IO out over a longer time, = but if much of the checkpoint IO is really being done by the background = writer, than it is already getting spread out fairly well. I didn=92t know that, thanks. Seems, that I have quite small shared = buffers size. I will investigate this problem. >=20 > When the checkpoint starts (12:54:41.479) dstat says that I/O load = increases: > =20 > ... >=20 > But when it finishes (12:57:06.107) the I/O load is much higher than = the hardware can do: >=20 > During the writing phase of the checkpoint, PostgreSQL passes the = dirty data to the OS. At the end, it then tells the OS to make sure = that that data has actually reached disk. If your OS stored up too much = dirty data in memory then it kind of freaks out once it is notified it = needs to actually write that data to disk. The best solution for this = may be to lower dirty_background_bytes or dirty_background_ratio so the = OS doesn't store up so much trouble for itself. >=20 Actually, I have already tuned them to different values. Test results = above have been obtained with such settings for page cache: vm.dirty_background_ratio =3D 5 vm.dirty_ratio =3D 40 vm.dirty_expire_centisecs =3D 100 vm.dirty_writeback_centisecs =3D 100 Togethrer with previous point I will try to tune os and postgres = settings. Thanks. > Cheers >=20 > Jeff -- Vladimir --Apple-Mail=_398CD3AA-4FFE-45B8-B812-996AD7B39782 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=windows-1251 14 = =E0=EF=F0. 2014 =E3., =E2 19:11, Jeff Janes <jeff.janes@gmail.com> = =ED=E0=EF=E8=F1=E0=EB(=E0):

On = Mon, Apr 14, 2014 at 2:46 AM, Borodin Vladimir <root@simply.name> wrote:
Hi all.

I=92m running PostgreSQL 9.3.4 and doing stress test of the database = with writing only load. The test plan does 1000 transactions per second = (each of them does several updates/inserts). The problem is that = checkpoint is not distributed over time well. When the checkpoint = finishes, the db gets lots of I/O operations and response timings grows = strongly.

My checkpoint settings looks like = that:

postgres=3D# = select name, setting from pg_catalog.pg_settings where name like = 'checkpoint%' and boot_val !=3D reset_val;
            =  name             | = setting 
------------------------------+---------
 checkpoint_completion_target | 0.9
 checkpoint_segments     =      | 100500
 checkpoint_timeout           | = 600
(3 = rows)

postgres=3D#

But in the log I see = that checkpoint continues less than 600*0.9 =3D 540 = seconds:

2014-04-14 = 12:54:41.479 MSK,,,10517,,53468da6.2915,433,,2014-04-10 16:25:10 = MSK,,0,LOG,00000,"checkpoint starting: time",,,,,,,,,""
2014-04-14 12:57:06.107 = MSK,,,10517,,53468da6.2915,434,,2014-04-10 16:25:10 = MSK,,0,LOG,00000,"checkpoint complete: wrote 65140 buffers (24.8%); 0 = transaction log file(s) added, 0 removed, 327 recycled; write=3D134.217 = s, sync=3D10.292 s, total=3D144.627 s; sync files=3D31, longest=3D3.332 = s, average=3D0.331 s",,,,,,,,,=BB"

When a checkpoint = starts, the checkpointer process counts up all the buffers that need to = be written.  Then it goes through and writes them.  It paces = itself by comparing how many buffers it itself has written to how many = need to be written.  But if a buffer that needs to be checkpointed = happens to get written by some other process (the background writer, or = a backend, because they need a clean buffer to read different data = into), the checkpointer is not notified of this and doesn't count that = buffer as being written when it computes whether it is on track. =  This causes it to finish early.  This can be confusing, but = probably doesn't cause any real problems.  The reason for = checkpoint_completion_target is to spread the IO out over a longer time, = but if much of the checkpoint IO is really being done by the background = writer, than it is already getting spread out fairly = well.

I didn=92t = know that, thanks. Seems, that I have quite small shared buffers size. I = will investigate this problem.


When the checkpoint starts (12:54:41.479) dstat says that I/O = load increases:
=
 
...

But when it finishes (12:57:06.107) the I/O load is = much higher than the hardware can = do:

During the writing phase of the checkpoint, PostgreSQL passes the dirty = data to the OS.  At the end, it then tells the OS to make sure that = that data has actually reached disk.  If your OS stored up too much = dirty data in memory then it kind of freaks out once it is notified it = needs to actually write that data to disk.  The best solution for = this may be to lower dirty_background_bytes = or dirty_background_ratio so the OS doesn't store up so much = trouble for itself.
=


Actually= , I have already tuned them to different values. Test results above have = been obtained with such settings for page = cache:

vm.dirty_background_ratio =3D = 5
vm.dirty_ratio =3D 40
vm.dirty_expire_centisecs =3D = 100
vm.dirty_writeback_centisecs =3D = 100

Togethrer with previous point I will try to = tune os and postgres settings. Thanks.

Cheers

Jeff

--
Vladimir




= --Apple-Mail=_398CD3AA-4FFE-45B8-B812-996AD7B39782--