Unknown ruby processes show up in "top" when running cronjob

Discussion in 'Ruby' started by observatory@gmail.com, Nov 20, 2006.

  1. Guest

    Hello,

    I have a ruby (rails) cronjob.
    When I monitor the execution of the cronjob with top, I notice that 2
    more processes show up in there (instead of just one for my cronjob).

    My cronjob captures the output of running a python script (with the
    `python script.py` syntax). Can this be the cause? Why?

    Thanks for any tips
     
    , Nov 20, 2006
    #1
    1. Advertising

  2. Guest

    I don't think that's the case, I'm talking about two more "ruby"
    processes showing up there. (Python also appears)

    I created two test scripts, one in ruby that launches (with `python
    script.py`) the other written in python (I also put some sleep(5) calls
    in there for better observation). And as it is normal, only one "ruby"
    process appears and for the duration of the python script, a "python"
    process.

    This probably has something to do with rails, but I don't know what.

    Thanks

    Paul Lutus wrote:
    > wrote:
    >
    > > Hello,
    > >
    > > I have a ruby (rails) cronjob.
    > > When I monitor the execution of the cronjob with top, I notice that 2
    > > more processes show up in there (instead of just one for my cronjob).
    > >
    > > My cronjob captures the output of running a python script (with the
    > > `python script.py` syntax). Can this be the cause?

    >
    > Yes.
    >
    > > Why?

    >
    > Because the cronjob has its own process ID (1), then it needs to execute the
    > Python interpreter (2) which runs the Python script (3). All separate
    > processes.
    >
    > --
    > Paul Lutus
    > http://www.arachnoid.com
     
    , Nov 21, 2006
    #2
    1. Advertising

  3. Guest

    Maybe it's related to the fact that the rails script/runner doesn't
    like that piping (`python script.py`). I noticed that those 2 ruby
    processes appear as soon as a "sh" process briefly appears in top and
    then vanishes.

    Does anyone have any suggestions?

    Thanks

    wrote:
    > I don't think that's the case, I'm talking about two more "ruby"
    > processes showing up there. (Python also appears)
    >
    > I created two test scripts, one in ruby that launches (with `python
    > script.py`) the other written in python (I also put some sleep(5) calls
    > in there for better observation). And as it is normal, only one "ruby"
    > process appears and for the duration of the python script, a "python"
    > process.
    >
    > This probably has something to do with rails, but I don't know what.
    >
    > Thanks
    >
    > Paul Lutus wrote:
    > > wrote:
    > >
    > > > Hello,
    > > >
    > > > I have a ruby (rails) cronjob.
    > > > When I monitor the execution of the cronjob with top, I notice that 2
    > > > more processes show up in there (instead of just one for my cronjob).
    > > >
    > > > My cronjob captures the output of running a python script (with the
    > > > `python script.py` syntax). Can this be the cause?

    > >
    > > Yes.
    > >
    > > > Why?

    > >
    > > Because the cronjob has its own process ID (1), then it needs to execute the
    > > Python interpreter (2) which runs the Python script (3). All separate
    > > processes.
    > >
    > > --
    > > Paul Lutus
    > > http://www.arachnoid.com
     
    , Nov 21, 2006
    #3
  4. Guest

    I found the cause:

    It's because of some "net/http" calls I make in the ruby script. It
    seems that ruby forks two more processes when doing that. (I 'head'
    certain web addresses.)
    The forked processes remain in memory for the duration of the main
    process.

    You can imagine why this is very annoying; the same calls are made by
    my long running rails FastCGI processes, this means that there will be
    3 times as many FastCGI processes reported as running at a given time -
    and DreamHost's procwatch will start killing them (too much memory
    used) resulting in error screens.

    Is there a way to prevent the apparition of these processes when making
    net/http calls ? Or at least to make them go away - without killing the
    main process?

    Thanks

    wrote:
    > Maybe it's related to the fact that the rails script/runner doesn't
    > like that piping (`python script.py`). I noticed that those 2 ruby
    > processes appear as soon as a "sh" process briefly appears in top and
    > then vanishes.
    >
    > Does anyone have any suggestions?
    >
    > Thanks
    >
    > wrote:
    > > I don't think that's the case, I'm talking about two more "ruby"
    > > processes showing up there. (Python also appears)
    > >
    > > I created two test scripts, one in ruby that launches (with `python
    > > script.py`) the other written in python (I also put some sleep(5) calls
    > > in there for better observation). And as it is normal, only one "ruby"
    > > process appears and for the duration of the python script, a "python"
    > > process.
    > >
    > > This probably has something to do with rails, but I don't know what.
    > >
    > > Thanks
    > >
    > > Paul Lutus wrote:
    > > > wrote:
    > > >
    > > > > Hello,
    > > > >
    > > > > I have a ruby (rails) cronjob.
    > > > > When I monitor the execution of the cronjob with top, I notice that 2
    > > > > more processes show up in there (instead of just one for my cronjob).
    > > > >
    > > > > My cronjob captures the output of running a python script (with the
    > > > > `python script.py` syntax). Can this be the cause?
    > > >
    > > > Yes.
    > > >
    > > > > Why?
    > > >
    > > > Because the cronjob has its own process ID (1), then it needs to execute the
    > > > Python interpreter (2) which runs the Python script (3). All separate
    > > > processes.
    > > >
    > > > --
    > > > Paul Lutus
    > > > http://www.arachnoid.com
     
    , Nov 21, 2006
    #4
  5. 2006/11/20, Paul Lutus <>:
    > wrote:
    >
    > > Hello,
    > >
    > > I have a ruby (rails) cronjob.
    > > When I monitor the execution of the cronjob with top, I notice that 2
    > > more processes show up in there (instead of just one for my cronjob).
    > >
    > > My cronjob captures the output of running a python script (with the
    > > `python script.py` syntax). Can this be the cause?

    >
    > Yes.
    >
    > > Why?

    >
    > Because the cronjob has its own process ID (1), then it needs to execute the
    > Python interpreter (2) which runs the Python script (3). All separate
    > processes.


    No: Python does not create two processes. However, the backtick
    command uses a sub-shell to execute the command line, so: cron
    launches Ruby (1 process), which launches "/bin/sh -c 'python
    script.py'" (1 process), which launches Python on the script (1
    process). See the documentation for Kernel#` (the actual method
    implementing the backtick command).

    If you don"t need shell-specific features (pipes and redirections) in
    the command line you execute, you can fork the Ruby process and then
    call exec to *replace* that child process with python, thus bypassing
    the intermediate shell. It's probably not worth the trouble though.
     
    Pierre-Charles David, Nov 22, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Rodriguez
    Replies:
    23
    Views:
    1,204
    David Schwartz
    Dec 9, 2003
  2. Vincent Arnoux
    Replies:
    1
    Views:
    272
    Arnaud Bergeron
    Aug 11, 2006
  3. Marc Heiler
    Replies:
    1
    Views:
    192
    Robert Klemme
    May 24, 2009
  4. Matthew Lagace

    Problem with cronjob and ruby script

    Matthew Lagace, Jun 5, 2009, in forum: Ruby
    Replies:
    19
    Views:
    330
    Hassan Schroeder
    Jun 5, 2009
  5. Public Interest

    How Do I Use CGI->System Call As CronJob?

    Public Interest, Oct 31, 2003, in forum: Perl Misc
    Replies:
    10
    Views:
    294
    Kevin Shay
    Oct 31, 2003
Loading...

Share This Page