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

Millon of close syscalls on lxd container when run a simple command as nice #406

Closed
cduelo opened this issue Sep 27, 2017 · 3 comments
Closed
Assignees

Comments

@cduelo
Copy link

cduelo commented Sep 27, 2017

I noticed a very different performance running commands on lxd container so, simple as sh.nice()

Host

    $ time python -c "import sh; sh.nice()"
    real	0m0.077s
    user	0m0.052s
    sys	0m0.012s

Container

    $ time python -c "import sh; sh.nice()"
    real	0m0.215s
    user	0m0.088s
    sys	0m0.120s

My next step was use strace which says that the container version call 1048796 times the syscall close!! The majority of the times it returns EBADF (Bad file descriptor).

Here is what I have done, any idea whats happening?
I do not know if it is a sh module issue or not but it is happening only here..

    $ uname -a
    Linux cmp-1 4.4.0-96-generic #119-Ubuntu SMP Tue Sep 12 14:59:54 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
    $ lxc launch ubuntu:precise new-precise-sh
    $ lxc exec new-precise-sh -- bash
    $ apt-get install python-pip
    $ pip install sh
    $ strace -f -e close python -c "import sh; sh.nice()" 2>&1 | wc -l
    1048796

Running strace with output in different files. There is one too big strace.2618

    $ strace -ff -o strace python -c "import sh; sh.nice()"
    $ ls -la
    total 75276
    drwxrwxr-x  2 user user     4096 Sep 27 16:58 .
    drwxr-xr-x 41 user user     4096 Sep 27 16:45 ..
    -rw-r--r--  1 root   root     121780 Sep 27 16:33 strace.2615
    -rw-r--r--  1 root   root       3995 Sep 27 16:33 strace.2616
    -rw-r--r--  1 root   root       6108 Sep 27 16:33 strace.2617
    -rw-r--r--  1 root   root   76558803 Sep 27 16:33 strace.2618
    -rw-r--r--  1 root   root     362363 Sep 27 16:33 strace.2619
    -rw-r--r--  1 root   root      10748 Sep 27 16:33 strace.2620

The content of the file something like this:

    $ cat strace.2618
    ...................
    ...................
    getrlimit(RLIMIT_NOFILE, {rlim_cur=1024*1024, rlim_max=1024*1024}) = 0
    close(3)                                = 0
    close(4)                                = 0
    close(5)                                = -1 EBADF (Bad file descriptor)
    close(6)                                = -1 EBADF (Bad file descriptor)
    close(7)                                = 0
    close(8)                                = 0
    close(9)                                = -1 EBADF (Bad file descriptor)
    close(10)                               = 0
    close(11)                               = -1 EBADF (Bad file     descriptor)
    ...................
    ...................
    close(33)                               = -1 EBADF (Bad file descriptor)
    close(34)                               = -1 EBADF (Bad file descriptor)
    close(35)                               = -1 EBADF (Bad file descriptor)
    close(36)                               = -1 EBADF (Bad file descriptor)
    close(37)                               = -1 EBADF (Bad file descriptor)
    close(38)                               = -1 EBADF (Bad file descriptor)
    ...................
    ...................
    close(1048568)                          = -1 EBADF (Bad file descriptor)
    close(1048569)                          = -1 EBADF (Bad file descriptor)
    close(1048570)                          = -1 EBADF (Bad file descriptor)
    close(1048571)                          = -1 EBADF (Bad file descriptor)
    close(1048572)                          = -1 EBADF (Bad file descriptor)
    close(1048573)                          = -1 EBADF (Bad file descriptor)
    close(1048574)                          = -1 EBADF (Bad file descriptor)
    close(1048575)                          = -1 EBADF (Bad file descriptor)
    ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 -opost -isig -icanon -echo ...}) = 0
@cduelo
Copy link
Author

cduelo commented Sep 27, 2017

Please, check out https://github.com/lxc/lxd/issues/3860

@amoffat
Copy link
Owner

amoffat commented Sep 28, 2017

Thanks for reporting. I read the related issue. It could probably be fixed by using https://docs.python.org/2.7/library/os.html#os.closerange. I don't think we can rely on /proc/ existing on other systems (like OSX).

@amoffat amoffat self-assigned this Apr 24, 2020
@amoffat
Copy link
Owner

amoffat commented Apr 24, 2020

Fixed by #513 and will go out in the next release

@amoffat amoffat closed this as completed Apr 24, 2020
bmwiedemann added a commit to bmwiedemann/openSUSE that referenced this issue Jun 17, 2020
https://build.opensuse.org/request/show/815418
by user StevenK + dimstar_suse
- Update to 1.13.1:
  * regression fix if `_fg=False` [#520](amoffat/sh#520)
  * minor Travis CI fixes [#492](amoffat/sh#492)
  * bugfix for boolean long options not respecting `_long_prefix` [#488](amoffat/sh#488)
  * fix deprecation warning on Python 3.6 regexes [#482](amoffat/sh#482)
  * `_pass_fds` and `_close_fds` special kwargs for controlling file descriptor inheritance in child.
  * more efficiently closing inherited fds [#406](amoffat/sh#406)
  * bugfix where passing invalid dictionary to `_env` will cause a mysterious child 255 exit code. [#497](amoffat/sh#497)
  * bugfix where `_in` using 0 or `sys.stdin` wasn't behaving like a TTY, i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants