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 1jbGkH-0003DB-RL for pgsql-hackers@arkaria.postgresql.org; Wed, 20 May 2020 04:54:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jbGkE-0006Y9-Ex for pgsql-hackers@arkaria.postgresql.org; Wed, 20 May 2020 04:54:18 +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 1jbGkE-0006Y2-5t for pgsql-hackers@lists.postgresql.org; Wed, 20 May 2020 04:54:18 +0000 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jbGk5-0006ht-DP for pgsql-hackers@postgresql.org; Wed, 20 May 2020 04:54:16 +0000 Received: by mail-pj1-x1044.google.com with SMTP id n15so696884pjt.4 for ; Tue, 19 May 2020 21:54:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:to:cc:subject:from:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=a4a7QokJFntWito2TshZwgZVzWoP4/oIqVSb7+jI+C4=; b=AKJz/WlLNNtFsOcckVbYFVDuTq1DBRMAJ5Mm/RW7DwoBRaD3tShSk/mQMf48UbjJy0 dL1lWJJo1SjpLs3DpGngio6A/qyENMNucWYhKRejliJl2X01PWqu8dkgPZ8Ivl1DLZf6 vTGDO9rzJgx6i9SUC9+5HF0I+rThNv3kiBEsppI7aXtIEABNDpnP8tvd8O793L9bAsyu MrjdHVny2Onr3Ul1GsBTF2tN0+CUh5soGnw3W2qUQwRE6zz/b27jF2aKFZzuzdhbwq7S 4EdEg+vnOWGAzJIk+hEEZUzNsAc2LVbFXr+8Nqwa29Tzt6jbqJutudoHor7pMssl1oDj UTlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:to:cc:subject:from:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=a4a7QokJFntWito2TshZwgZVzWoP4/oIqVSb7+jI+C4=; b=hwXwaj8IMa96mVhIcxZ8aCYxokCsrR2Ewg5+P8E408/9u5mBkJwDDFzs83VqU++WlP M26tdicHq3VecAzfjmaiidFG9Dk0oVZzEFsvzD+RnU5iQHykm3xiIFU/2X2RcAcPsNvn wvJzVyY93DQW+yuyzZXE+UsAtzKnscuC+QqtRslh+WBZRKJRVbPZUWDOJZ3jDIYAVOth Ysu6+/iryQRo68dQnbodrk6GIOqCoY6syVC7N51jL6VYHULQowxMs+T0rUA1YpWFw3lD XPDVOpNX6rovXk2P2/gplafG4rmlmKrgHk6k2f5H1I52UY0enp111lqrhtq6qspaDUq1 VuJw== X-Gm-Message-State: AOAM53392JkLdJUyx1GfZqZAa/6ylCALpu723OHfZuNyFTbnFDsLh097 uiRTzwWhjhYj4DiEu51ECx4= X-Google-Smtp-Source: ABdhPJyjSR4feAX0cFPBrlkV1DxKqcxY7hzwd2e4hGWeT4HxkK9NO51+cwxUT3SACw9qg0E72Wpsqg== X-Received: by 2002:a17:902:522:: with SMTP id 31mr2894492plf.68.1589950446876; Tue, 19 May 2020 21:54:06 -0700 (PDT) Received: from localhost (ag027197.dynamic.ppp.asahi-net.or.jp. [157.107.27.197]) by smtp.gmail.com with ESMTPSA id d8sm933149pfq.123.2020.05.19.21.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 21:54:05 -0700 (PDT) Date: Wed, 20 May 2020 13:54:04 +0900 (JST) Message-Id: <20200520.135404.64670166185539892.horikyota.ntt@gmail.com> To: x4mmm@yandex-team.ru Cc: pgsql-hackers@postgresql.org Subject: Re: MultiXact\SLRU buffers configuration From: Kyotaro Horiguchi In-Reply-To: References: <102F673B-C9C5-4823-A92F-96799FC61ED0@yandex-team.ru> <20200515.090333.24867479329066911.horikyota.ntt@gmail.com> User-Agent: Mew version 6.8 on Emacs 26.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=koi8-r Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk At Fri, 15 May 2020 14:01:46 +0500, "Andrey M. Borodin" wrote in = > = > = > > 15 =CD=C1=D1 2020 =C7., =D7 05:03, Kyotaro Horiguchi =CE=C1=D0=C9=D3=C1=CC(=C1): > > = > > At Thu, 14 May 2020 11:44:01 +0500, "Andrey M. Borodin" wrote in = > >>> GetMultiXactIdMembers believes that 4 is successfully done if 2 > >>> returned valid offset, but actually that is not obvious. > >>> = > >>> If we add a single giant lock just to isolate ,say, > >>> GetMultiXactIdMember and RecordNewMultiXact, it reduces concurren= cy > >>> unnecessarily. Perhaps we need finer-grained locking-key for sta= ndby > >>> that works similary to buffer lock on primary, that doesn't cause= > >>> confilicts between irrelevant mxids. > >>> = > >> We can just replay members before offsets. If offset is already th= ere - members are there too. > >> But I'd be happy if we could mitigate those 1000us too - with a hi= nt about last maixd state in a shared MX state, for example. > > = > > Generally in such cases, condition variables would work. In the > > attached PoC, the reader side gets no penalty in the "likely" code > > path. The writer side always calls ConditionVariableBroadcast but = the > > waiter list is empty in almost all cases. But I couldn't cause the= > > situation where the sleep 1000u is reached. > Thanks! That really looks like a good solution without magic timeouts= . Beautiful! > I think I can create temporary extension which calls MultiXact API an= d tests edge-cases like this 1000us wait. > This extension will also be also useful for me to assess impact of bi= gger buffers, reduced read locking (as in my 2nd patch) and other tweak= s. Happy to hear that, It would need to use timeout just in case, though. > >> Actually, if we read empty mxid array instead of something that is= replayed just yet - it's not a problem of inconsistency, because trans= action in this mxid could not commit before we started. ISTM. > >> So instead of fix, we, probably, can just add a comment. If this r= easoning is correct. > > = > > The step 4 of the reader side reads the members of the target mxid.= It > > is already written if the offset of the *next* mxid is filled-in. > Most often - yes, but members are not guaranteed to be filled in orde= r. Those who win MXMemberControlLock will write first. > But nobody can read members of MXID before it is returned. And its me= mbers will be written before returning MXID. Yeah, right. Otherwise assertion failure happens. regards. -- = Kyotaro Horiguchi NTT Open Source Software Center