Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

100% CPU when the _SC_OPEN_MAX is a big number #147

Closed
whywhy36 opened this issue Apr 4, 2024 · 3 comments
Closed

100% CPU when the _SC_OPEN_MAX is a big number #147

whywhy36 opened this issue Apr 4, 2024 · 3 comments

Comments

@whywhy36
Copy link

whywhy36 commented Apr 4, 2024

We observed that it took very long time to open a JetBrains terminal in the new Amazon AL2023 VM. The CPU usage is 100% for process PtyProcess Reap (the full name of that thread is PtyProcess Reaper for [/bin/bash, --rcfile, /home/owner/.cache/JetBrains/RemoteDev/dist/ideaIU-2022.3.2/plugins/terminal/jediterm-bash.in, -i]).

strace -p PID indicates that JNA call was trying to close a huge range of FDs, which should be defined in exe_pty.c. If _SC_OPEN_MAX holds a big value, the loop would degrade the performance.

The similar issue has been reported in other projects, such as

Wondering should we apply a similar patch as netdata/netdata#14213 to the impacted codes.

@whywhy36
Copy link
Author

whywhy36 commented Apr 4, 2024

The issue should also be fixed by PR #124

@morgwai
Copy link

morgwai commented Jun 16, 2024

For Linux users affected by this problem and looking for a workaround until #149 is released:
Decreasing the limits of maximum open files mitigates the problem. See this stackExchange post explaining how to set global and per process limits.
For me setting fs.file-max=10485760 in sysctl and * hard nofile 1048576 in limits.conf was sufficiently low to make it work.

@segrey
Copy link
Collaborator

segrey commented Jun 17, 2024

Thank you for reporting and sorry for the delay. Should be fixed by 04685d8 and available since pty4j version 0.12.27.

@segrey segrey closed this as completed Jun 17, 2024
adangel added a commit to adangel/cdt that referenced this issue Jun 22, 2024
…ipse-cdt#855)

When _SC_OPEN_MAX (max nr of open files limit per process) is a very
big number, then closing all possible file handles can take a while.
This change first tries to use the syscall close_range() if available,
falling back to use /proc/self/fd to close only open file handles,
and lastly falling back to the old way of closing all possible handles
one after another.
In general, the first or second approach should be available
which speeds up the pty spawning.

Refs JetBrains/pty4j#147
Copied from JetBrains/pty4j@04685d8
(which is EPL 1.0)

Co-authored-by: Sergey Simonchik <sergey.simonchik@jetbrains.com>
adangel added a commit to adangel/cdt that referenced this issue Jun 22, 2024
…ipse-cdt#835)

When _SC_OPEN_MAX (max nr of open files limit per process) is a very
big number, then closing all possible file handles can take a while.
This change first tries to use the syscall close_range() if available,
falling back to use /proc/self/fd to close only open file handles,
and lastly falling back to the old way of closing all possible handles
one after another.
In general, the first or second approach should be available
which speeds up the pty spawning.

Refs JetBrains/pty4j#147
Copied from JetBrains/pty4j@04685d8
(which is EPL 1.0)

Co-authored-by: Sergey Simonchik <sergey.simonchik@jetbrains.com>
jonahgraham pushed a commit to eclipse-cdt/cdt that referenced this issue Jun 23, 2024
When _SC_OPEN_MAX (max nr of open files limit per process) is a very
big number, then closing all possible file handles can take a while.
This change first tries to use the syscall close_range() if available,
falling back to use /proc/self/fd to close only open file handles,
and lastly falling back to the old way of closing all possible handles
one after another.
In general, the first or second approach should be available
which speeds up the pty spawning.

Refs JetBrains/pty4j#147
Copied from JetBrains/pty4j@04685d8
(which is EPL 1.0)

Co-authored-by: Sergey Simonchik <sergey.simonchik@jetbrains.com>
jonahgraham pushed a commit to jonahgraham/cdt that referenced this issue Jun 27, 2024
…ipse-cdt#835)

_This commit adds to eclipse-cdt#840 7bd8d52 to apply the same fix to
another place that does the same operation on all fds._

When _SC_OPEN_MAX (max nr of open files limit per process) is a very
big number, then closing all possible file handles can take a while.
This change first tries to use the syscall close_range() if available,
falling back to use /proc/self/fd to close only open file handles,
and lastly falling back to the old way of closing all possible handles
one after another.
In general, the first or second approach should be available
which speeds up the pty spawning.

Refs JetBrains/pty4j#147
Copied from JetBrains/pty4j@04685d8
(which is EPL 1.0)

