简体   繁体   中英

How to test if my java application can successfully handle low memory/CPU resources on Tomcat server?

I want to test how my java application would behave on Tomcat server with 512M RAM only. In other words I need to do memory load-testing to check if my application can run in such restricted environment.

Using which tools and how can I achieve this?

I heard about APM software including Stackify Prefix, New Relic APM, JMeter, JVisualVM, JVM Monitor, JBenchX - but I am not sure I need to proceed with any of them for my specific purpose.

The same problem for having very limited CPU resources. I'd like to test my app on my desktop PC before deploying to Jelastic cloud with limited memory/CPU.

You can artificially limit the JVM heap allocated to tomcat by modifying -Xmx command-line argument which defines the maximum heap space your Tomcat server will use.

If low heap size is the only thing you would like to test - it would be sufficient.

You might also amending CPU affinity to bind your Tomcat server to a single CPU core (or limited number of cores)


If you want to go further you can create a virtual machine using ie VirtualBox and replicate all the anticipated hardware/software which you'll have after the deployment.

With regards to testing I would recommend the following performance testing techniques :

  • Load Testing - putting your system under anticipated load to see if it is capable of handling it
  • Soak Testing - basically the same as Load Testing but for prolonged duration (ie overnight or weekend) - it will allow you to identify memory leaks
  • Stress Testing - start with Load Testing and gradually increase the load until response time starts exceeding acceptable threshold or errors start occurring (whatever comes the first) - it will let you know the limits of your application/configuration and vision what and how is gonna break

Using profiler tools like YourKit or JProfiler for fine-tuning your code would be beneficial as well.

The best way to do this is with a Virtual Machine. You can pick your technology of choice, but an easy option would be to use Oracle VirtualBox, which is freely-available for many platforms. Just install a minimal OS inside the VM, then add Java, your application, etc. and then run your load-test against it.

Networking works as usual, so you can use your existing load-testing framework and just point it at the IP address of the VM.

There are other fancier way to do it, eg using Docker or whatever, but this will get the job done for a smoke-test.

I wouldn't recommend trying to use a server with a large amount of RAM and then try to "synthesize" a low-RAM situation without using something like a Virtual Machine (and BTW Docker uses VMs internally).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM