4 ms·
Please throw up a 'hello world' servlet on github and let me know which arguments to pass it to reduce the memory usage. I've tried, but I may have missed somet
by jshen 15y ago
Please throw up a 'hello world' servlet on github and let me know which arguments to pass it to reduce the memory usage. I've tried, but I may have missed something, and yes I've tried all the obvious things like setting the heap size.
I think the commenter you're quoting is confusing the heap size with the total size. Or I'm missing something and would love for someone to show me what I'm missing.
- DanielRibeiro 15y agoI don't know about tomcat, as its memory footprint can be quite big. But Jetty's hello world is a 5 lines in Bash, and takes 9 MB: http://wiki.eclipse.org/Jetty/Tutorial/Jetty_HelloWorld http://wiki.eclipse.org/Jetty/Tutorial/Jetty_HelloWorld Java ecosystem is too big, and it is common for newcomers to overlook the juicy parts. The mainstream frameworks and libraries reflect the mainstream use of java: big apps for medium/big companies.
- jshen 15y agoIt's taking 57.6MB for me. That's Real Mem in the macs Activity Monitor.
- DanielRibeiro 15y agoWell, I am using this on Ubuntu Lucid, with jdk 1.6.0_25-b06 You may wanna try playing with some variables. With the following command line: java -cp .:servlet-api-2.5.jar:jetty-all-7.0.2.v20100331.jar -client -XX:MaxPermSize=1M -Xmx2M -Xms2M HelloWorld I've added -client -XX:MaxPermSize=1M -Xmx2M -Xms2M. It took it down to 7Mb from 9Mb. However, this should not concern you in VPS/Amazon EC2 instances, as you can always run linux there, and these problems should not come by.
- jshen 15y agoThis is on my linux VPS (64bit) $ java -cp .:servlet-api-2.5.jar:jetty-all-7.0.2.v20100331.jar -client -XX:MaxPermSize=1M -Xmx2M -Xms2M HelloWorld Error occurred during initialization of VM Too small initial heap for new size specified I can't get it to run in under 30MB RES according to top. This is after hitting it with a little traffic, i'm not sure if you hit yours with any traffic.
- DanielRibeiro 15y agoAh, 64bit JVM. It likes to think it is of itself as enterprise. One thing that may help is -XX:+UseCompressedOops, and even -Xmn1M. Note that depending on the enverionment it may say it is too small, so you may have to ramp up a bit some of these stats. I also get it if I set lower than then ones I gave. Note that jvm is very tunnable[1,2]. Also note that you can use a 32 bit jdk in a 64bit machine. It won't get you beyond 2GB vm, but if you are going for small memory, this is not something that matters (and it should allow you to get to a very small memory footprint). Also note that there are other JVMs, like Oracle's JRockit (with extra memory options[3]), and KVM[4] (designed for small memory footprint[5]). But hey, that is lower than 32 MB already! Edit You can also try some other lesser drastic measures[6,7]. Note that you are getting in less mainstream use of the JVM, and things can get a little crazy in this area. [1] http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html http://www.oracle.com/technetwork/java/javase/tech/vmoptions... [2] http://www.caucho.com/resin-3.0/performance/jvm-tuning.xtp http://www.caucho.com/resin-3.0/performance/jvm-tuning.xtp [3] http://download.oracle.com/docs/cd/E15289_01/doc.40/e15060/tune_footprint.htm http://download.oracle.com/docs/cd/E15289_01/doc.40/e15060/t... [4] http://en.wikipedia.org/wiki/K_virtual_machine http://en.wikipedia.org/wiki/K_virtual_machine [5] http://java.sun.com/products/cldc/wp/ http://java.sun.com/products/cldc/wp/ [6] http://www.coderanch.com/t/202896/Performance/java/Ways-reduce-memory-footprint-JVM http://www.coderanch.com/t/202896/Performance/java/Ways-redu... [7] http://stackoverflow.com/questions/4893192/process-memory-vs-heap-jvm http://stackoverflow.com/questions/4893192/process-memory-vs...
- jshen 15y agothanks for the thoughtful replies!
- DanielRibeiro 15y agoNo problem!
- democracy 15y agoIn j2ee (and servlet is part of j2ee, you should know that) there is no such thing as standalone servlet. Servlet is a part of the framework which includes all of j2ee interfaces and implementations.