本帖最后由 susanlovelemo 于 2012-06-18 11:46:28 编辑 你好!向你请教个问题:
我是个新手,最近在使用netty框架。在做压力测试程序的时候碰到了问题,自己查阅资料并且网上求助无果,希望你能提供帮助。谢谢!
测试客户端:CPU:Inter(R) Core(TM)2 Duo CPU E7500 @2.93GHz Ram:1.96GB
jdk:1.6.0_14 jvm:-Xms128m -Xmx128m netty:3.2.4Final
被测试的服务端是电信服务器,性能很好,应该没有问题。
测试程序中部分代码为:
public static void main(String[] args) throws Exception {
initLog4j();
logger.info("Pressure test begins!");
try {
Timer timer = new Timer();
timer.schedule(new ReportTask(), 1000 * 60 * 3, 1000 * 60 * 5);
} catch (Exception e) {
logger.error("Timer failed!");
e.printStackTrace();
}
String host = "xxx.xxx.xxx.xxx";
int port = 8918;
ClientBootstrap bootstrap = new ClientBootstrap(
new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
bootstrap.setPipelineFactory(new MessageClientPipelineFactory());
int testN = -1;
int sleepTime = -1;
if (args == null || args.length < 2 || Integer.valueOf(args[0]) < 0
|| Integer.valueOf(args[1]) < 0) {
System.out.println("Please enter the rignt user number for test and the rignt sleepTime when connect!");
return;
} else {
testN = Integer.valueOf(args[0]);
StatisticsInTest.getInstance().setTotalUserNum(testN);
sleepTime = Integer.valueOf(args[1]);
}
ChannelFuture future[] = new ChannelFuture[testN];
for (int i = 0; i < testN; i++) {
future[i] = bootstrap.connect(new InetSocketAddress(host, port));
Thread.sleep(sleepTime);
}
for (int i = 0; i < testN; i++) {
future[i].getChannel().getCloseFuture().awaitUninterruptibly();
}
bootstrap.releaseExternalResources();
}
testN 与sleeptime是通过main函数传参进去的。我在handler中对channelconnect进行技术的时候,发现总有一定比例的连接会丢失,比如说testN=1000,sleeptime=200,最多有994个channelconnect事件发生,最少只有973个。我测了很多次,从来都没有全部连接上过。
请问这是什么原因呢?
------解决方案--------------------------------------------------------
还是自问自答吧。最终问题解决啦,是linux系统文件参数需要调优。不容易啊,从中学到很多知识!哈哈
------解决方案--------------------------------------------------------
楼主精神可嘉