问题:使用模拟器测试,提示:
参考:http://grokbase.com/t/thrift/user/101gw5eh24/tframedtransport-and-tbufferedtransport
Generally, unless you're working directly from memory, you should always use
either framed or buffered transport. Otherwise, every little byte you need
to read out will go to the OS buffer, which will just crush your
performance.
Additionally, if you are connecting to a nonblocking server (like Java's
TNonblockingServer and THsHaServer), then you *must* use a framed transport,
since this is the only way they can tell when a whole message has been sent.
参考:http://halloffame.iteye.com/blog/2346959
1--transport_type本例中只列举使用了以下三种:
(1) buffered:使用经典的缓冲流Socket;
(2) framed:基于帧的方式的Socket,每个帧都是按照4字节的帧长加上帧的内容来组织,帧内容就是我们要收发的数据。读的时候按长度预先将整Frame数据读入Buffer,再从Buffer慢慢读取。写的时候,每次flush将Buffer中的所有数据写成一个Frame。framed这种方式有点类似于http协议的chunked编码;
(3) fastframed:和framed相比是内存利用率更高的一个内存读写缓存区,它使用自动增长的byte[](不够长度才new),而不是每次都new一个byte[],提高了内存的使用率。framed的ReadBuffer每次读入Frame时都会创建新的byte[],WriteBuffer每次flush时如果大于初始1K也会重新创建byte[]。
2--protocol_type本例中只列举使用了以下三种:
(1) binary:二进制编码格式进行数据传输;
(2) json:使用JSON的数据编码协议进行数据传输;
(3) compact:高效率的,密集的二进制编码格式进行数据传输
[popexizhi: 这个正好是
TCompactProtocol 和 TBinaryProtocol 的区别]
Thrift: Mon Feb 6 12:16:48 2017 TConnectedClient died: Frame size has negative value
client端提示错误为:
message='TSocket read 0 bytes')
thrift.transport.TTransport.TTransportException: TSocket read 0 bytes
message='TSocket read 0 bytes')
thrift.transport.TTransport.TTransportException: TSocket read 0 bytes
修改使用
21 transport = TTransport.TFramedTransport(transport)
23 protocol = TCompactProtocol.TCompactProtocol(transport)
21 transport = TTransport.TFramedTransport(transport)
23 protocol = TCompactProtocol.TCompactProtocol(transport)
替代如下:测试通过
20 #transport = TTransport.TBufferedTransport(transport)
22 #protocol = TBinaryProtocol.TBinaryProtocol(transport)
20 #transport = TTransport.TBufferedTransport(transport)
22 #protocol = TBinaryProtocol.TBinaryProtocol(transport)
解释:
TFramed与TBuffered的区别参考:http://grokbase.com/t/thrift/user/101gw5eh24/tframedtransport-and-tbufferedtransport
Generally, unless you're working directly from memory, you should always use
either framed or buffered transport. Otherwise, every little byte you need
to read out will go to the OS buffer, which will just crush your
performance.
Additionally, if you are connecting to a nonblocking server (like Java's
TNonblockingServer and THsHaServer), then you *must* use a framed transport,
since this is the only way they can tell when a whole message has been sent.
参考:http://halloffame.iteye.com/blog/2346959
1--transport_type本例中只列举使用了以下三种:
(1) buffered:使用经典的缓冲流Socket;
(2) framed:基于帧的方式的Socket,每个帧都是按照4字节的帧长加上帧的内容来组织,帧内容就是我们要收发的数据。读的时候按长度预先将整Frame数据读入Buffer,再从Buffer慢慢读取。写的时候,每次flush将Buffer中的所有数据写成一个Frame。framed这种方式有点类似于http协议的chunked编码;
(3) fastframed:和framed相比是内存利用率更高的一个内存读写缓存区,它使用自动增长的byte[](不够长度才new),而不是每次都new一个byte[],提高了内存的使用率。framed的ReadBuffer每次读入Frame时都会创建新的byte[],WriteBuffer每次flush时如果大于初始1K也会重新创建byte[]。
2--protocol_type本例中只列举使用了以下三种:
(1) binary:二进制编码格式进行数据传输;
(2) json:使用JSON的数据编码协议进行数据传输;
(3) compact:高效率的,密集的二进制编码格式进行数据传输
[popexizhi: 这个正好是
TCompactProtocol 和 TBinaryProtocol 的区别]
没有评论:
发表评论