facebook / fbthrift

Facebook's branch of Apache Thrift, including a new C++ server.
Apache License 2.0
2.55k stars 608 forks source link

thrift go client usage #522

Closed lee-qiu closed 1 year ago

lee-qiu commented 1 year ago

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?

yfeldblum commented 1 year ago

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.

lee-qiu commented 1 year ago

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?

yfeldblum commented 1 year ago

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

lee-qiu commented 1 year ago

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