tags:

views:

63

answers:

2

is there a problem with doing? will there be some constraint on resources?

#main.rb
(1..100000).each do |loop|

`ruby dosomething.rb`

end

The reason i am doing this is because main.rb needs to be run in Jruby.

Somescript.rb runs faster using less resource in just Ruby, hence i am running it as shell command.

+2  A: 

So starting up the ruby process, parsing the script, executing it and exiting 100,000 times is faster than importing the script into the loop under JRuby? Well, fine if you've measured that then there isn't too much wrong with what you're doing. But if you've only measured running the script once in JRuby and once under ruby (or maybe averaged 5 runs, not in loops of 100,000 times, then there may well be something wrong with what you're doing because you've partially compared the JRuby startup time to the ruby startup time, which wouldn't be a fair comparison since you must run JRuby and then ruby in what you've actually written.

From you comments it seems you're having trouble clearing the memory used by each run when run in JRuby. In that case, you might try a varient of running the loop in the external ruby if that handles the memory correctly it's better than starting up ruby 100,000 times.

#main.rb
`ruby dosomething.rb`
----
#dosomething.rb
(1..100000).each do |loop|
doingSomething
end
dlamblin
this is why i am resorting to this. http://stackoverflow.com/questions/1811472/running-nokogiri-in-jruby-vs-just-ruby
joeyaa
If I read correctly, what you're saying is that you cannot run it in a loop in JRuby because it runs out of memory eventually, while running it as a process does not run out of memory. That's frustrating, but it's certainly one way to force the memory used from each run to get purged.
dlamblin
A: 

There's not much 'wrong' with doing it. It's not a great way to work around a memory bug and I fear for the environment into which you have to deploy. If you have to run in JRuby it seems like it's probably because your sysadmin doesn't want to have a build of Ruby MRI installed so requiring that to run is odd.

But yeah, if it works it works. I would talk to your sysadmin and make sure that it's cool to be running MRI as well as JRuby.

Chuck Vose