Co-authored-by: Sergey Simonchik <sergey.simonchik@jetbrains.com>
jonahgraham pushed a commit to eclipse-cdt/cdt that referenced this issue Jun 28, 2024
_This commit adds to #840 7bd8d52 to apply the same fix to
another place that does the same operation on all fds._

When _SC_OPEN_MAX (max nr of open files limit per process) is a very
big number, then closing all possible file handles can take a while.
This change first tries to use the syscall close_range() if available,
falling back to use /proc/self/fd to close only open file handles,
and lastly falling back to the old way of closing all possible handles
one after another.
In general, the first or second approach should be available
which speeds up the pty spawning.

Refs JetBrains/pty4j#147
Copied from JetBrains/pty4j@04685d8
(which is EPL 1.0)

Co-authored-by: Sergey Simonchik <sergey.simonchik@jetbrains.com>
jonahgraham pushed a commit to jonahgraham/cdt that referenced this issue Jun 28, 2024
…ipse-cdt#835)

When _SC_OPEN_MAX (max nr of open files limit per process) is a very
big number, then closing all possible file handles can take a while.
This change first tries to use the syscall close_range() if available,
falling back to use /proc/self/fd to close only open file handles,
and lastly falling back to the old way of closing all possible handles
one after another.
In general, the first or second approach should be available
which speeds up the pty spawning.

Refs JetBrains/pty4j#147
Copied from JetBrains/pty4j@04685d8
(which is EPL 1.0)

Co-authored-by: Sergey Simonchik <sergey.simonchik@jetbrains.com>
(cherry picked from commit 7bd8d52)
jonahgraham pushed a commit to jonahgraham/cdt that referenced this issue Jun 28, 2024
…ipse-cdt#835)

_This commit adds to eclipse-cdt#840 7bd8d52 to apply the same fix to
another place that does the same operation on all fds._

When _SC_OPEN_MAX (max nr of open files limit per process) is a very
big number, then closing all possible file handles can take a while.
This change first tries to use the syscall close_range() if available,
falling back to use /proc/self/fd to close only open file handles,
and lastly falling back to the old way of closing all possible handles
one after another.
In general, the first or second approach should be available
which speeds up the pty spawning.

Refs JetBrains/pty4j#147
Copied from JetBrains/pty4j@04685d8
(which is EPL 1.0)

Co-authored-by: Sergey Simonchik <sergey.simonchik@jetbrains.com>
(cherry picked from commit 3875408)
jonahgraham pushed a commit to jonahgraham/cdt that referenced this issue Jun 28, 2024
…ipse-cdt#835)

When _SC_OPEN_MAX (max nr of open files limit per process) is a very
big number, then closing all possible file handles can take a while.
This change first tries to use the syscall close_range() if available,
falling back to use /proc/self/fd to close only open file handles,
and lastly falling back to the old way of closing all possible handles
one after another.
In general, the first or second approach should be available
which speeds up the pty spawning.

Refs JetBrains/pty4j#147
Copied from JetBrains/pty4j@04685d8
(which is EPL 1.0)

Co-authored-by: Sergey Simonchik <sergey.simonchik@jetbrains.com>
cherry picked and squashed from commits:
- 7bd8d52
- 24d9bd1
- 3875408
jonahgraham pushed a commit to jonahgraham/cdt that referenced this issue Jun 29, 2024
…ipse-cdt#835)

When _SC_OPEN_MAX (max nr of open files limit per process) is a very
big number, then closing all possible file handles can take a while.
This change first tries to use the syscall close_range() if available,
falling back to use /proc/self/fd to close only open file handles,
and lastly falling back to the old way of closing all possible handles
one after another.
In general, the first or second approach should be available
which speeds up the pty spawning.

Refs JetBrains/pty4j#147
Copied from JetBrains/pty4j@04685d8
(which is EPL 1.0)

Co-authored-by: Sergey Simonchik <sergey.simonchik@jetbrains.com>
cherry picked and squashed from commits:
- 7bd8d52
- 24d9bd1
- 3875408
jonahgraham pushed a commit to eclipse-cdt/cdt that referenced this issue Jun 29, 2024
When _SC_OPEN_MAX (max nr of open files limit per process) is a very
big number, then closing all possible file handles can take a while.
This change first tries to use the syscall close_range() if available,
falling back to use /proc/self/fd to close only open file handles,
and lastly falling back to the old way of closing all possible handles
one after another.
In general, the first or second approach should be available
which speeds up the pty spawning.

Refs JetBrains/pty4j#147
Copied from JetBrains/pty4j@04685d8
(which is EPL 1.0)

Co-authored-by: Sergey Simonchik <sergey.simonchik@jetbrains.com>
cherry picked and squashed from commits:
- 7bd8d52
- 24d9bd1
- 3875408
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants