Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit34782a3

Browse files
committed
Try to ensure that stats collector's receive buffer size is at least 100KB.
Back-patch of commit8b0b630.Discussion:https://postgr.es/m/22173.1494788088@sss.pgh.pa.us
1 parent98bff29 commit34782a3

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

‎src/backend/postmaster/pgstat.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@
9292
#definePGSTAT_POLL_LOOP_COUNT(PGSTAT_MAX_WAIT_TIME / PGSTAT_RETRY_DELAY)
9393
#definePGSTAT_INQ_LOOP_COUNT(PGSTAT_INQ_INTERVAL / PGSTAT_RETRY_DELAY)
9494

95+
/* Minimum receive buffer size for the collector's socket. */
96+
#definePGSTAT_MIN_RCVBUF(100 * 1024)
97+
9598

9699
/* ----------
97100
* The initial size hints for the hash tables used in the collector.
@@ -537,6 +540,35 @@ pgstat_init(void)
537540
gotostartup_failed;
538541
}
539542

543+
/*
544+
* Try to ensure that the socket's receive buffer is at least
545+
* PGSTAT_MIN_RCVBUF bytes, so that it won't easily overflow and lose
546+
* data. Use of UDP protocol means that we are willing to lose data under
547+
* heavy load, but we don't want it to happen just because of ridiculously
548+
* small default buffer sizes (such as 8KB on older Windows versions).
549+
*/
550+
{
551+
intold_rcvbuf;
552+
intnew_rcvbuf;
553+
ACCEPT_TYPE_ARG3rcvbufsize=sizeof(old_rcvbuf);
554+
555+
if (getsockopt(pgStatSock,SOL_SOCKET,SO_RCVBUF,
556+
(char*)&old_rcvbuf,&rcvbufsize)<0)
557+
{
558+
elog(LOG,"getsockopt(SO_RCVBUF) failed: %m");
559+
/* if we can't get existing size, always try to set it */
560+
old_rcvbuf=0;
561+
}
562+
563+
new_rcvbuf=PGSTAT_MIN_RCVBUF;
564+
if (old_rcvbuf<new_rcvbuf)
565+
{
566+
if (setsockopt(pgStatSock,SOL_SOCKET,SO_RCVBUF,
567+
(char*)&new_rcvbuf,sizeof(new_rcvbuf))<0)
568+
elog(LOG,"setsockopt(SO_RCVBUF) failed: %m");
569+
}
570+
}
571+
540572
pg_freeaddrinfo_all(hints.ai_family,addrs);
541573

542574
return;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp