simulate high cpu load for java development

2019-03-03 20:27发布

问题:

I'm developing a Java app and would like to see how it runs on slower/overloaded machines. (I suspect there may be some thread unsafe issues, etc. that get ignored because my machine just compiles it quickly enough.

Is there a way to simulate high CPU load/limit available CPU for the Java app? Of course, I could write a script to actually overload my CPU with various tasks, but I would prefer to keep the rest of my OS running smoothly and not overheat my machine, if possible. Is there an easy/known way to do this?

I am currently using Eclipse Kepler as my IDE, but would be willing to switch if another could do this natively.

EDIT: I'm working in Windows, forgot to clarify. :)

回答1:

Well, the thing is if you write a script that will open another process in your machine, loading your machine with many processes is not a good option to check thread safety as multithreading on diffrent processes is handled by the kernel.

What you want id to check the threading into only your process... don't know but if you have web app ,Apache benchmark is best option for you ... in general you can check with http://jmeter.apache.org/ this can do better load testing.



回答2:

Use BES to throttle your CPU for that specific prcocess.

I would highly recommend you limiting your memory usage for the exact same purpose.

See this post for a very easy way to pass in a maximum memory usage when you execute the compiled file.