Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tnMPt-004ZsJ-0m for pgsql-hackers@arkaria.postgresql.org; Wed, 26 Feb 2025 18:45:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tnMPr-00BRll-V9 for pgsql-hackers@arkaria.postgresql.org; Wed, 26 Feb 2025 18:45:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tnMPr-00BRif-Je for pgsql-hackers@lists.postgresql.org; Wed, 26 Feb 2025 18:45:55 +0000 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tnMPo-000FNc-1b for pgsql-hackers@postgresql.org; Wed, 26 Feb 2025 18:45:55 +0000 Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5e4bed34bccso31386a12.3 for ; Wed, 26 Feb 2025 10:45:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740595552; x=1741200352; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=r5l93rgeOMZ8EQEsOeCFmw43LLfLHR5MjDFdogtULhk=; b=ehl/Ex6XilyVRVGiXvvx5fcWT8m6s5O2Nzu4u/Z1J2En4SPoehmnNPL7IdXvvNkTd8 /4wFg4VZlxmmAzuEImOqOrTr133iwfY6kXFfm+ar5Kk0EUN0CP9iK9DNtzqZGuxNt3iu k4XiPsSkzkXfkUq0b86DRvQXAcwXcgzAs7YnfciRIxCNO/9ne8q6R+v8vOrQ48DArGqn nAiehkXeoxrtxNSOAHD2hFhfRZCiLoKze4mgfjhFB9eJ3BUm3+2jC74Sc33COWV23v0u veIAALJOWLCQMiSByDnicnT41mAGMQ40WgBSlc/A9v6NmruMQhSxwNGwtZvkxQlAteS0 aAmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740595552; x=1741200352; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r5l93rgeOMZ8EQEsOeCFmw43LLfLHR5MjDFdogtULhk=; b=O7g4SlDR7dAJq9UEvBNtXF9lddYRoyCgEDoLgtn6gy6rL6t7ix9HHqdiSShtrsHfYw 1uWSJPHhqgrkyNuy7DJ37v+5jqIj6KLSMCauzl+LEm6aQRBq3jp/1l74On/EpcWElB0+ JkjNnaUSiVmJ9rCM0ncArBlB/Q5uVzC2MwxYz98oCpD7aGZ5OWE0V6UDcje5wKVIn21j S+j2630To8Z/uVG4T9MScfEvbp+2QBK6g3MmvijNVoGuVXkbEjhCA6VN/KU1Lg6QXZek AOmZ6a9Ivxb5rRpkQZeEB8abH8XCz9G/0rtQsxdbzr5gp23wxKqFgZQjkli4EIRhphyB sUQQ== X-Forwarded-Encrypted: i=1; AJvYcCUDkNmdT1JcdqHLqpabsUc+PyPjkrCB0Vi5c5jE6c53DJJElAIyIesCXw4bEg3Uk5WE5rWgJz3HwUBLpI2F@postgresql.org X-Gm-Message-State: AOJu0YxQV0Ygkgv/PfYfzWX19c1j24xq4jStBw4hRRFzgDz5Pw55LlLg DJrSMBHoqDZ+rcmzjSv8Y3RD+DRIhUsOXtwSoc77elYNhTvVwSj45aq3GDrbnaY0XB6IrPu+WRq Q/A1r1EPiy7pp9EtQZDMCoHGyUJU= X-Gm-Gg: ASbGncscbZeB3ubK0TJN2YeUvfgADRFjN/XixxQrghC6sKh5VuROCLoRmba9jZEiBj0 cVXxx8kEm//mAxFnsKb3Zwx3sGx9REriYseWEc+Q3gbcu2DgbqSIurwk2DzKL+eFaUiDk2o1cdT 00+CYEXvBLD50iqbIbIYQIvJKkw/2QYC+8aE9dGqpbuQ== X-Google-Smtp-Source: AGHT+IE0FmxoUmznq4yD/dY48ZJJJGWADfuhkoqzvqBdUkALekI0Xk1SDjQlBnlQRKJXoXiWQiCKp4+FqCzhkbpHeLw= X-Received: by 2002:a05:6402:35c9:b0:5dc:1f35:563 with SMTP id 4fb4d7f45d1cf-5e4a0d45ce0mr6302418a12.7.1740595551206; Wed, 26 Feb 2025 10:45:51 -0800 (PST) MIME-Version: 1.0 References: <65fe2d68-a214-40f0-80a8-56ca7323ad5c@oss.nttdata.com> In-Reply-To: From: Melanie Plageman Date: Wed, 26 Feb 2025 13:45:39 -0500 X-Gm-Features: AQ5f1Jqo-GLPRFNF8Hx3W0KRgY34ORijSRBsXQPProtlFB6PLoPuDS_Nwzyf4g4 Message-ID: Subject: Re: Log connection establishment timings To: Bertrand Drouvot Cc: Fujii Masao , Guillaume Lelarge , Pg Hackers , Daniel Gustafsson , andrey.chudnovskiy@microsoft.com, Jelte Fennema-Nio , Jacob Champion Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Thanks for the continued review! On Wed, Feb 26, 2025 at 2:41=E2=80=AFAM Bertrand Drouvot wrote: > > On Wed, Feb 26, 2025 at 01:46:19PM +0900, Fujii Masao wrote: > > > > With the current patch, when log_connections is enabled, the connection= time is always > > captured, and which might introduce performance overhead. No? Some user= s who enable > > log_connections may not want this extra detail and want to avoid such o= verhead. > > So, would it make sense to extend log_connections with a new option lik= e "timing" and > > log the connection time only when "timing" is specified? > > +1, I also think it's a good idea to let users decide if they want the ti= ming > measurement overhead (and it's common practice with track_io_timing, > track_wal_io_timing, the newly track_cost_delay_timing for example) It seems to me like the extra timing collected and the one additional log message isn't enough overhead to justify its own guc (for now). > > Including the PID seems unnecessary since it's already available via lo= g_line_prefix with %p? > > Yeah, we would get things like: > > [1111539] LOG: connection received: host=3D[local] > [1111539] LOG: connection authenticated: user=3D"postgres" method=3Dtrus= t (/home/postgres/postgresql/pg_installed/pg18/data/pg_hba.conf:117) > [1111539] LOG: connection authorized: user=3Dpostgres database=3Dpostgre= s application_name=3Dpsql > [1111539] LOG: backend ready for query. pid=3D1111539. socket=3D9. conne= ction establishment times (ms): total: 2, fork: 0, authentication: 0 > > I also wonder if "backend ready for query" is worth it. Maybe something l= ike: > > 2025-02-26 06:44:23.265 UTC [1111539] LOG: connection establishment time= s (ms): total: 2, fork: 0, authentication: 0 > > would be good enough? Yes, thank you. v5 attached in [1] changes the wording as you recommend.. > +typedef struct ConnectionTiming > +{ > + instr_time fork_duration; > + instr_time auth_duration; > +} ConnectionTiming; > > As it's all about instr_time, I wonder if we could use an enum + array in= stead. > That's probably just a matter of taste but that sounds more flexible to e= xtend > (should we want to add more timing in the future). I think we can change it later if we add many more. For now I prefer the clarity of accessing members by name. Especially because we don't have any code yet that loops through all of them or anything like that. > +ConnectionTiming conn_timing =3D {0}; > > There is no padding in ConnectionTiming and anyway we just access its fie= lds > so that's ok to initialize that way. Yes, this properly zero initializes the struct. In fact it shouldn't be needed since a global like this should be zero initialized. But all of the globals defined above conn_timing zero initialize themselves, so I thought I would be consistent with them. > Add a few words in the log_connections GUC doc? (anyway we will have to i= f > Fujii-san idea above about the timing is implemented) I forgot to do this in v5 attached in [1]. Let me go ahead and do this next= . > + /* Calculate total fork duration in child backend for log= ging */ > + if (child_type =3D=3D B_BACKEND) > + { > + INSTR_TIME_SET_CURRENT(conn_timing.fork_duration)= ; > + INSTR_TIME_SUBTRACT(conn_timing.fork_duration, > + ((Backend= StartupData *) startup_data)->fork_time); > + } > + > /* Close the postmaster's sockets */ > ClosePostmasterPorts(child_type =3D=3D B_LOGGER); > > @@ -618,6 +630,14 @@ SubPostmasterMain(int argc, char *argv[]) > /* Read in the variables file */ > read_backend_variables(argv[2], &startup_data, &startup_data_len)= ; > > + /* Calculate total fork duration in child backend for logging */ > + if (child_type =3D=3D B_BACKEND) > + { > + INSTR_TIME_SET_CURRENT(conn_timing.fork_duration); > + INSTR_TIME_SUBTRACT(conn_timing.fork_duration, > + ((BackendStartupData *) startup_data)->fo= rk_time); > + } > > worth to add a helper function to avoid code duplication? I've added INSTR_TIME_GET_DURATION_SINCE(start_time). Which I like because it seems generally useful. It does not however cut down on LOC, so I'm somewhat on the fence. - Melanie [1] https://www.postgresql.org/message-id/CAAKRu_Y9sgZAWCiQoHtpwx6Mv28fBGav= 5ztrWyeSrx%2BB%3DACN6g%40mail.gmail.com