0

I have a VPS (512 RAM max) on which I want to run a simple IRC bot. I've written it in JAVA, but it turned out JVM is eating a tremendous amount of 144 MB ram. The bot itself has a very low demand for memory, unlike JVM.

So the question is: Is Java appropriate for this task? I'm not running any other java apps on this server so this seems to be an utter RAM waste. Would it be better to just rewrite everything in c/c++ or is there a way to run small java programs with little JVM memory overhead?

Just to be sure we're not duplicating questions: -Xms and -Xmx are not going to help, see: Java seems to ignore -Xms and -Xmx options

Community
  • 1
  • 1
Itako
  • 2,049
  • 3
  • 16
  • 19
  • Is there a memory pressure on the OS. Java is likely NOT to free up memory until there is a reason to do so (i.e. the machine is out of RAM) – Stilgar Jun 23 '11 at 07:48
  • Do you need the other ~350 Mb of ram to anything ? If your JVM takes 150Mb, other stuff takes 400Mb you have a problem. If not, you're good. It's just as big a waste running with tons of unused ram as it is running a bloated program. – nos Jun 23 '11 at 08:12
  • Of course I need all the ram i can get of the VPS - otherwise I wouldn't ask this question – Itako Jun 23 '11 at 08:24
  • 1
    You've been told (rightly or wrongly) over on that other question (a) that you're misinterpreting the results of `top`, your process is using 16MB of RAM not 144MB; and (b) that `java` does not ignore `-Xmx`, you've misinterpreted the meaning of that too. You can't really evaluate Java against other languages until you understand what the numbers mean, so I think you need to deal with the issues over on that other question. Demonstrate for certain that your process is using 144MB of RAM as you say, not just assigning 144MB of virtual address space as Peter Lawrey says. – Steve Jessop Jun 23 '11 at 11:09
  • Is an hammer a good tool to drive in a screw? If that's the only tool you have ... – pmg Jun 23 '11 at 12:02
  • Wow, we're really a bit generous with the downvotes here. Even though the author demonstrates not to fully understand Memory and the reporting tools, **this is a valid, well-formed question** and the author has put in the effort required. Why all the downvotes? – Konerak Aug 22 '11 at 08:01

2 Answers2

5

the JVM is huge. write in C or C++ for a much smaller footprint.

or check out smaller VMs like http://jamvm.sourceforge.net/

jcomeau_ictx
  • 37,688
  • 6
  • 92
  • 107
3

Clearly, running an entire JVM on a VPS for the sole purpose of running a single instance of an application which should have a small memory footprint is overkill. On the other hand, if you're not running anything else on the box, then there's no need to worry about that level of memory usage: why rewrite something that works?

Of course, I'm guessing that this is a personal "for fun" project, so you could look at a few language benchmarks benchmarks for hard data on comparisons, and if you have the programming chops to rewrite your bot in C/C++ without introducing a bunch of memory leaks, it is almost certain that the memory footprint would be less.

That being said, you can find a list of alternate JVMs on this wikipedia page, some of which might be able to run with a lower memory footprint.

Caspar
  • 7,039
  • 4
  • 29
  • 41