Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xl2EZ-0002W0-QB for pgsql-performance@arkaria.postgresql.org; Sun, 02 Nov 2014 20:58:48 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xl2EZ-00008I-6u for pgsql-performance@arkaria.postgresql.org; Sun, 02 Nov 2014 20:58:47 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xl2EW-000089-ON for pgsql-performance@postgresql.org; Sun, 02 Nov 2014 20:58:45 +0000 Received: from mail-pd0-x235.google.com ([2607:f8b0:400e:c02::235]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Xl2ES-0006Zl-CH for pgsql-performance@postgresql.org; Sun, 02 Nov 2014 20:58:42 +0000 Received: by mail-pd0-f181.google.com with SMTP id y10so10223916pdj.26 for ; Sun, 02 Nov 2014 12:58:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :message-id:references:to; bh=CHfGOegPxXNGQQRoJTEdG9rFqHIyU0ZjJLG6gtQ4tlU=; b=SkSu6U4ZMNY8LRooRONVOPrP/70kuyc311RsD5zkHRejWeq7AqpmrBoiXhFzd2PNwo TLzfMX/tE5uz6Lf++bVjiDwE67430u3EiWfywtFZYS9w50M7Lq6/NaKPRBjfnHt9TK+v eJRw+efbpz7xS8rKVH0MfhBr64AiJcVLSayDvBJ54ZMU/s5FQT/uSCioz3GEXVpfchCr +n6YvBfUlTj7q90ygqiTeWfyOV7D3ckl6C2tcjoG5OlOHZlk5t6B/E3iINAYOg0HU2T0 vFClCM95Cev8lJUZf3m5/LUvmSdQp6479NpcGC1Rdugcalwac+1HfIr3I7Rbb/02edD9 BzOw== X-Received: by 10.70.95.198 with SMTP id dm6mr38951633pdb.58.1414961918537; Sun, 02 Nov 2014 12:58:38 -0800 (PST) Received: from [10.0.1.16] (cpe-104-174-121-31.socal.res.rr.com. [104.174.121.31]) by mx.google.com with ESMTPSA id oo9sm15322128pdb.26.2014.11.02.12.58.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 02 Nov 2014 12:58:38 -0800 (PST) Content-Type: multipart/alternative; boundary="Apple-Mail=_D15DEEF5-2EA8-424F-90CD-D4440F0F7FCF" Mime-Version: 1.0 (Mac OS X Mail 8.0 \(1990.1\)) Subject: Re: Replication Lag Causes From: Mike Wilson In-Reply-To: Date: Sun, 2 Nov 2014 12:58:31 -0800 Cc: pgsql-performance@postgresql.org Message-Id: <29D3BBBA-1310-4624-8E78-F306B1803764@gmail.com> References: To: Valentine Gogichashvili X-Mailer: Apple Mail (2.1990.1) X-Pg-Spam-Score: -2.7 (--) 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=_D15DEEF5-2EA8-424F-90CD-D4440F0F7FCF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Load on the slave is relatively light. It averages about 1.0 due to = some data ware house select queries running against it frequently. = Previously only the load on the master seems to have affected our = replication lag no matter what the slave was doing. =20 In thinking about this a bit more, the load on the master does cause = increasing lag but only if the query mix begins to change to more DML = than SELECTS. Basically, the amount of DML is what really appears to = cause the replication to lag. This is an OLTP system backing a rather = heavy commercial website where memberships are sold and when the = purchase traffic increases that is when we start to see extreme lag = develop on the slave. CPU utilization on the slave during extreme lag is similar to normal = operation even if the slave is lagging more than usual. Thanks for the info on max_wal_senders. That=E2=80=99s good to know. Mike Wilson > On Nov 1, 2014, at 4:14 PM, Valentine Gogichashvili = wrote: >=20 > Hello Mike,=20 >=20 > what kind of load does the slave get? >=20 > what does the recovery process do on the slave during the times when = lag is being observed? Does it use 100% of the CPU? >=20 > WAL can be replayed by only one process, so no need to increase the = max_wal_senders. >=20 > Cheers, >=20 > -- Valentine Gogichashvili >=20 > On Sun, Nov 2, 2014 at 1:33 AM, Mike Wilson > wrote: > I have two 9.3.4 PG instances that back a large internet website that = has very seasonal traffic and can generate large query loads. My = instances are in a master-slave streaming replication setup and are = stable and in general perform very well. The only issues we have with = the boxes is that when the master is busy the slave may start to lag = excessively. I can give specifics as to what heavily loaded means and = additionally the postgresql.conf for both boxes but my basic questions = are: > * What causes streaming replication lag to increase? =20 > * What parameters can be tuned to reduce streaming replication lag? > * Can a loaded slave affect lag adversely? > * Can increasing max_wal_senders help reduce lag? >=20 > The reason I ask this is that as mentioned above the servers are = stable and are real troopers in general as they back a very popular web = site that puts the master under heavy seasonal load at times. At those = times though we see an almost exponential growth in streaming = replication lag compared to load on the master. =20 >=20 > For example, the master is a very beefy Solaris: > * 4 Recent Intel Zeons (16 physical cores) > * 256 GB of ECC RAM > * 12 TB of ZFS (spindle and SSD internal storage) > * DB on disk size is 2TB > * ZFS ARC cache of roughly 250G. > * ZFS ARC2/ZIL configured for SSD=E2=80=99s (this is awesome by the = way) >=20 > Basic PG Config: > shared_buffers =3D 2GB > work_mem =3D 128MB > max_connections =3D 1700 (supports roughly 100 web servers) > wal_keep_segments =3D 256 (roughly enough for 24 hours of operation = under heavy load) > wal_sender_timeout =3D 60s > replication_timeout=3D(not set) > wal_receiver_status_interval=3D10s > max_wal_senders=3D6 > * wal archiving is off > * 98% of the queries on the master complete in under 500ms. > * No hung or very long running queries in general. >=20 > The master on a normal day maintains a load of about 0.5, during which = replication lag to the slave is in hundreds milliseconds. When the = production db server is heavily hit though the load may go as high as 4 = on the master and the streaming replication lag may increase to more = than 2 hours relatively quickly. Load on the slave is generally below 1 = even when the master is heavily loaded. The traffic to the master is = primarily read with about 10% DML (new users, purchase records, etc). = DML statements increase proportionally when under load though. The = master and slave are connected via dedicated 10G fiber link and even = under heavy load the utilization of the link is nowhere near close to = saturation. BTW, the slave does run some reported related queries = throughout the day that might take up to a minute to complete. >=20 > I have the task of figuring out why this otherwise healthy DB starts = to lag so badly under load and if there is anything that we could do = about it. I=E2=80=99ve been wondering particularly if we should up the = max_wal_senders but from the docs it is unclear if that would help. In = my testing with pg_bench on our dev boxes which were the previous = production hardware for these servers I have determined that it = doesn=E2=80=99t take much DML load on the master to get the slave to = start lagging severely. I was wondering if this was expected and/or = some design consideration? Possibly streaming replication isn=E2=80=99t = meant to be used for heavily hit databases and maintain small lag times? = I would like to believe that the fault is something we have done though = and that there is some parameter we could tune to reduce this lag. >=20 > Any recommendations would be very helpful. =20 > =20 > Mike Wilson > Predicate Logic Consulting >=20 >=20 >=20 >=20 --Apple-Mail=_D15DEEF5-2EA8-424F-90CD-D4440F0F7FCF Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Load on the slave is relatively light.  It averages = about 1.0 due to some data ware house select queries running against it = frequently.  Previously only the load on the master seems to have = affected our replication lag no matter what the slave was doing. =  

In thinking = about this a bit more, the load on the master does cause increasing lag = but only if the query mix begins to change to more DML than SELECTS. =  Basically, the amount of DML is what really appears to cause the = replication to lag.  This is an OLTP system backing a rather heavy = commercial website where memberships are sold and when the purchase = traffic increases that is when we start to see extreme lag develop on = the slave.

CPU = utilization on the slave during extreme lag is similar to normal = operation even if the slave is lagging more than usual.

Thanks for the info on = max_wal_senders.  That=E2=80=99s good to know.

Mike Wilson




On Nov 1, 2014, at 4:14 PM, Valentine Gogichashvili <valgog@gmail.com> = wrote:

Hello Mike, 

what kind of load does the slave = get?

what does = the recovery process do on the slave during the times when lag is being = observed? Does it use 100% of the CPU?

WAL can be replayed by only one = process, so no need to increase the max_wal_senders.

Cheers,

-- Valentine = Gogichashvili

On Sun, Nov 2, 2014 at 1:33 = AM, Mike Wilson <mfwilson@gmail.com> wrote:
I have two 9.3.4 PG instances = that back a large internet website that has very seasonal traffic and = can generate large query loads.  My instances are in a master-slave = streaming replication setup  and are stable and in general perform = very well.  The only issues we have with the boxes is that when the = master is busy the slave may start to lag excessively.  I can give = specifics as to what heavily loaded means and additionally the = postgresql.conf for both boxes but my basic questions are:
   * What causes streaming replication lag to = increase?  
   * What parameters can = be tuned to reduce streaming replication lag?
  =  * Can a loaded slave affect lag adversely?
   * Can increasing max_wal_senders help reduce = lag?

The = reason I ask this is that as mentioned above the servers are stable and = are real troopers in general as they back a very popular web site that = puts the master under heavy seasonal load at times.  At those times = though we see an almost exponential growth in streaming replication lag = compared to load on the master.  

For example, the master is a very beefy = Solaris:
   * 4 Recent Intel Zeons (16 = physical cores)
   * 256 GB of ECC = RAM
   * 12 TB of ZFS (spindle and SSD = internal storage)
   * DB on disk size is = 2TB
   * ZFS ARC cache of roughly = 250G.
   * ZFS ARC2/ZIL configured for = SSD=E2=80=99s (this is awesome by the way)

Basic PG Config:
   shared_buffers =3D 2GB
 =  work_mem =3D 128MB
  =  max_connections =3D 1700 (supports roughly 100 web = servers)
   wal_keep_segments =3D 256 = (roughly enough for 24 hours of operation under heavy load)
   wal_sender_timeout =3D 60s
   replication_timeout=3D(not set)
   wal_receiver_status_interval=3D10s
   max_wal_senders=3D6
  =  * wal archiving is off
   * 98% of = the queries on the master complete in under 500ms.
   * No hung or very long running queries in = general.

The = master on a normal day maintains a load of about 0.5, during which = replication lag to the slave is in hundreds milliseconds.  When the = production db server is heavily hit though the load may go as high as 4 = on the master and the streaming replication lag may increase to more = than 2 hours relatively quickly.  Load on the slave is generally = below 1 even when the master is heavily loaded.  The traffic to the = master is primarily read with about 10% DML (new users, purchase = records, etc).  DML statements increase proportionally when under = load though.  The master and slave are connected via dedicated 10G = fiber link and even under heavy load the utilization of the link is = nowhere near close to saturation.  BTW, the slave does run some = reported related queries throughout the day that might take up to a = minute to complete.

I have the task of figuring out why this otherwise healthy DB = starts to lag so badly under load and if there is anything that we could = do about it.  I=E2=80=99ve been wondering particularly if we should = up the max_wal_senders but from the docs it is unclear if that would = help.  In my testing with pg_bench on our dev boxes which were the = previous production hardware for these servers I have determined that it = doesn=E2=80=99t take much DML load on the master to get the slave to = start lagging severely.  I was wondering if this was expected = and/or some design consideration?  Possibly streaming replication = isn=E2=80=99t meant to be used for heavily hit databases and maintain = small lag times?  I would like to believe that the fault is = something we have done though and that there is some parameter we could = tune to reduce this lag.

Any recommendations would be very helpful.  
 
Mike Wilson
Predicate Logic Consulting





= --Apple-Mail=_D15DEEF5-2EA8-424F-90CD-D4440F0F7FCF--