3

AsyncHTTPClient を使用してテストしている一部のコードで問題が発生しています。ここに一般的な構成があります

    this.config = (new AsyncHttpClientConfig.Builder())
            .setAllowPoolingConnection(true)
            .setAllowSslConnectionPool(true)
            .addRequestFilter(new ThrottleRequestFilter(10))
            .setMaximumConnectionsPerHost(20)
            //.setMaximumConnectionsTotal(20)
            .setRequestTimeoutInMs(100000)
            .build();
    this.client = new AsyncHttpClient(new NettyAsyncHttpProvider(config));

(ThrottleRequestFilter を使用する際の奇妙なバグのため、最大接続数はコメントアウトされていることに注意してください。こちらを参照してください https://groups.google.com/forum/?fromgroups=#!topic/asynchttpclient/nEnQnPtCP2g )

ここにいくつかのテストコードがあります、

FileInputStream fstream = new FileInputStream("import.txt");
DataInputStream dstream = new DataInputStream(fstream);
BufferedReader reader = new BufferedReader(new InputStreamReader(dstream));
while ((line = reader.readLine()) != null) {
//Some code to build and create a request using the build function and then perform a GET operation. Request is built using Java's Future object from java.concurrent
}

import.txt ファイルが次のような 100 行未満の単純なテキストの場合

 196    242 3   881250949

すべてが正常に機能し、すべてのリクエストが通過し、応答を確認するとすべて問題ありません。100 を超えるとタイムアウトが発生し始め、1000 以上の場合は実際に permGen メモリ エラーが発生し始めます。

ThrottleRequestFilter は、最大スレッドを 10 に制限し、一度に 10 のみを処理することになっていると思いました。テキスト ファイルに 100 行以上あると、なぜ爆発するのですか?

また、Grizzly 実装を使用するように切り替えようとしましたが、それも同じように爆発します。テスト コードの書き方に問題があるのか​​、大量のリクエストを作成するときに Async HTTP Client に実際に問題があるのではないかと疑い始めています。もしそうなら、Java用の他の良い非同期httpクライアントはありますか?

4

1 に答える 1

1

問題は、ファイルの読み取りを開始する前にバッファサイズを設定しなかったことです。この例を見てください

private static final int EXT_DEFAULT_BUFFER_SIZE = 1024 * 8;
InputStream   inputStream=this.getClass().getClassLoader().getResourceAsStream("Resource_Name");
public static String copyLargeExt(InputStream input) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[EXT_DEFAULT_BUFFER_SIZE];
        int n = 0;
        while(-1 != (n = input.read(buffer))) {
            baos.write(buffer, 0, n);
        }
        return baos.toString();
    }
于 2012-11-07T23:31:23.903 に答える