【问题标题】:Apache thrift: client timeout issuesApache thrift:客户端超时问题
【发布时间】:2011-08-28 21:07:50
【问题描述】:

我有一些带有 perl-server 和 php-client 的 Apache Thrift (v.0.6.1) 测试应用程序。

我无法解释的行为:如果我们使用无效参数调用服务器方法,我们会在服务器输出中看到错误,但 php-client 会无限等待响应。

这里是服务器的来源:

sub new {
    my $classname = shift;
    my $self      = {};

    return bless($self,$classname);
}

sub DateToTimestamp
{
    my ($self, $date) = @_;
    my $result = CommonAPI::DateToTimestamp($date);
    return $result;
}

eval {
  my $handler       = new RPCHandler;
  my $processor     = new RPCPerformanceTest::RPCPerformanceTestProcessor($handler);
  my $serversocket  = new Thrift::ServerSocket(9091);
  my $forkingserver = new Thrift::ForkingServer($processor, $serversocket);
  print "Starting the server...\n";
  $forkingserver->serve();
  print "done.\n";
}; if ($@) {
  if ($@ =~ m/TException/ and exists $@->{message}) {
    my $message = $@->{message};
    my $code    = $@->{code};
    my $out     = $code . ':' . $message;
    die $out;
  } else {
    die $@;
  }
}

和客户:

try {

    $socket = new TSocket($server_host, $server_port);

    $transport = new TBufferedTransport($socket, 1024, 1024);
    $protocol = new TBinaryProtocol($transport);

    $client = new RPCPerformanceTestClient($protocol);
    $transport->open();

    $start = microtime(true);

    $result = $client->DateToTimestamp('071/26/2011 01:23:45');

    var_dump($result);

} catch (Exception $e) {
    echo 'Exception: <b>' . $e->getMessage() . '</b>';
}

为什么会这样?是我的错吗?是预期的行为吗?

【问题讨论】:

标签: php perl thrift


【解决方案1】:

Thrift PHP 库有点损坏。您需要手动设置超时 例如

  $socket = new TSocket('host', 9095);
  $socket->setSendTimeout(60000);
  $socket->setRecvTimeout(60000)

【讨论】:

  • 好像加超时没用,报错一样!有没有其他方法可以在不更改代码的情况下增加超时,例如配置文件..
【解决方案2】:

这种情况经常发生在不提供消息长度的协议中:客户端发送的数据比服务器预期的多,并等待服务器接收数据。服务器接收到一些数据,尝试解析它并失败。现在协议的服务器端处于错误状态。如果它继续读取数据,它可能会阻塞。很可能,服务器端已经向您发送了一些错误响应,同时正在等待客户端接收响应,但这也永远不会发生。

这是我的猜测。恕我直言,最好的策略是为客户端和服务器套接字设置超时。

【讨论】:

  • 超时设置,它是由thrift开发团队在TSockettransport中设置的。但出于某种原因 - 它没有被触发。无论如何,感谢您的回复,这个问题现在对我来说并不实际,所以以您的回答结束;-)
  • 尝试在您的 conf/hbase-site.xml 中更改它:hbase.client.scanner.timeout.period60000 此链接中的更多内容:hbase.apache.org/book/config.files.html
猜你喜欢
  • 2017-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-08
  • 1970-01-01
  • 2020-12-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多