简体   繁体   English

是thrift-cpp线程安全的客户端吗?

[英]Is client-side of thrift-cpp thread-safe?

I have three quetions. 我有三个问题。

  1. Is client-side of thrift-cpp thread-safe? 是thrift-cpp线程安全的客户端吗?
  2. Do they have some kind of connection-pool on thrift? 他们在节俭上有某种连接池吗?
  3. Any good practice for using thrift-cpp-client. 使用thrift-cpp-client的任何好习惯。

thanks! 谢谢!

Thrift has doxygen docs, but they don't seem to get built. Thrift有doxygen docs,但它们似乎没有建成。 They're not terribly pretty. 他们不是很漂亮。 To generate a copy, run (in the thrift source directory) doxygen -g Doxyfile , change RECURSIVE to YES, then run doxygen Doxyfile . 要生成副本,运行(在thrift源目录中) doxygen -g Doxyfile ,将RECURSIVE更改为YES,然后运行doxygen Doxyfile

In answer to your questions: 在回答你的问题时:

  1. Which client? 哪个客户? There are whole bunch of different thrift transports. 有一大堆不同的节俭运输。 In general, there isn't (AFAICT) any global state, so you can create different clients in different threads. 通常,没有(AFAICT)任何全局状态,因此您可以在不同的线程中创建不同的客户端。 If you're trying to use the same transport in multiple threads, you probably want manual locking unless you've read the code and confirmed that it's okay. 如果您尝试在多个线程中使用相同的传输,则可能需要手动锁定,除非您已阅读代码并确认它没有问题。

  2. I haven't seen one. 我还没见过一个。 AFAICT there are just a bunch of transports that you can connect yourself. AFAICT只有一堆你可以自己连接的传输。 There's the TSocketPool, but that's a load-balancing tool, which isn't what I think you're looking for. 有TSocketPool,但这是一个负载平衡工具,这不是我认为你正在寻找的。

  3. My advice: use the memory transport only and do your own networking. 我的建议:只使用内存传输并进行自己的网络连接。 What Thrift does probably isn't what you want to do, and, even if it is, their documentation and packaging is pretty bad. 什么Thrift可能不是你想要做的,即使它是,他们的文档和包装是非常糟糕的。 (Or use protocol buffers instead of thrift -- they are IMO much better maintained these days. I think this even though I was a thrift contributor way back when.) (或者使用协议缓冲区而不是节俭 - 这些天它们是IMO得到了更好的维护。我认为即使我是一个节俭的贡献者的方式。)

with thrift 0.12. 节俭0.12。

  1. Is client-side of thrift-cpp thread-safe? 是thrift-cpp线程安全的客户端吗? YES This is from a .h/.cpp Autogenerated file by Thrift Compiler (0.12.0) 这是来自Thrift编译器的一个.h / .cpp自动生成的文件(0.12.0)

The 'concurrent' client is a thread safe client that correctly handles out of order responses. '并发'客户端是一个线程安全客户端,可以正确处理乱序响应。 It is slower than the regular client, so should only be used when you need to share a connection among multiple threads 它比常规客户端慢,因此只应在需要在多个线程之间共享连接时使用

Defining a ExampleService (example.thrift) you should have: 定义一个ExampleService(example.thrift)你应该:

class ExampleServiceConcurrentClient : virtual public ExampleServiceIf {
}
  1. Do they have some kind of connection-pool on thrift? 他们在节俭上有某种连接池吗? NO You can make your own connection for each thread or use a connectionConcurrentClient for all threads, it's up to you. 您可以为每个线程建立自己的连接,或者对所有线程使用connectionConcurrentClient,这取决于您。
  2. Any good practice for using thrift-cpp-client. 使用thrift-cpp-client的任何好习惯。 MAYBE Catch at least apache::thrift::TException on every service call MAYBE在每次服务调用时至少捕获apache :: thrift :: TException

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM