1

サービスをテストするための単純な Thrift クライアントとサーバーを作成しました。私が見つけることができる最も単純なクライアントを使用しています...

TSocket socket = new TSocket(<host here>, 8002);
TProtocol proto = new TBinaryProtocol(socket);
Facade.Client client = new Facade.Client(proto);
socket.open();
...

...そして最も単純なサーバー...

Facade.Iface implementation = facadeContext.getBean(Facade.Iface.class);
Facade.Processor processor = new Facade.Processor(implementation);
TServerTransport transport = facadeContext.getBean(TServerSocket.class);  
final TServer thriftServer = new TSimpleServer(new Args(transport).processor(processor));
thriftServer.serve();
...

(また、環境内のすべてが Thrift 0.6.1 です。)

このクライアントで数百のリクエストをはぎ取ると、応答時間は約 2 ミリ秒に落ち着きます。これは私のコンテキストでは問題ありません。ただし、リクエストを続けてリクエストの間にわずかな遅延 (たとえば 5 秒) を入れると、これらの時間は 4 ~ 6 ミリ秒まで急増します。

ソケットのキープアライブ プロパティなどをいじってみましたが、定量化できないオーバーヘッドが発生しています。他の誰かがこれを見たことがありますか?

4

1 に答える 1

0

プレーンな java.io.Socket を使用して単純な TCP サーバーを作成しましたが、上記の内容は Thrift とは何の関係もないと思います。私が観察したわずかな遅延は、リクエストのバーストがサーバーでそれらのリクエストからの入力をバッファリングするという事実に関係していたと思いますが、断続的なリクエストはその利点を得られません. 具体的には、以下のコードで...

public class SocketServerTest {
    public static void main(String[] args) throws Exception {
        try (ServerSocket serverSocket = new ServerSocket(8002)) {
            Socket socket = serverSocket.accept();
            PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

            String inputLine = null;

            while ((inputLine = in.readLine()) != null) {
                if (inputLine.equals("ping")) { out.println("pong"); }
            }

            out.close();
            in.close();
            socket.close();
        }
    }
}

...in.readLine() は、リクエスト データがバッファリングされている場合にブロックされません。

これだけでは 2 ミリ秒の遅延は説明できませんが、上記のシーケンスが発生している場所がいくつかあるため、加算されます。

于 2013-01-22T22:06:53.553 に答える