Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use a Groovy shell script over Bash (when memory footprint is important)? [closed]

Tags:

linux

bash

groovy

I've got a Bash script (50 lines of code) that requires a bit of hacking due to limitations of bash. So someone said: "hey, use a better language than bash for that!"

So, I looked at Groovy (Groovy/Grails is next up on my to-learn list, so maybe this is a good time). I can do more complex shell scripts, so this might be a perfect fit.

But when I run even a simple Groovy script (while(true){...}) the memory consumption of the Java process is 123M, ouch, I've got about 10 such scripts to run (all bash based now) on a box with 650M of memory. The equivalent stand-alone bash script runs in around 1.5M of memory.

So is this a case of:

  • I'm a newbie doing something wrong, 123M memory footprint is not necessary?
  • Groovy isn't a good fit here? Perhaps Python or Perl are more memory conscious?
  • bash is a good option, even for its shortcomings, when a small footprint is important?
like image 707
David Parks Avatar asked Jul 15 '11 08:07

David Parks


1 Answers

If memory is limited like that, then any language running on the JVM will be at a disadvantage. And Groovy is such a language.

Other languages like Python or Perl have a leaner runtime and require less memory for simple scripts (my guess is that Python is still a bit leaner than Perl, but I can't back that up with numbers).

In my opinion Python is a nice step-up from bash scripts, providing much nicer features while still being lean enough to be used in common scripts.

bash itself is a nice scripting language with a reasonable memory requirement. If memory footprint is really important, than another POSIX-compliant shell (such as dash) might be a reasonable replacement. Note that many, but not all features of bash are present in modern POSIX-compliant Shells.

like image 67
Joachim Sauer Avatar answered Sep 18 '22 12:09

Joachim Sauer