I recently use php thrift client to call some service implemented by java thrift server.
But I found that when I transfer a large amount of complex data, php spent a lot of time serialize and deserialize data because of tens of thousands of TBinaryProtocol::readXXX()
or TBinaryProtocol::writeXXX()
calls.
Any good idea to optimize this?
The TBufferedTransport
or TFramedTransport
may help. The former only has a buffer in between to reduce I/O calls, while the latter also changes the transport stack by modifying the wire data (i.e. an Int32 holding the total length of the data block is inserted at the beginning).
Hence, TBufferedTransport
is a purely local thing, in contrast TFramedTransport
must be used on both client and server. Aside from that, both are working very similar.
Furthermore, some of the server types available require TFramedTransport
, so for any new API it may be a good choice to add TFramedTransport
from the beginning.