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

Commitd38bab5

Browse files
committed
pgbench: Increase RLIMIT_NOFILE if necessary
pgbench already had code to check if the soft rlimit is too low for thespecified number of connections. If too low, it errored out, telling the userto increase the limit.However, we can do better: If the hard limit allows, increase the soft limitto be sufficiently for the number of connections.It is common for the soft limit to be considerably lower than the hard limit,due to the danger of soft limits > 1024 breaking programs that use theselect(2), as explained in [1].[1]:https://0pointer.net/blog/file-descriptor-limits.htmlAuthor: Jelte Fennema-Nio <postgres@jeltef.nl>Reviewed-by: Andres Freund <andres@anarazel.de>Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>Discussion:https://postgr.es/m/CAGECzQQh6VSy3KG4pN1d%3Dh9J%3DD1rStFCMR%2Bt7yh_Kwj-g87aLQ%40mail.gmail.com
1 parent9b1cb58 commitd38bab5

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

‎src/bin/pgbench/pgbench.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6815,13 +6815,26 @@ main(int argc, char **argv)
68156815
#ifdefHAVE_GETRLIMIT
68166816
if (getrlimit(RLIMIT_NOFILE,&rlim)==-1)
68176817
pg_fatal("getrlimit failed: %m");
6818-
if (rlim.rlim_cur<nclients+3)
6818+
6819+
if (rlim.rlim_max<nclients+3)
68196820
{
68206821
pg_log_error("need at least %d open files, but system limit is %ld",
6821-
nclients+3, (long)rlim.rlim_cur);
6822+
nclients+3, (long)rlim.rlim_max);
68226823
pg_log_error_hint("Reduce number of clients, or use limit/ulimit to increase the system limit.");
68236824
exit(1);
68246825
}
6826+
6827+
if (rlim.rlim_cur<nclients+3)
6828+
{
6829+
rlim.rlim_cur=nclients+3;
6830+
if (setrlimit(RLIMIT_NOFILE,&rlim)==-1)
6831+
{
6832+
pg_log_error("need at least %d open files, but couldn't raise the limit: %m",
6833+
nclients+3);
6834+
pg_log_error_hint("Reduce number of clients, or use limit/ulimit to increase the system limit.");
6835+
exit(1);
6836+
}
6837+
}
68256838
#endif/* HAVE_GETRLIMIT */
68266839
break;
68276840
case'C':

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp