Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZXAaO-0001nu-SA for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Sep 2015 16:08:32 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZXAaN-0006bd-Kg for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Sep 2015 16:08: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_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZXAZ2-00058s-51 for pgsql-hackers@postgresql.org; Wed, 02 Sep 2015 16:07:08 +0000 Received: from mail-wi0-f180.google.com ([209.85.212.180]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZXAYt-0002IQ-Mu for pgsql-hackers@postgresql.org; Wed, 02 Sep 2015 16:07:07 +0000 Received: by wicge5 with SMTP id ge5so46302059wic.0 for ; Wed, 02 Sep 2015 09:06:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=H7MbWQdqqiCAnaYu7AaDOHnPfRZ3xefiOmTrxtrAk+0=; b=f/KmP9658eBmMSs0DNvF2NyQnvxdvyE1QCjb/iBveiK778v1COJ6ZoGf8E4TG/sBhb YZLhiaZRTfWLa6YV8d2ksFEpBRoDQOEuZYHUFWYYTjl+NE0rLT+2NzYHqpNBmBspe555 Jfsziw4XQKuBy3SpBlYoD84jgmsGlNz0kQiWoTbpcDt1xc2+ycXQEmqYSFmaVQ3H8/qn ZdX/eTCcystAajvVMPTt+rc9mNdSc9y+nHQD9sL+KydBTuv2Ua5gAiB94ZIiA0Yu0bzP jOmnHn/od2U1cl2stZstZekEdxCZe0vDWqGYlFaMqKNiXjFuAyMA9lRCAA3wQ41awomp iD3g== X-Gm-Message-State: ALoCoQnnSy5MSzkIBkSKJsYTW/9SdJ6eL5jMzmLZDuKwundoX0OMa8/AAi7NqVTRpEd+OP09aFUL5IvMedhP4iYSdfMZnm5PXv0fJ7fFnABEmjQN3tQBRRFfziPceVwhffxZmzRKB7z9Vckhy9m7V/GRuKyWry4f8DEOGbnGShZ8GXcL3nzJRiy5RufL48Gl+4KXHGvWTsWE X-Received: by 10.180.76.231 with SMTP id n7mr4896522wiw.65.1441210017304; Wed, 02 Sep 2015 09:06:57 -0700 (PDT) Received: from [10.137.2.12] (ip-78-45-216-26.net.upcbroadband.cz. [78.45.216.26]) by smtp.gmail.com with ESMTPSA id pu6sm33107313wjc.34.2015.09.02.09.06.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Sep 2015 09:06:56 -0700 (PDT) Message-ID: <55E71E9E.4090403@2ndquadrant.com> Date: Wed, 02 Sep 2015 18:06:54 +0200 From: Tomas Vondra User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: pgsql-hackers@postgresql.org Subject: Re: Allow a per-tablespace effective_io_concurrency setting References: <20141206130828.GA1314@momjian.us> <20141209204337.GC24488@momjian.us> <55AA2469.20306@dalibo.com> <55AA27C3.7060009@dalibo.com> <20150902135351.GA5286@alap3.anarazel.de> In-Reply-To: <20150902135351.GA5286@alap3.anarazel.de> Content-Type: text/plain; charset=windows-1252; format=flowed 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 Hi On 09/02/2015 03:53 PM, Andres Freund wrote: > > Hi, > > On 2015-07-18 12:17:39 +0200, Julien Rouhaud wrote: >> I didn't know that the thread must exists on -hackers to be able to add >> a commitfest entry, so I transfer the thread here. > > Please, in the future, also update the title of the thread to something > fitting. > >> @@ -539,6 +541,9 @@ ExecInitBitmapHeapScan(BitmapHeapScan *node, EState *estate, int eflags) >> { >> BitmapHeapScanState *scanstate; >> Relation currentRelation; >> +#ifdef USE_PREFETCH >> + int new_io_concurrency; >> +#endif >> >> /* check for unsupported flags */ >> Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK))); >> @@ -598,6 +603,25 @@ ExecInitBitmapHeapScan(BitmapHeapScan *node, EState *estate, int eflags) >> */ >> currentRelation = ExecOpenScanRelation(estate, node->scan.scanrelid, eflags); >> >> +#ifdef USE_PREFETCH >> + /* check if the effective_io_concurrency has been overloaded for the >> + * tablespace storing the relation and compute the target_prefetch_pages, >> + * or just get the current target_prefetch_pages >> + */ >> + new_io_concurrency = get_tablespace_io_concurrency( >> + currentRelation->rd_rel->reltablespace); >> + >> + >> + scanstate->target_prefetch_pages = target_prefetch_pages; >> + >> + if (new_io_concurrency != effective_io_concurrency) >> + { >> + double prefetch_pages; >> + if (compute_io_concurrency(new_io_concurrency, &prefetch_pages)) >> + scanstate->target_prefetch_pages = rint(prefetch_pages); >> + } >> +#endif > > Maybe it's just me - but imo there should be as few USE_PREFETCH > dependant places in the code as possible. It'll just be 0 when not > supported, that's fine? It's not just you. Dealing with code with plenty of ifdefs is annoying - it compiles just fine most of the time, until you compile it with some rare configuration. Then it either starts producing strange warnings or the compilation fails entirely. It might make a tiny difference on builds without prefetching support because of code size, but realistically I think it's noise. > Especially changing the size of externally visible structs depending > ona configure detected ifdef seems wrong to me. +100 to that >> + /*---------- >> + * The user-visible GUC parameter is the number of drives (spindles), >> + * which we need to translate to a number-of-pages-to-prefetch target. >> + * The target value is stashed in *extra and then assigned to the actual >> + * variable by assign_effective_io_concurrency. >> + * >> + * The expected number of prefetch pages needed to keep N drives busy is: >> + * >> + * drives | I/O requests >> + * -------+---------------- >> + * 1 | 1 >> + * 2 | 2/1 + 2/2 = 3 >> + * 3 | 3/1 + 3/2 + 3/3 = 5 1/2 >> + * 4 | 4/1 + 4/2 + 4/3 + 4/4 = 8 1/3 >> + * n | n * H(n) > > I know you just moved this code. But: I don't buy this formula. Like at > all. Doesn't queuing and reordering entirely invalidate the logic here? Well, even the comment right next after the formula says that: * Experimental results show that both of these formulas aren't * aggressiveenough, but we don't really have any better proposals. That's the reason why users generally either use 0 or some rather high value (16 or 32 are the most common values see). The problem is that we don't really care about the number of spindles (and not just because SSDs don't have them at all), but about the target queue length per device. Spinning rust uses TCQ/NCQ to optimize the head movement, SSDs are parallel by nature (stacking multiple chips with separate channels). I doubt we can really improve the formula, except maybe for saying "we want 16 requests per device" and multiplying the number by that. We don't really have the necessary introspection to determine better values (and it's not really possible, because the devices may be hidden behind a RAID controller (or a SAN). So we can't really do much. Maybe the best thing we can do is just completely abandon the "number of spindles" idea, and just say "number of I/O requests to prefetch". Possibly with an explanation of how to estimate it (devices * queue length). regards -- Tomas Vondra http://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