Set higher open files limit in init script#8819
Conversation
There was a problem hiding this comment.
I expect these to fail (i.e. not take effect) unless one of /etc/security/limits.conf or /etc/systemd/user.conf or /etc/systemd/system.conf has a value higher than this allowed for the Trino user.
I'll try and verify in a VM.
EDIT: Correction. It's /etc/security/limits.conf and /etc/systemd/user.conf. They need to have higher values to allow ulimit to succeed otherwise it fails with an error. To check values you can use sysctl -a | grep 'files.nr_open'.
There was a problem hiding this comment.
I think root can execute them regardless of what's in /etc/security/limits.conf.
There was a problem hiding this comment.
BTW I checked CentOS packages and found only one that defines limits in /etc/security/limits.d, which is libvma. But it's also the single package that has a SysV init script, not a SystemD unit file.
There was a problem hiding this comment.
This only works because CentOS (since 7) uses SystemD and systemd sets the default hard limit to a high enough value that your command doesn't fail. This is not an assumption that is safe to make.
See https://www.freedesktop.org/software/systemd/man/systemd-system.conf.html#DefaultLimitCPU=.
And since we are setting the values we should also be setting nproc too either way.
My suggestion is to test whether we get a meaningful error message at startup.
We don't want the default state to be a situation where out of the box it's not visible why Trino fails to startup.
There was a problem hiding this comment.
Try this:
# CentOS 7
[root@centos hashhar]# sysctl -a | grep 'fs.nr_open'
fs.nr_open = 1048576
[root@centos hashhar]# ulimit -Hn 1048577
bash: ulimit: open files: cannot modify limit: Operation not permitted
[root@centos hashhar]# sysctl -w fs.nr_open=1048579
[root@centos hashhar]# ulimit -Hn 1048579
[root@centos hashhar]# ulimit -Hn
1048579
Also the soft limit needs to be increased too to actually allow any running process to make use of the increased hard limit. (EDIT: I see you set both).
I found https://unix.stackexchange.com/questions/447583/ulimit-vs-file-max very helpful.
There was a problem hiding this comment.
nproc at some point was dropped from the docs PR I linked. I'm not sure why, none of the comments there refer to that part. So we need an agreement for the right value and also put it in docs. Sounds like a separate issue.
I'm not sure what's the ask here. To set these to the least of 131072 and current fs.nr_open?
There was a problem hiding this comment.
I've made changes here to only raise the limit, never lower it, and never raise it above fs.nr_open.
|
I'm starting to think the better solution is to only verify the ulimits are not insanely low (e.g. maybe values from The correct place to do this seems to be the cc: @trinodb/maintainers Please chime in with opinions. For context the issue is that most OSs default ulimits are very low (1024/4096) which can cause the ServiceLoader to fail but silently swallow |
|
I think we should not modify the system, but instead in the launcher verify everything is sufficient and if not - report error and fail start up. We dont automatically install / upgrade / downgrade Python or Java either. And that verification should be compatible so that it works with tarball, rpm and on containers and is independent of the Linux distro. This change downgrades the ulimit for systems that might have higher values for some good reason .. |
db05794 to
e2a446c
Compare
@mosabua I've made changes here to only raise the limit, never lower it, and never raise it above |
7741416 to
a478157
Compare
|
Looks good now.. ultimately I still think this should go into the validation in the launcher script. Could be a follow up task and then we remove this here again. |
|
cc @losipiuk |
There was a problem hiding this comment.
nit: When the current_limit is gt what we want, we should not invoke ulimit at all.
Avoid calling ulimit unnecessarily, as it could, in theory, fail.
There was a problem hiding this comment.
We'd have to either:
- conditionally call
ulimit -Hnand always callulimit -Sn - also read the current value of
ulimit -Sand conditionally call bothulimit -Hnandulimit -Sn - always call
ulimit -n- I just checked the manual, and when neither-Hnor-Sis specified, it sets both limits.
To keep things simple, I'd assume ulimit is declarative and always call it. It's a bash built-in, so we don't even start another process here. I changed this to be a single call.
a478157 to
d820ca2
Compare
hashhar
left a comment
There was a problem hiding this comment.
@findepi i dont agree about doing this in RPM. This problem is general and affects every deployment mechanism like tarball, RPM and Docker.
I think the better solution is for the launcher to verify the limits are at-least some sane value.
|
Turns out we already have validation for this (thanks to Piotr for pointing to it) in place at I think we can close this PR now. |
The added value of the change is that RPM 'just works' instead of having user to update things. I don't feel strongly about this though. |
hashhar
left a comment
There was a problem hiding this comment.
Looks good % comment + a justification in commit msg.
0d1a71d to
e7342b8
Compare
Make sure the init script installed by the RPM package is setting the maximum number of open files as recommended in the documentation. If the value is too low, a warning would be logged. But if there's a large number of connectors present, the server would fail to start. Any limits set in `/etc/security/limits.conf` would override these defaults.
e7342b8 to
5adb595
Compare
#5066 added mention of
ulimitto Trino's requirements. These recommended values should be used by default when installing Trino using the RPM package.The reason to set these in the init script, not in a
/etc/security/limits.d/99-trino.conffile is that it's a simpler change and at some point in time Trino might migrate from a SysV script to a SystemD unit file, which would ignore limits from/etc/securitysince those are only used by PAM (thepam_limits.somodule).Defining these limits before sourcing the
env.shfile allows users to adjust them further if required.