Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d38bab5

Browse files
committed
pgbench: Increase RLIMIT_NOFILE if necessary
pgbench already had code to check if the soft rlimit is too low for the specified number of connections. If too low, it errored out, telling the user to increase the limit. However, we can do better: If the hard limit allows, increase the soft limit to 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 the select(2), as explained in [1]. [1]: https://0pointer.net/blog/file-descriptor-limits.html Author: 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 parent 9b1cb58 commit d38bab5

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/bin/pgbench/pgbench.c

+15-2
Original file line numberDiff line numberDiff line change
@@ -6815,13 +6815,26 @@ main(int argc, char **argv)
68156815
#ifdef HAVE_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)