Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1duPf8-0003G1-FJ for pgsql-committers@arkaria.postgresql.org; Tue, 19 Sep 2017 21:02: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 1duPf7-0007tF-UX for pgsql-committers@arkaria.postgresql.org; Tue, 19 Sep 2017 21:02:33 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1duPf7-0007sy-Co for pgsql-committers@postgresql.org; Tue, 19 Sep 2017 21:02:33 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1duPf4-0000zq-Hq for pgsql-committers@postgresql.org; Tue, 19 Sep 2017 21:02:32 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id AF4B420AEF; Tue, 19 Sep 2017 17:02:29 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Tue, 19 Sep 2017 17:02:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=4RRYJl40QrP1r78aQY RWjJZJsk+1QKaXZdlqsDDKkfs=; b=WeUx3S8fJctcloER7//LdmV2OV6GzfAzrw L7+0Qe/hK/4odJFxZLyrwgE8hUPLehl5QPAZLUDD5B37qnKJZ6cAcWyxu91lxuo6 17flUY3+g8hmSZ8c4qYmLRt7f9FAvMXdetSJ1z5iSCBQAySoMRZIue4J8cmXK4CG vAnr/n6H01GtEHJtHTe2fXCMxPZIwznZcbWymp1n4kWfS2ATmkCt2B8BWg2z7bcq Hoj/j/gBXoItZS9rPP4BWvG8h9o5NHkZai5LQNaP+5hmBEldiIiiUJlafinP6G3T nQnRb+yFHkcjxjqTHOB3LdPYUmtlK/YQza7ppMekFphC4WAbXlpQ== X-ME-Sender: X-Sasl-enc: M41SoiNLrapFs3FNF+5U+UD//bI98LxczW9CM/1OC1kl 1505854949 Received: from intern.anarazel.de (unknown [136.24.76.72]) by mail.messagingengine.com (Postfix) with ESMTPA id 481F1244C7; Tue, 19 Sep 2017 17:02:29 -0400 (EDT) Date: Tue, 19 Sep 2017 14:02:28 -0700 From: Andres Freund To: Tom Lane Cc: pgsql-committers@postgresql.org Subject: Re: pgsql: Speedup pgstat_report_activity by moving mb-aware truncation to Message-ID: <20170919210228.wfo2q6qi3dwunhaf@alap3.anarazel.de> References: <32707.1505852731@sss.pgh.pa.us> <20170919203239.lshzqs4fqnpeo7sg@alap3.anarazel.de> <1506.1505854389@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1506.1505854389@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-committers Precedence: bulk Sender: pgsql-committers-owner@postgresql.org On 2017-09-19 16:53:09 -0400, Tom Lane wrote: > Andres Freund writes: > > On 2017-09-19 16:25:31 -0400, Tom Lane wrote: > >> Looks like you're going to need to not depend on strnlen(). > > > Yup noticed - we have pg_strnlen as a static function in > > src/port/snprintf. I'm tempted to just make that public, rather than > > open code the equivalent? > > No, we should not tie this to whether we're using port/snprintf.c. Oh, I would have moved it to src/common/string.c, sorry for not mentioning that. > Personally, I don't see why this isn't coded more like > > int rawlen = strlen(activity); > > rawlen = Min(rawlen, pgstat_track_activity_query_size - 1); Pure paranoia, but probably not justified paranoia. We take care that there's always a trailing NULL byte, even under concurrent modifications (which exist due to pgstat_get_backend_current_activity()). I'll just change things so that the pnstrdup() happens first, and then do a plain strlen() on that. Same paranoia, less cost. > It seems likely to me that strlen() is going to be optimized a lot > harder than strnlen() on most platforms, so that this way would win > not only for strings up to pgstat_track_activity_query_size but for > strings some way beyond that. Yes, for really really long queries > the strnlen way would win, but that's optimizing for the wrong case IMO. I wasn't thinking of optimizing this - and I've a hard time seing a case where even the naive snprintf pg_strnlen(), or a plain strlen() would be relevant performancewise. Greetings, Andres Freund -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers