我在Java中有一个后端服务,我需要它来测试它的性能。它不会暴露在网络上,也可能永远不会。我想知道如何测试这个多线程服务(简单的带有公共方法的类)在大量流量(每秒100K+调用次数)下的性能。
发布于 2013-06-19 15:28:34
如果你想通过你的程序每秒创建100K+调用,那么使用ThreadExecutor来创建你想要在你的调用中测试公共方法的最大线程数。例如,下面的代码模拟地调用您的公共方法,1000个线程访问这些方法
ExecutorService executor = Executors.newFixedThreadPool(1000);
List<YourClass> callingList = new ArrayList<YourClass>();
for (int i = 0; i < 1000; i++) {
EntryPoint Impl = new EntryPoint (YourClass);
callingList.add(Impl);
}
private Class EntryPoint implements Callable<Object>{
private YourClass example;
EntryPoint (YourClass class) {
this.example = class;
}
public List onCall() throws InterruptedException {
example.yourPublicMethod(); 如果你想测量每个方法的每个线程所花费的时间使用interceptor.You的aspectJ可以记录列表中的每个方法所花费的时间直到调用1000 threads.Finally u可以再次迭代一个列表来获得每个方法所花费的时间.If你正在寻找的工具VisualVM或Jconsole.You可以获得关于CPU使用率,内存使用率,线程状态,垃圾收集器,创建的对象的数量和对象消耗的字节数,加载的类的数量等等的信息。
发布于 2013-06-19 06:41:32
JMeter适用于负载测试。
http://jmeter.apache.org/
https://stackoverflow.com/questions/17180196
复制相似问题