Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gMkrK-0007jN-WA for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Nov 2018 02:24:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gMkrI-0007d4-Qi for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Nov 2018 02:24:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gMkrI-0007cw-7n for pgsql-hackers@lists.postgresql.org; Wed, 14 Nov 2018 02:24:48 +0000 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gMkrB-0005Ga-11 for pgsql-hackers@postgresql.org; Wed, 14 Nov 2018 02:24:46 +0000 Received: by mail-pg1-x533.google.com with SMTP id 80so6626640pge.4 for ; Tue, 13 Nov 2018 18:24:40 -0800 (PST) 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=Gv9sSu9BtzmsuttdWy+Ks04NhpDBx/Rr2mWXaXx1Y+I=; b=V6QYk7sg2GjQt9FQz4CA1k+G/iXexMU6gBc3sUiHdj9oBHKeF9ulVNOR9oRSOdjMtI rUAk8PPfQdR1iaK4HZLc1xcQArNr6kid83nv2zsuEKxeRSgwtYTHD8qYS7BJKMweWWLJ UvXdidCjIgas7M+g8GgbGPHkECEL7djpH5Qf0= 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=Gv9sSu9BtzmsuttdWy+Ks04NhpDBx/Rr2mWXaXx1Y+I=; b=l3Z5euhpLdswcmh/UATHSUbfm4mQrTdPtqtWKazSzI5E0yDcc2ebbys1pidOimn9GA adsMciCoXsji1PsT5mg07ojjRgAQFNl70ByNOwoSBvf6dmjGR+SWBhs4+oucWCall0be LaBCrvJ5VD34ANaU9juJnJUwcZrLjqlC+EsQmWVa/kVfzAo4Ux4RJEOzLW0bWjyaJazn 33wOlOaRsDAefL4S49vCLbJbvIFh73di7eXobjCpXOnZV8zlS6IqFD5DYeY69cZrUxa1 vbClK1bfYzwT6XUKxF7LvWE19K/BEhqMqebBqI8VG6QTnEn/NIT7r3RavTdi/MyVdp5z Ol6A== X-Gm-Message-State: AGRZ1gItYoySRYNB5XKH9MF6qb12u1H8GAe3bmajJqGzldvwF04PYs87 y3Zeqh14TduxcCunlWcTkQS7nw== X-Google-Smtp-Source: AJdET5ckaX4ZdI6FYxU9pME0xS5oCDD7kPUt66AGqzAkjf62BnHfbqmfQgQu+tIypjqX605px4futQ== X-Received: by 2002:a63:6cc:: with SMTP id 195mr83982pgg.52.1542162279730; Tue, 13 Nov 2018 18:24:39 -0800 (PST) Received: from rfd.leadboat.com (c-73-158-248-138.hsd1.ca.comcast.net. [73.158.248.138]) by smtp.gmail.com with ESMTPSA id r6-v6sm24899282pfk.157.2018.11.13.18.24.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Nov 2018 18:24:38 -0800 (PST) Date: Tue, 13 Nov 2018 18:24:35 -0800 From: Noah Misch To: Tom Lane , Thomas Munro Cc: Pg Hackers Subject: Re: DSM segment handle generation in background workers Message-ID: <20181114022435.GC1096408@rfd.leadboat.com> References: <17043.1539046409@sss.pgh.pa.us> <9879.1539233472@sss.pgh.pa.us> <20181112083358.GA1073796@rfd.leadboat.com> <32455.1542033541@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <32455.1542033541@sss.pgh.pa.us> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Nov 12, 2018 at 09:39:01AM -0500, Tom Lane wrote: > Thomas Munro writes: > > On Mon, Nov 12, 2018 at 9:34 PM Noah Misch wrote: > >> Compared to the old code, the new code requires more wall time to visit every > >> possible seed value. New code xor's the PID bits into the fastest-changing > >> timestamp bits, so only about twenty bits can vary within any given one-second > >> period. (That assumes a PID space of twenty or fewer bits; fifteen bits is > >> the Linux default.) Is that aspect of the change justified? > > > Hmm, right. How about applying pg_bswap32() to one of the terms, as > > an easy approximation of reversing the bits? That seems adequate, yes. But why not just restore the old algorithm in the new function? (I'm not opposed to revising the algorithm, but I think a revision should have explicit goals. The ease of pg_bswap32() is not itself a worthy goal, because the old BackendRun() algorithm was also quite easy.) > I doubt that's a good idea; to a first approximation, it would mean that > half the seed depends only on the PID and the other half only on the > timestamp. Maybe we could improve matters a little by left-shifting the > PID four bits or so, but I think we still want it to mix with some > rapidly-changing time bits. > > I'm not really sure that we need to do anything though. Basically, > what we've got here is a tradeoff between how many bits change over > a given timespan and how unpredictable those bits are. I don't see > that one of those is necessarily more important than the other. What counts is the ease of predicting a complete seed. HEAD's algorithm has ~13 trivially-predictable bits, and the algorithm that stood in BackendRun() from 98c5065 until 197e4af had no such bits. You're right that the other 19 bits are harder to predict than any given 19 bits under the old algorithm, but the complete seed remains more predictable than it was before 197e4af. Goal I recommend: if connections arrive in a Poisson distribution of unknown lambda, maximize the number of distinct seeds. nm