Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is client-side of thrift-cpp thread-safe?

I have three quetions.

  1. Is client-side of thrift-cpp thread-safe?
  2. Do they have some kind of connection-pool on thrift?
  3. Any good practice for using thrift-cpp-client.

thanks!

like image 621
kerwin Avatar asked Jun 07 '12 06:06

kerwin


2 Answers

Thrift has doxygen docs, but they don't seem to get built. 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.

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. 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. There's the TSocketPool, but that's a load-balancing tool, which isn't what I think you're looking for.

  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. (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.)

like image 196
Andy Lutomirski Avatar answered Nov 17 '22 21:11

Andy Lutomirski


with thrift 0.12.

  1. Is client-side of thrift-cpp thread-safe? YES This is from a .h/.cpp Autogenerated file by Thrift Compiler (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:

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.
  2. Any good practice for using thrift-cpp-client. MAYBE Catch at least apache::thrift::TException on every service call
like image 29
joseAndresGomezTovar Avatar answered Nov 17 '22 22:11

joseAndresGomezTovar