Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jPJnk-0001TX-3h for pgsql-committers@arkaria.postgresql.org; Fri, 17 Apr 2020 05:44:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jPJnZ-0001f5-OV for pgsql-committers@arkaria.postgresql.org; Fri, 17 Apr 2020 05:44:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jPJnZ-0001cx-B0 for pgsql-committers@lists.postgresql.org; Fri, 17 Apr 2020 05:44:21 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jPJnW-0006XB-Je for pgsql-committers@lists.postgresql.org; Fri, 17 Apr 2020 05:44:20 +0000 Received: by mail-pg1-x541.google.com with SMTP id x26so572298pgc.10 for ; Thu, 16 Apr 2020 22:44:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Q8hLq+iTWBaG7CbeOk7whmBvRF1MLx+i+u+pjZdB95c=; b=PZ6bUXlpKKYSxLHsiEIocFSmDUaPmPyO5WklSUYBbuYbBeUH/42eFdAdjHZIKc1VLf r/jfbEhVDYpRPFuIZxKMXJK3cpoAo4KSMYdAGSumvzW88MypF+tRiJxaA33u7zcNWmqW nrRttlAIbhpryjnYePODr3WlEAwXVx5+Wn/6U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Q8hLq+iTWBaG7CbeOk7whmBvRF1MLx+i+u+pjZdB95c=; b=j/0TLVSwZivTsfBB0o9U5z4eE5ZVPVK6dg1ewi6y7o89PdxcyoJaHiUxtbGRxVggPU RYr1TrF17rzajpKG+eCBsT4awyPyl8Kvak/IO/dDUGO1b9eR20O9blUuXj9dDTTQ0z5G kVB7UluFd/m2xbLwBDh0LUf6/skygbSdMRWtn/k4k8ysTE9BQpceU0qwoFsZIXYQT8n2 54EkTT8DwF0LazxZ1R6d/Ka38xCEj1WjX8p2Sa2gTXw8P2MX5KRlWRSmbGYD9Uij8gVh nB2wLySaVJv2NQdZuY+6fJ3LfURwmrY9VD9DOCQPC2q/GJP8INRahWZJgK5/7AEd/sy7 RWTQ== X-Gm-Message-State: AGi0PuYgXH6jWE0D1n31+SOcWgGrUf+5DcUTvfRICT00EDWSTFOuovfL rTo5mauWdNXRggXUDQ0rfNEMhw== X-Google-Smtp-Source: APiQypJAszhelg1+Fuiks8K5G8aVW/MYH71hxMVm8GbrrGV8IZxfjPCQ/7jbFyopRhE+IknOSnjNdg== X-Received: by 2002:a62:e30f:: with SMTP id g15mr1573519pfh.150.1587102254855; Thu, 16 Apr 2020 22:44:14 -0700 (PDT) Received: from rfd.leadboat.com (108-233-125-46.lightspeed.sntcca.sbcglobal.net. [108.233.125.46]) by smtp.gmail.com with ESMTPSA id fy21sm4350866pjb.25.2020.04.16.22.44.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Apr 2020 22:44:14 -0700 (PDT) Date: Thu, 16 Apr 2020 22:44:12 -0700 From: Noah Misch To: Fujii Masao Cc: pgsql-committers@lists.postgresql.org Subject: Re: pgsql: When WalSndCaughtUp, sleep only in WalSndWaitForWal(). Message-ID: <20200417054412.GB1061007@rfd.leadboat.com> References: <3e370b08-96a2-fe03-421e-9a188cb66cce@oss.nttdata.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3e370b08-96a2-fe03-421e-9a188cb66cce@oss.nttdata.com> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Apr 17, 2020 at 04:50:38AM +0900, Fujii Masao wrote: > On 2020/04/12 2:35, Noah Misch wrote: > >When WalSndCaughtUp, sleep only in WalSndWaitForWal(). > > > >Before sleeping, WalSndWaitForWal() sends a keepalive if MyWalSnd->write > >< sentPtr. That is important in logical replication. When the latest > >physical LSN yields no logical replication messages (a common case), > >that keepalive elicits a reply, and processing the reply updates > >pg_stat_replication.replay_lsn. WalSndLoop() lacks that; when > >WalSndLoop() slept, replay_lsn advancement could stall until > >wal_receiver_status_interval elapsed. This sometimes stalled > >src/test/subscription/t/001_rep_changes.pl for up to 10s. > > Since this commit, walsender started consuming CPU resource too much in my env. Confirmed. I have shared this with the main thread and added details there. > wakeEvents = WL_LATCH_SET | WL_EXIT_ON_PM_DEATH | WL_TIMEOUT | > - WL_SOCKET_READABLE; > + WL_SOCKET_READABLE | WL_SOCKET_WRITEABLE; > > I wonder if this change caused WaitLatchOrSocket() in WalSndLoop() to wake up > frequently more than necessary. I collected lower wakeup counts after the commit. The problem is a shortage of waits.