Websocket サーバーの負荷テスト用のツールをコーディングしています。サーバーへの多数 (数万) のクライアント接続を作成する必要があります。
だから私はいくつかのクライアントクラスを持っています。このクラス内で、次の新しいバージョンを作成します。
- ChannelPipelineFactory (ハンドラーと webscoket クライアント ハンドシェーカーを使用)
- クライアントブートストラップ
run() メソッドには、次のコードがあります。
public void run() {
clientBootstrap.setPipelineFactory(clientChannelPipelineFactory);
ChannelFuture future = clientBootstrap.connect(
new InetSocketAddress(
clientConfiguration.getHost(),
clientConfiguration.getPort()
)
);
try {
future.awaitUninterruptibly().rethrowIfFailed();
WebSocketClientHandshaker handshaker = clientChannelPipelineFactory.getHandshaker();
channel = future.getChannel();
handshaker.handshake(channel).awaitUninterruptibly().rethrowIfFailed();
} catch (Exception e) {
log.error("Error in the client channel", e);
stop();
}
}
ChannelFuture によって返されるチャネルは、クライアントのフィールドとして保存されます。
それから私は自分の仕事をして、開いているすべてのチャネルを閉じようとします。stop() メソッド:
public void stop() {
log.debug(String.format("Close channel for client(%s)", id));
if (channel != null) {
if (channel.isWritable()) {
log.debug(String.format("Channel for client(%s) is writable", id));
ChannelFuture writeFuture = channel.write(new CloseWebSocketFrame());
writeFuture.addListener(ChannelFutureListener.CLOSE);
}
}
clientBootstrap.releaseExternalResources();
}
しかし、任意のクライアントで stop() が呼び出されると、すべてのチャネルが閉じられます!?
ps すべてのチャネルを閉じるコード (シングル スレッド):
for (FSBBridgeServerClient client : clients) {
for (FSBBridgeServerClient subClient : clients) {
log.debug("c:" + subClient.getChannel());
log.debug("c:" + subClient.getChannel().isOpen());
}
client.stop();
}
いくつかのデバッグ ログ:
2012-04-04 17:19:29,441 DEBUG [main] ClientApp - c:[id: 0x2344b18f, /127.0.0.1:38366 => localhost/127.0.0.1:5544]
2012-04-04 17:19:29,441 DEBUG [main] ClientApp - c:true
2012-04-04 17:19:29,442 DEBUG [main] ClientApp - c:[id: 0x01c20eb7, /127.0.0.1:38367 => localhost/127.0.0.1:5544]
2012-04-04 17:19:29,442 DEBUG [main] ClientApp - c:true
2012-04-04 17:19:34,414 DEBUG [main] ClientApp - c:[id: 0x2344b18f, /127.0.0.1:38366 :> localhost/127.0.0.1:5544]
2012-04-04 17:19:34,414 DEBUG [main] ClientApp - c:false
2012-04-04 17:19:34,414 DEBUG [main] ClientApp - c:[id: 0x01c20eb7, /127.0.0.1:38367 :> localhost/127.0.0.1:5544]
2012-04-04 17:19:34,414 DEBUG [main] ClientApp - c:false