0
このコードの目的は、grpcサービスが利用できなかったときにgrpcスタブの動作を最初にテストすることでした。しかし、私が見ている行動は、私が理解していないことが起こっていることを示しています。このコードでGrpcクライアント側のC++チャンネルデストラクタが10秒かかる
:
#define IN_MILLISECONDS(x) (std::chrono::system_clock::now() + std::chrono::milliseconds(x))
string NowString()
{
char buf[128];
SYSTEMTIME timeBuf;
::GetLocalTime(&timeBuf);
sprintf(buf, "%02d:%02d:%02d.%03d - ", timeBuf.wHour, timeBuf.wMinute, timeBuf.wSecond, timeBuf.wMilliseconds);
return string(buf);
}
void testStub(std::shared_ptr<grpc::Channel> chan)
{
MessageProcessor::Stub client(chan);
Void _void;
AccumulateAmount amount;
amount.set_amount(42);
grpc::ClientContext ctx;
ctx.set_deadline(IN_MILLISECONDS(100));
cout << NowString() << " Making RPC\n";
grpc::Status st = client.Accumulate(&ctx, amount, &_void);
cout << NowString() << " Leaving testStub()\n";
}
void test()
{
auto chan = grpc::CreateChannel("localhost:54321", grpc::InsecureChannelCredentials());
cout << NowString() << " Channel Up- Testing Stub\n";
testStub(chan);
cout << NowString() << " Leaving test()\n";
}
int main()
{
cout << NowString() << "Calling test()\n";
test();
cout << NowString() << "Exiting 'main'\n";
return 1;
}
出力は、チャネルのデストラクタはわずか10秒を取っているタイムスタンプにより明らかなはずである
11:42:05.400 - Calling test()
11:42:05.403 - Channel Up- Testing Stub
11:42:05.404 - Making RPC
11:42:05.506 - Leaving testStub()
11:42:05.507 - Leaving test()
11:42:15.545 - Exiting 'main'
Press any key to continue . . .
です。
私の質問はこれです:grpcチャンネルを破壊するのにかかる時間を大幅に短縮するにはどうすればよいですか?