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 1hs0mi-0006Kq-Gb for pgsql-performance@arkaria.postgresql.org; Mon, 29 Jul 2019 08:13:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hs0mh-00026i-BJ for pgsql-performance@arkaria.postgresql.org; Mon, 29 Jul 2019 08:13:31 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hs0mg-00023p-VB for pgsql-performance@lists.postgresql.org; Mon, 29 Jul 2019 08:13:31 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hs0me-00047f-9n for pgsql-performance@lists.postgresql.org; Mon, 29 Jul 2019 08:13:30 +0000 Received: by mail-wr1-x432.google.com with SMTP id c2so57536663wrm.8 for ; Mon, 29 Jul 2019 01:13:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=subject:to:cc:references:from:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=TkPxVme4oqDBaBeOgcsS4gpyOx+YhBuwh2MR3YOOiW8=; b=m0fOMWr78K2I832hM15bCtKGwmDby9fUdTlVB4hremZwibrahxwnrJoVTZzYYKJx/2 17hT+BMmJBW/TcvScEBDuHl0wADg0aKglZjPYGFmK8W41Cvc9hD3boUvcsjsop/3OHCI Znr7im/FQZJ+okHK0ewAXAPM7LJwNcW41ykOeUymzxy4ly8070xwk9NVILK4Q20Exaeo hTDVDb4XXjqo+maBpFmLU9VEdL8ZhYfjte07h4nPSZD4IOmVXSNeatnfBPdW97pxXx3P XkinSJD6ux2OwAH06PQlf5Hage77t67w9MyaP3jRav9P1ooKRixBIS/ciJwVk6QGjFHi V8lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=TkPxVme4oqDBaBeOgcsS4gpyOx+YhBuwh2MR3YOOiW8=; b=rM3CXw2wZKTTbjYQySDa4GijBNUxbRkKogbZog0qWLih8Ki6OnhgAv0wKBWEmQEybM BcsrXmXPypoqBP2VZHVPJ3DU1zDXmvEyohRSzSSyJRwj7UyRnK4kcMPQzx8sl7NKnZBQ YlnkjnutC7F/437lqY5XmfYIA6ilub53d52EtQEul16kLFUrUTXrPRzAc6wwjBr562k4 gcYLSYpGBvVCl2i/NQMxOYQKvvp8TvwWy2SO5rttyRoB9D9GU+z8cPB8GNyL+xz1CMzR gcpbtkxsMq3dm563xGSItFswKoNga3s4ZB5AEz0qeL/OwpPUUlB2/I+wrhJdf3Yq9pHu k0rA== X-Gm-Message-State: APjAAAU+OIuO/rTzOEC7gdAcKlw0+gBekuwIxpgYQNGE1m7xeiV1UR0v 6r6byEm9SVfB5yig5IUyxgoNlffR X-Google-Smtp-Source: APXvYqwyQNKKlbp1KFpOqLrZottLLccve7o7czL3C+EPcMMAL2jRaX42Q0gVCrMWgEYkO3pQB4DQRQ== X-Received: by 2002:a5d:6ccd:: with SMTP id c13mr116466352wrc.4.1564388005500; Mon, 29 Jul 2019 01:13:25 -0700 (PDT) Received: from ?IPv6:2003:cd:ef25:1700:6584:4e87:a805:fef9? (p200300CDEF25170065844E87A805FEF9.dip0.t-ipconnect.de. [2003:cd:ef25:1700:6584:4e87:a805:fef9]) by smtp.googlemail.com with ESMTPSA id n12sm64066270wmc.24.2019.07.29.01.13.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Jul 2019 01:13:24 -0700 (PDT) Subject: Re: Standard uuid vs. custom data type uuid_v1 To: Tomas Vondra Cc: pgsql-performance@lists.postgresql.org References: <2d21f58d-230b-27b9-e48c-dda23a258066@googlemail.com> <20190727134736.xmzqbo2uoigmfkkv@development> From: Ancoron Luciferis Openpgp: preference=signencrypt Autocrypt: addr=ancoron.luciferis@googlemail.com; prefer-encrypt=mutual; keydata= mQINBE3Z7bUBEAC3ZYDTnxOiu0JWJR+6XzFQmJEVncGMehyuE9GBfyaNYnsNKmFITkubNVB9 tN/xgn5FJ9eg0WediTaWXigHNDDOPSNHZGaf1nHu0AQNOgpEyJETtX/A56PXQ82+VwoKCNUN v8+m5CJ8njWZlZMCVA3AcQ1vR2VRR6O0pzEVPDCDMutPytkRl+XrPoPhxMTVEmwM4jfWwmfI NgiOZnsueU78VW8Go1qTN20YdVOdVpbPWfyp8VIGYBNjEEefv5f/l+zt4Z+CQMmvunDUdaKY 85opNIMLqC3dDY0AQG+FpcDLhHWLcuGLmE+Ghiix0G3kX4QX/fH0/2KtVNdfnZtcpq+5rim0 E97PVQe4EixVD/DivpwvNMWqQ2GJlOCx52+J13ZSfe/63XpjL7TNqhR3wMnNuMidLMgLoH5z RtQ2FH9zeYlKgqMUkmwvEHVI+M4oQRE0rzgqx6xHbkPIFEov9ZziQVwCtct+Ja9ho/BXoe/T VIFVOGEp7DG12QSaiLILhzTRUkDXqa+BH9H4V2Hsv77nT2JQ7KO9pM5gb4wq4gtLFo7MMTUq jlqjD2vOm3NY3tg1s7HTggVNgGsWhh9JlNR3v9SRGckKVIIvwDxvzo+Z4iji2SLElWb9BWiH Xku5IEuWGTmC+nOzSvbSxTaC53JcppC5kKXj11N73uw5eR4s3wARAQABtDRBbmNvcm9uIEx1 Y2lmZXJpcyA8YW5jb3Jvbi5sdWNpZmVyaXNAZ29vZ2xlbWFpbC5jb20+iQI4BBMBAgAiBQJN 2e21AhsDBgsJ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e/A7ICU3kLx8BKiUZXhOoTur jG7LftY+nte9Tt8CTQ== Message-ID: Date: Mon, 29 Jul 2019 10:13:23 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190727134736.xmzqbo2uoigmfkkv@development> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 27/07/2019 15:47, Tomas Vondra wrote: > On Thu, Jul 25, 2019 at 11:26:23AM +0200, Ancoron Luciferis wrote: >> Hi, >> >> I have finally found some time to implement a custom data type optimized >> for version 1 UUID's (timestamp, clock sequence, node): >> https://github.com/ancoron/pg-uuid-v1 >> >> Some tests (using a few millions of rows) have shown the following >> results (when used as a primary key): >> >> COPY ... FROM: ~7.8x faster (from file - SSD) >> COPY ... TO  : ~1.5x faster (no where clause, sequential output) >> >> The best thing is that for INSERT's there is a very high chance of >> hitting the B-Tree "fastpath" because of the timestamp being the most >> significant part of the data type, which tends to be increasing. >> >> This also results in much lower "bloat", where the standard "uuid" type >> easily goes beyond 30%, the "uuid_v1" should be between 10 and 20%. >> >> Additionally, it also reveals the massive performance degrade I saw in >> my tests for standard UUID's: >> >> Initial 200 million rows: ~ 80k rows / second >> Additional 17 million rows: ~26k rows / second >> >> ...and the new data type: >> Initial 200 million rows: ~ 623k rows / second >> Additional 17 million rows: ~618k rows / second >> > > Presumably, the new data type is sorted in a way that eliminates/reduces > random I/O against the index. But maybe that's not the case - hard to > say, because the linked results don't say how the data files were > generated ... > Yes, by definition, version 1 UUID's contain the timestamp and when used in applications, that is usually the "current" timestamp when an entry gets prepared for storage. As a result, for testing I've simulated 9 nodes with increasing timestamps, which then results in very similar behavior to sequentially increasing values. The calculation for the above numbers has been based on "\timing" in logged psql test sessions (so the little client overhead is included in calculation). Internal behavior has also been tracked with Linux "perf record" and flamegraph'd. Test data has been generated by the following Java (Maven) project: https://github.com/ancoron/java-uuid-serial ...with arguments: mvn clean test \ -Duuids=217000000 \ # number of UUID's -Duuid.skip.v1=false \ # generate V1 UUID's and serial -Dnodes=9 \ # how many nodes to simulate -Duuid.historic=true \ # enable historic mode (not "now") -Dinterval_days=365 # range of days to generate ...which will generate V1 UUID's into a file "target/uuids.v1.historic.txt" as follows: fb2893ae-9265-11e8-90d8-e03f496e733b fb2c3d2e-9265-11e8-a131-e03f49777cbb fda90b33-9265-11e8-af1b-e03f4957fa73 fdaba343-9265-11e8-b648-e03f49e7fd77 fdad50f3-9265-11e8-b9be-e03f49de7ab7 fdaf73d3-9265-11e8-bdce-e03f49dff937 fdb25a03-9265-11e8-a0d8-e03f49c67ff3 fdb28113-9265-11e8-9c15-e03f4976fd73 fdb2a823-9265-11e8-8273-e03f49d6f3f7 fdb8c2a3-9265-11e8-90d8-e03f496e733b fdbc6c23-9265-11e8-a131-e03f49777cbb 00393a28-9266-11e8-af1b-e03f4957fa73 003bd238-9266-11e8-b648-e03f49e7fd77 003d7fe8-9266-11e8-b9be-e03f49de7ab7 003fa2c8-9266-11e8-bdce-e03f49dff937 004288f8-9266-11e8-a0d8-e03f49c67ff3 0042b008-9266-11e8-9c15-e03f4976fd73 0042d718-9266-11e8-8273-e03f49d6f3f7 0048f198-9266-11e8-90d8-e03f496e733b ...so yes, they are ever-increasing from a timestamp-perspective, which is what I was intending to optimize for in the first iteration. I'll do some more testing with slight time offsets between the nodes to simulate behavior when some nodes generate time a few seconds behind others. I might re-implement the UUID test data generator in Python as that would be far more usable for others. Cheers, Ancoron