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 1jvjKc-0000lI-Jv for pgsql-general@arkaria.postgresql.org; Wed, 15 Jul 2020 15:28:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jvjKb-0000np-HI for pgsql-general@arkaria.postgresql.org; Wed, 15 Jul 2020 15:28:25 +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 1jvjKb-0000ni-81 for pgsql-general@lists.postgresql.org; Wed, 15 Jul 2020 15:28:25 +0000 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jvjKX-0006YD-OM for pgsql-general@lists.postgresql.org; Wed, 15 Jul 2020 15:28:24 +0000 Received: by mail-ot1-x341.google.com with SMTP id 5so1743019oty.11 for ; Wed, 15 Jul 2020 08:28:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=nPCaLlKyKB9zd9EdY4RFWEX4cPNANB1t4lH4pxZVWZI=; b=IlcV9LmImksUbZoWnNmlvUi/3Fzpn001pKf39il0PFLjwVNyouqQIn/eGCd+cqenpH oPboS0KDHNVix32U9UXFMSh0QHFTJud/x3lc8pzkko4Gsm+16MBpM1hf8RjiAtL6E38u FGXHrj5GfGX5YKokA7oQ3a12y3HtugwnoB9pOXlTZivKIRD5ZIrXD411J0fotTe+6gaZ TECKlMyc3XTR5YX1H0w64OvxZ6iH0yvclgEHjkQcoobITlTQQ+P+b8XHYKhZL7cwzBu0 IJXt3lOGLQS+11MUU9Fm+cpk6zpSBpI4J1kP1hWGttnW+fr3IQiElMM2MQjGVTFHgO0G E2aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=nPCaLlKyKB9zd9EdY4RFWEX4cPNANB1t4lH4pxZVWZI=; b=lzIPPK4Q2IzUgbDG9gbB4yGugswEmQzljEHa1aoIxFaU2vN3EGw5Rv2kaAyNIAS6zs 5V4xkCa63+J8r1ZwjC5x6z44hwgItm2ravtNxZrDFgk9xqwKOXXvaxRnLM5DyoFnmTqk rNRbc3Rhqzx0sQHYorrISgr1eaFxUA/pJAVHomc0B8A+wutFj5LxaVhhX58sxrfSEZiu O/XgAgCLI/+wP+oHBeDSoGwIi1UshYnXR9qK/CsTdMyvp3TPYqFODo4QaYc0bUhuAFzV qpqFrjUPiAVAHLRWC8RG4DGxCLTMPW04Lr/PqDZj08mHDkZywFUrXLT2uRTMI/ehRHkk dy9w== X-Gm-Message-State: AOAM53315+gIS0QxTMl3SClONOZFXXEguDswrDx7X7b7L316mSwyvS8L WmCrQmfldHOeuLxEH+s8PdW5ZHWp4AU= X-Google-Smtp-Source: ABdhPJwSTDr4ueYxS6xAm82XLKHouw0gbgeEvXgVG7gZqJk2tzu1jmFPmfEJvtS3gw0KLAvZSrUdRA== X-Received: by 2002:a05:6830:817:: with SMTP id r23mr159478ots.29.1594826899698; Wed, 15 Jul 2020 08:28:19 -0700 (PDT) Received: from [192.168.1.10] (ip70-186-126-197.no.no.cox.net. [70.186.126.197]) by smtp.googlemail.com with ESMTPSA id t16sm478558oou.28.2020.07.15.08.28.18 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 15 Jul 2020 08:28:19 -0700 (PDT) Subject: Re: 2 million queries against a table To: pgsql-general@lists.postgresql.org References: From: Ron Message-ID: Date: Wed, 15 Jul 2020 10:28:18 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 7/15/20 10:10 AM, Adam Sanchez wrote: > Hi > > I need to run 2 million queries against a three columns table t > (s,p,o) which size is 10 billions rows. The data type of each column > is string. The server has 512G RAM, 32 cores and 14T SSD (RAID 0) > > Only two types of queries: > > select s p o from t where s = param > select s p o from t where o = param What's the index cardinality of "s" and "o" (about how many records per key)? What kind of indexes do you have on them?  Is the table clustered on one of the keys? What version of Postgresql? > If I store the table in a Postgresql database takes 6 hours using a > Java ThreadPoolExecutor. How many threads? What values of: shared_buffers temp_buffers work_mem > Do you think Postgresql itself can speed up the queries processing > even more? What would be the best strategy? 2M queries in 6 hours is 93 queries/second.  Over 32 cores, that's only three per second.   Not very much. > These are my ideas: > > 1. Use Spark to launch queries against the table (extracted from > Postgresql) loaded in a dataframe > 2. Use PG-Strom, an extension module of PostgreSQL with GPU support > and launch the queries against the table. > > > Any suggestion will be appreciated IO is -- as usual -- the bottleneck, followed closely by cache efficiency.  Are you issuing the queries in a random order, or sequentially by key (which would enhance cache efficiency)? -- Angular momentum makes the world go 'round.