facebook/fbthrift

thrift go client usage

lee-qiu opened this issue · 4 comments

It seems that conn is not thread safe in thrift's go lib, so I have to build multi connections (just like a connection pool) when I use conn in multi thread, Is there any suggestions to handle with it? or maybe we can enhance this conn to be thread-safe?

The suggestion is to design programs not to use the same conn concurrently from multiple threads, and more generally to treat low-level i/o as single-threaded.

when service interface is time-consuming and i/o thread costs too much time to wait for response, and what we can do is to build a connection pool to handle with this. Is there any better solutions? Or maybe any planning for thrift to support multiplexing for socket like http/2 and GRPC?

The Thrift protocol natively supports multiplexing multiple requests and streams over a single TCP connection. Some target language implementations, including the C++ implementation, have multiplexing. But not all do - for example, the Go implementation does not. I am not aware of any current work on or current plans for multiplexing for Go. So for now, a reasonable option in your case is to build a connection pool.

(Note that an individual client or connection would still be single-threaded, even if it were hypothetically to support multiplexed requests.)

Thanks for your answer, and I have made some simple changes to support multiplexing for my thrift client and it seems works.