Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cox0I-00008b-F4 for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Mar 2017 18:53:34 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cox0H-0004mR-GV for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Mar 2017 18:53:33 +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 1cowyn-00028v-H5 for pgsql-hackers@postgresql.org; Fri, 17 Mar 2017 18:52:01 +0000 Received: from mail-qk0-x22a.google.com ([2607:f8b0:400d:c09::22a]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1cowyj-0006hC-LP for pgsql-hackers@postgresql.org; Fri, 17 Mar 2017 18:52:00 +0000 Received: by mail-qk0-x22a.google.com with SMTP id 1so71857769qkl.3 for ; Fri, 17 Mar 2017 11:51:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=from:subject:to:references:cc:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=+cDxscJVcqHfBj0pzu8HBzvrMmaLNFgNQDN8Zguuggc=; b=cvg4FEYouDMPaeMUgXxcPgQfBiZnlxhkmw71bkLv9f8Sllygj+cVZjNGUP4q8I546n G8YEycPrExwffFu1kJflzaIv4vaG81wuMhHeQQFAaEzx9lZpTp/yzuZe5ZQ5Wk6xSwIt ZkAvsPqh6K41MYFv92PL/cs0HA2GnPooNeoPDAryY3dzhelSk6gGMyLcazT2At24cKJY bWV9FJnfn2ukvNQWkYQ4c5HoL4raZ7VWllD45RzrqxUxXyoon84ZL6EHEGWlLyjQDph6 TV+AhuHB4dWrvmkb/qOxtuKp/jTZCL28GBYWHb3dy+Bs/gcCksIE4jS9ccMKlXok/uXj 98pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:references:cc:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=+cDxscJVcqHfBj0pzu8HBzvrMmaLNFgNQDN8Zguuggc=; b=f+z96iWP6GvIClLJxV8wE4hUn/4Kp04v0eWSO5u54a/7lcar959wKVnJZ5lyS17O5o fDDDmghmBEjdzWBTXmn/lO2TAkS0YnpTFx+7DSYV4CBjCHypjHq18DgEsx39/KeOyZPZ SEaJOAqCRznPbye9Mx/hvM3XnboWNQc28m7wGuenkMT9qqsAYb3Vu7KHuQdSQCdMExk7 0wQt+5HwQgpYchQLIwAcYlxXWnZAS0QFu41vUqOJKGBtEFduQ3kW/eRPGMSolrBMe+qd 1gMbVnLRSMpg3UTZ4QioJe+mEj0iYTQnjCmdAZE/B6qcdSlDW9guO0qjO+oOwNV6us9N Knqw== X-Gm-Message-State: AFeK/H2Ks+7h2H65djGj88ohz3Afz1OcJyQt42LEqLIieODALj7LHBET/Q8Ul6qrvg4rnP6Kimi3S0SqsuORri5J+FzYo0tXeeoGQJVza7tWwjkrHi3+O5JhLaJRL731S4WAdL7aVeackdpTwPZmRHp+ZNyz8wcatK1JpQj8ZKEsB240V9tvyym+njZyN2dlPeMEqSf2qQOo+NE= X-Received: by 10.55.73.147 with SMTP id w141mr15717226qka.205.1489776715599; Fri, 17 Mar 2017 11:51:55 -0700 (PDT) Received: from [192.168.10.146] ([98.122.164.227]) by smtp.gmail.com with ESMTPSA id j1sm6500252qkf.57.2017.03.17.11.51.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Mar 2017 11:51:54 -0700 (PDT) From: Andrew Dunstan X-Google-Original-From: Andrew Dunstan Subject: Re: [COMMITTERS] pgsql: Use asynchronous connect API in libpqwalreceiver To: Tom Lane , Petr Jelinek References: <19403.1488586564@sss.pgh.pa.us> <34d98fbf-9195-04d2-b85a-634d6952ffdf@2ndquadrant.com> <19815.1488600693@sss.pgh.pa.us> <4144256b-dc4f-892c-a720-71f6e7b9ac87@2ndquadrant.com> <3ffe98f7-d2ed-65c6-51f3-4d97ffd6e312@2ndquadrant.com> <34591606-976a-bbee-8eda-778c1e1fc52f@2ndQuadrant.com> <10458.1489763266@sss.pgh.pa.us> <5b6a6d6d-fb45-0afb-2e95-5600063c3dbd@2ndquadrant.com> <13398.1489768097@sss.pgh.pa.us> Cc: Peter Eisentraut , pgsql-hackers@postgresql.org Message-ID: <927edd39-ed04-ea57-a98c-638eb0365431@2ndQuadrant.com> Date: Fri, 17 Mar 2017 14:51:54 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: <13398.1489768097@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 03/17/2017 12:28 PM, Tom Lane wrote: > Petr Jelinek writes: >> Now the documentation for WSAEventSelect says "The FD_WRITE network >> event is handled slightly differently. An FD_WRITE network event is >> recorded when a socket is first connected with a call to the connect, >> ConnectEx, WSAConnect, WSAConnectByList, or WSAConnectByName function or >> when a socket is accepted with accept, AcceptEx, or WSAAccept function >> and then after a send fails with WSAEWOULDBLOCK and buffer space becomes >> available. Therefore, an application can assume that sends are possible >> starting from the first FD_WRITE network event setting and lasting until >> a send returns WSAEWOULDBLOCK. After such a failure the application will >> find out that sends are again possible when an FD_WRITE network event is >> recorded and the associated event object is set." >> But while PQconnectPoll does connect() before setting connection status >> to CONNECTION_STARTED and returns PGRES_POLLING_WRITING so the FD_WRITE >> eventually happens, it does not do any writes in the code block that >> switches to CONNECTION_MADE and PGRES_POLLING_WRITING. That means >> FD_WRITE event is never recorded as per quoted documentation. > Ah-hah! Great detective work. > >> Then what remains is why it works in libpq. If you look at >> pgwin32_select which is eventually called by libpq code, it actually >> handles the situation by trying empty WSASend on any socket that is >> supposed to wait for FD_WRITE and only calling the >> WaitForMultipleObjectsEx when WSASend failed with WSAEWOULDBLOCK, when >> the WSASend succeeds it immediately returns ok. >> So I did something similar in attached for WaitEventSetWaitBlock() and >> it indeed solves the issue my windows test machine. Now the >> coding/placement probably isn't the best (and there are no comments), >> but maybe somebody will find proper place for this now that we know the >> cause. > Yeah, I'm afraid we had better do something more or less like this. > It's interesting to speculate about whether WaitEventSet could keep > additional state that would avoid the need for a dummy send() every > time, but that seems like material for new development not a bug fix. > > In any case, a quick review of the code suggests that there are no > performance-critical places where we wait for WL_SOCKET_WRITEABLE > unless we've already detected that we have to wait for the network; > so the dummy send() isn't going to do anything except consume a > few more CPU cycles before we get to the point of blocking. It may > not be worth worrying about. > > I'll add some comments and push this. Does everyone agree that > this had better get back-patched, too? > > Confirmed that this fixes the problem on jacana. +1 for backpatching. Does that mean we could remove the special logic in pgstat.c? cheers andrew -- Andrew Dunstan https://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers