日志打屏对性能有多少影响
36m的文件,在局域网服务器之间socket单进程传输,client读取源文件并socket发送文件,server接收文件。
server日志打屏的时候花费时间
begin sec[1433750824], microsec[847467]
file[tsl.txt] read over .
end sec[1433750993], microsec[163170]
不打屏的时候花费时间file[tsl.txt] read over .
end sec[1433750993], microsec[163170]
begin sec[1433751290], microsec[743043]
file[tsl.txt] read over .
end sec[1433751291], microsec[39021]
file[tsl.txt] read over .
end sec[1433751291], microsec[39021]
前者169s,后者仅0.65s,输出到stdout可见是一种极其低下的方式。
第二次性能测试比对发送不同大小的包对性能的影响
begin sec[1433751633], microsec[775116]
file[tsl.txt] read over .
end sec[1433751634], microsec[71070]
发送包size为1024,为上次发送的十分之一,耗时不到1s,差别不大file[tsl.txt] read over .
end sec[1433751634], microsec[71070]
begin sec[1433751850], microsec[534276]
file[tsl.txt] read over .
end sec[1433751851], microsec[416336]
发送包size为102,为上次发送的十分之一,耗时不到1s,差别不大。file[tsl.txt] read over .
end sec[1433751851], microsec[416336]
从测试结果看,socket通信中单次发送包的大小对读写效率有影响,包比较大的时候发送效率更快,但差别远没有文件大size和小size写入的差别那么夸张。
第三次测试阻塞IO和非阻塞IO的性能差别
begin sec[1433752606], microsec[316188]
file[tsl.txt] read over .
end sec[1433752607], microsec[35659]
/project/bm3.5/zhaodan/test#./tsclient
begin sec[1433752623], microsec[211854]
file[tsl.txt] read over .
end sec[1433752624], microsec[85021]
/project/bm3.5/zhaodan/test#./tsclient
begin sec[1433752638], microsec[868460]
file[tsl.txt] read over .
end sec[1433752639], microsec[683085]
file[tsl.txt] read over .
end sec[1433752607], microsec[35659]
/project/bm3.5/zhaodan/test#./tsclient
begin sec[1433752623], microsec[211854]
file[tsl.txt] read over .
end sec[1433752624], microsec[85021]
/project/bm3.5/zhaodan/test#./tsclient
begin sec[1433752638], microsec[868460]
file[tsl.txt] read over .
end sec[1433752639], microsec[683085]
非阻塞IO,单次发送102字节的包,发送36m,平均耗时0.8s,和阻塞IO接近一样。
begin sec[1433752705], microsec[148658]
file[tsl.txt] read over .
end sec[1433752705], microsec[264183]
/project/bm3.5/zhaodan/test#./tsclient
begin sec[1433752720], microsec[357477]
file[tsl.txt] read over .
end sec[1433752720], microsec[470690]
/project/bm3.5/zhaodan/test#./tsclient
begin sec[1433752863], microsec[351376]
file[tsl.txt] read over .
end sec[1433752863], microsec[459639]
非阻塞IO,单次发送1024字节的包,发送36m,平均耗时0.1s,nice啊,大幅提升。file[tsl.txt] read over .
end sec[1433752705], microsec[264183]
/project/bm3.5/zhaodan/test#./tsclient
begin sec[1433752720], microsec[357477]
file[tsl.txt] read over .
end sec[1433752720], microsec[470690]
/project/bm3.5/zhaodan/test#./tsclient
begin sec[1433752863], microsec[351376]
file[tsl.txt] read over .
end sec[1433752863], microsec[459639]
/project/bm3.5/zhaodan/test#./tsclient
begin sec[1433752954], microsec[603443]
file[tsl.txt] read over .
end sec[1433752954], microsec[630770]
/project/bm3.5/zhaodan/test#./tsclient
begin sec[1433752970], microsec[302743]
file[tsl.txt] read over .
end sec[1433752970], microsec[330649]
/project/bm3.5/zhaodan/test#./tsclient
begin sec[1433752976], microsec[764320]
file[tsl.txt] read over .
end sec[1433752976], microsec[791707]
begin sec[1433752954], microsec[603443]
file[tsl.txt] read over .
end sec[1433752954], microsec[630770]
/project/bm3.5/zhaodan/test#./tsclient
begin sec[1433752970], microsec[302743]
file[tsl.txt] read over .
end sec[1433752970], microsec[330649]
/project/bm3.5/zhaodan/test#./tsclient
begin sec[1433752976], microsec[764320]
file[tsl.txt] read over .
end sec[1433752976], microsec[791707]
非阻塞IO,单次发送10240字节的包,发送36m,平均耗时0.03s,good
从第三次测试结果来看,小size的包阻塞或者非阻塞基本看不出区别,随着发送包size的提升,性能提升极其显著,大数据IO推荐非阻塞方式。