Closed nullscode closed 2 years ago
I use this code to test NetworkStream.Write speed:
var t1 = DateTime.Now.Ticks;//start if (TcpStream != null) if (TcpStream.CanWrite) TcpStream.Write(buf, 0, buf.Length);//NetworkStream.Write var t2 = DateTime.Now.Ticks - t1;//end $"TCP Write:{t2 / 10}us {buf.Length} {Convert.ToHexString(buf)}".LogForDebug();//Write to logfile
then I got these logs sometimes return pretty slow this situation only in linux: 02:06:56.271|c__DisplayClass11_0|Debug > TCP Write:12us 13 AB00608D7B9100757ADA08DABA 02:06:56.277|c__DisplayClass11_0|Debug > TCP Write:5772us 13 AB0060AA839200757ADA0806BA 02:06:56.277|c__DisplayClass11_0|Debug > TCP Write:10us 13 AB00600AD89200757ADA08FDBA 02:06:56.298|c__DisplayClass11_0|Debug > TCP Write:20310us 13 AB0060E5259300757ADA08EEBA 02:06:56.298|c__DisplayClass11_0|Debug > TCP Write:12us 13 AB00603E799300757ADA0869BA 02:06:56.303|c__DisplayClass11_0|Debug > TCP Write:5518us 13 AB006099C69300757ADA0871BA 02:06:56.304|c__DisplayClass11_0|Debug > TCP Write:10us 13 AB0060FDE79400757ADA0833BA 02:06:56.323|c__DisplayClass11_0|Debug > TCP Write:19367us 13 AB00609D829600757ADA0834BA 02:06:56.324|c__DisplayClass11_0|Debug > TCP Write:13us 13 AB0060C3F99600757ADA0811BA 02:06:56.331|c__DisplayClass11_0|Debug > TCP Write:6900us 13 AB006063479700757ADA080EBA 02:06:56.331|c__DisplayClass11_0|Debug > TCP Write:10us 13 AB006033959700757ADA088CBA 02:06:56.351|c__DisplayClass11_0|Debug > TCP Write:19534us 13 AB00600BE49700757ADA08C5BA 02:06:56.351|c__DisplayClass11_0|Debug > TCP Write:11us 13 AB0060AE309800757ADA08BBBA 02:06:56.357|c__DisplayClass11_0|Debug > TCP Write:5604us 13 AB0060587D9800757ADA0800BA 02:06:56.357|c__DisplayClass11_0|Debug > TCP Write:12us 13 AB00601BCD9800757ADA08F3BA 02:06:56.376|c__DisplayClass11_0|Debug > TCP Write:19273us 13 AB0060A4199900757ADA0899BA 02:06:56.377|c__DisplayClass11_0|Debug > TCP Write:11us 13 AB0060D66A9900757ADA0898BA 02:06:56.382|c__DisplayClass11_0|Debug > TCP Write:3146us 14 AB00600155029900757ADA089FBA 02:06:56.383|c__DisplayClass11_0|Debug > TCP Write:12us 13 AB0060F9789A00757ADA08A6BA 02:06:56.402|c__DisplayClass11_0|Debug > TCP Write:19495us 13 AB006012C79A00757ADA08F2BA 02:06:56.402|c__DisplayClass11_0|Debug > TCP Write:11us 13 AB006042179B00757ADA0873BA 02:06:56.408|c__DisplayClass11_0|Debug > TCP Write:5492us 13 AB00605E639B00757ADA081BBA 02:06:56.408|c__DisplayClass11_0|Debug > TCP Write:10us 13 AB00605EB49B00757ADA08CCBA
02:06:56.271|c__DisplayClass11_0|Debug > TCP Write:12us 13 AB00608D7B9100757ADA08DABA 02:06:56.277|c__DisplayClass11_0|Debug > TCP Write:5772us 13 AB0060AA839200757ADA0806BA 02:06:56.277|c__DisplayClass11_0|Debug > TCP Write:10us 13 AB00600AD89200757ADA08FDBA 02:06:56.298|c__DisplayClass11_0|Debug > TCP Write:20310us 13 AB0060E5259300757ADA08EEBA 02:06:56.298|c__DisplayClass11_0|Debug > TCP Write:12us 13 AB00603E799300757ADA0869BA 02:06:56.303|c__DisplayClass11_0|Debug > TCP Write:5518us 13 AB006099C69300757ADA0871BA 02:06:56.304|c__DisplayClass11_0|Debug > TCP Write:10us 13 AB0060FDE79400757ADA0833BA 02:06:56.323|c__DisplayClass11_0|Debug > TCP Write:19367us 13 AB00609D829600757ADA0834BA 02:06:56.324|c__DisplayClass11_0|Debug > TCP Write:13us 13 AB0060C3F99600757ADA0811BA 02:06:56.331|c__DisplayClass11_0|Debug > TCP Write:6900us 13 AB006063479700757ADA080EBA 02:06:56.331|c__DisplayClass11_0|Debug > TCP Write:10us 13 AB006033959700757ADA088CBA 02:06:56.351|c__DisplayClass11_0|Debug > TCP Write:19534us 13 AB00600BE49700757ADA08C5BA 02:06:56.351|c__DisplayClass11_0|Debug > TCP Write:11us 13 AB0060AE309800757ADA08BBBA 02:06:56.357|c__DisplayClass11_0|Debug > TCP Write:5604us 13 AB0060587D9800757ADA0800BA 02:06:56.357|c__DisplayClass11_0|Debug > TCP Write:12us 13 AB00601BCD9800757ADA08F3BA 02:06:56.376|c__DisplayClass11_0|Debug > TCP Write:19273us 13 AB0060A4199900757ADA0899BA 02:06:56.377|c__DisplayClass11_0|Debug > TCP Write:11us 13 AB0060D66A9900757ADA0898BA 02:06:56.382|c__DisplayClass11_0|Debug > TCP Write:3146us 14 AB00600155029900757ADA089FBA 02:06:56.383|c__DisplayClass11_0|Debug > TCP Write:12us 13 AB0060F9789A00757ADA08A6BA 02:06:56.402|c__DisplayClass11_0|Debug > TCP Write:19495us 13 AB006012C79A00757ADA08F2BA 02:06:56.402|c__DisplayClass11_0|Debug > TCP Write:11us 13 AB006042179B00757ADA0873BA 02:06:56.408|c__DisplayClass11_0|Debug > TCP Write:5492us 13 AB00605E639B00757ADA081BBA 02:06:56.408|c__DisplayClass11_0|Debug > TCP Write:10us 13 AB00605EB49B00757ADA08CCBA
and this is same code I run in windows and the logs I got: 02:08:20.043|c__DisplayClass11_0|Debug > TCP Write:27us 13 AB006054545332757ADA08DCBA 02:08:20.045|c__DisplayClass11_0|Debug > TCP Write:22us 13 AB0060F0A35332757ADA088FBA 02:08:20.047|c__DisplayClass11_0|Debug > TCP Write:22us 13 AB0060C1F15332757ADA08ECBA 02:08:20.049|c__DisplayClass11_0|Debug > TCP Write:23us 13 AB0060903F5432757ADA0874BA 02:08:20.051|c__DisplayClass11_0|Debug > TCP Write:24us 13 AB00607A8D5432757ADA082CBA 02:08:20.053|c__DisplayClass11_0|Debug > TCP Write:26us 13 AB006063DC5432757ADA0864BA 02:08:20.055|c__DisplayClass11_0|Debug > TCP Write:38us 14 AB0060F128550032757ADA0803BA 02:08:20.057|c__DisplayClass11_0|Debug > TCP Write:22us 14 AB00608678550032757ADA0824BA 02:08:20.059|c__DisplayClass11_0|Debug > TCP Write:22us 15 AB00605502C7550032757ADA08A7BA 02:08:20.061|c__DisplayClass11_0|Debug > TCP Write:23us 13 AB00608E135632757ADA0844BA 02:08:20.063|c__DisplayClass11_0|Debug > TCP Write:21us 13 AB00605F625632757ADA08E4BA 02:08:20.065|c__DisplayClass11_0|Debug > TCP Write:43us 13 AB0060F6AF5632757ADA0880BA 02:08:20.067|c__DisplayClass11_0|Debug > TCP Write:29us 13 AB006035FF5632757ADA0813BA 02:08:20.069|c__DisplayClass11_0|Debug > TCP Write:33us 13 AB006090515732757ADA0819BA 02:08:20.071|c__DisplayClass11_0|Debug > TCP Write:36us 13 AB0060DE995732757ADA089FBA 02:08:20.073|c__DisplayClass11_0|Debug > TCP Write:24us 13 AB00608BEA5732757ADA08B9BA 02:08:20.075|c__DisplayClass11_0|Debug > TCP Write:22us 13 AB0060B6385832757ADA0859BA 02:08:20.077|c__DisplayClass11_0|Debug > TCP Write:22us 13 AB006014865832757ADA0845BA 02:08:20.079|c__DisplayClass11_0|Debug > TCP Write:23us 13 AB006061D45832757ADA0862BA 02:08:20.082|c__DisplayClass11_0|Debug > TCP Write:39us 13 AB006031215932757ADA08C6BA 02:08:20.086|c__DisplayClass11_0|Debug > TCP Write:146us 13 AB0060DFBF5932757ADA08B6BA 02:08:20.090|c__DisplayClass11_0|Debug > TCP Write:29us 13 AB006089815A32757ADA08DDBA 02:08:20.092|c__DisplayClass11_0|Debug > TCP Write:26us 13 AB00606DCE5A32757ADA0876BA 02:08:20.094|c__DisplayClass11_0|Debug > TCP Write:23us 13 AB0060BF1D5B32757ADA0876BA 02:08:20.096|c__DisplayClass11_0|Debug > TCP Write:22us 13 AB0060626C5B32757ADA08DABA 02:08:20.099|c__DisplayClass11_0|Debug > TCP Write:341us 14 AB0060D555025B32757ADA08BBBA 02:08:20.104|c__DisplayClass11_0|Debug > TCP Write:42us 13 AB00603F7C5C32757ADA0890BA 02:08:20.107|c__DisplayClass11_0|Debug > TCP Write:50us 13 AB0060291A5D32757ADA08E1BA 02:08:20.111|c__DisplayClass11_0|Debug > TCP Write:32us 13 AB0060C9B45D32757ADA08AFBA
02:08:20.043|c__DisplayClass11_0|Debug > TCP Write:27us 13 AB006054545332757ADA08DCBA 02:08:20.045|c__DisplayClass11_0|Debug > TCP Write:22us 13 AB0060F0A35332757ADA088FBA 02:08:20.047|c__DisplayClass11_0|Debug > TCP Write:22us 13 AB0060C1F15332757ADA08ECBA 02:08:20.049|c__DisplayClass11_0|Debug > TCP Write:23us 13 AB0060903F5432757ADA0874BA 02:08:20.051|c__DisplayClass11_0|Debug > TCP Write:24us 13 AB00607A8D5432757ADA082CBA 02:08:20.053|c__DisplayClass11_0|Debug > TCP Write:26us 13 AB006063DC5432757ADA0864BA 02:08:20.055|c__DisplayClass11_0|Debug > TCP Write:38us 14 AB0060F128550032757ADA0803BA 02:08:20.057|c__DisplayClass11_0|Debug > TCP Write:22us 14 AB00608678550032757ADA0824BA 02:08:20.059|c__DisplayClass11_0|Debug > TCP Write:22us 15 AB00605502C7550032757ADA08A7BA 02:08:20.061|c__DisplayClass11_0|Debug > TCP Write:23us 13 AB00608E135632757ADA0844BA 02:08:20.063|c__DisplayClass11_0|Debug > TCP Write:21us 13 AB00605F625632757ADA08E4BA 02:08:20.065|c__DisplayClass11_0|Debug > TCP Write:43us 13 AB0060F6AF5632757ADA0880BA 02:08:20.067|c__DisplayClass11_0|Debug > TCP Write:29us 13 AB006035FF5632757ADA0813BA 02:08:20.069|c__DisplayClass11_0|Debug > TCP Write:33us 13 AB006090515732757ADA0819BA 02:08:20.071|c__DisplayClass11_0|Debug > TCP Write:36us 13 AB0060DE995732757ADA089FBA 02:08:20.073|c__DisplayClass11_0|Debug > TCP Write:24us 13 AB00608BEA5732757ADA08B9BA 02:08:20.075|c__DisplayClass11_0|Debug > TCP Write:22us 13 AB0060B6385832757ADA0859BA 02:08:20.077|c__DisplayClass11_0|Debug > TCP Write:22us 13 AB006014865832757ADA0845BA 02:08:20.079|c__DisplayClass11_0|Debug > TCP Write:23us 13 AB006061D45832757ADA0862BA 02:08:20.082|c__DisplayClass11_0|Debug > TCP Write:39us 13 AB006031215932757ADA08C6BA 02:08:20.086|c__DisplayClass11_0|Debug > TCP Write:146us 13 AB0060DFBF5932757ADA08B6BA 02:08:20.090|c__DisplayClass11_0|Debug > TCP Write:29us 13 AB006089815A32757ADA08DDBA 02:08:20.092|c__DisplayClass11_0|Debug > TCP Write:26us 13 AB00606DCE5A32757ADA0876BA 02:08:20.094|c__DisplayClass11_0|Debug > TCP Write:23us 13 AB0060BF1D5B32757ADA0876BA 02:08:20.096|c__DisplayClass11_0|Debug > TCP Write:22us 13 AB0060626C5B32757ADA08DABA 02:08:20.099|c__DisplayClass11_0|Debug > TCP Write:341us 14 AB0060D555025B32757ADA08BBBA 02:08:20.104|c__DisplayClass11_0|Debug > TCP Write:42us 13 AB00603F7C5C32757ADA0890BA 02:08:20.107|c__DisplayClass11_0|Debug > TCP Write:50us 13 AB0060291A5D32757ADA08E1BA 02:08:20.111|c__DisplayClass11_0|Debug > TCP Write:32us 13 AB0060C9B45D32757ADA08AFBA
I tryed both version : 6.0 7.0 preview
I found the reason , the SendBufferSize is too low,I need set it to a high value.
I use this code to test NetworkStream.Write speed:
then I got these logs sometimes return pretty slow this situation only in linux:
02:06:56.271|c__DisplayClass11_0|Debug > TCP Write:12us 13 AB00608D7B9100757ADA08DABA 02:06:56.277|c__DisplayClass11_0|Debug > TCP Write:5772us 13 AB0060AA839200757ADA0806BA 02:06:56.277|c__DisplayClass11_0|Debug > TCP Write:10us 13 AB00600AD89200757ADA08FDBA 02:06:56.298|c__DisplayClass11_0|Debug > TCP Write:20310us 13 AB0060E5259300757ADA08EEBA 02:06:56.298|c__DisplayClass11_0|Debug > TCP Write:12us 13 AB00603E799300757ADA0869BA 02:06:56.303|c__DisplayClass11_0|Debug > TCP Write:5518us 13 AB006099C69300757ADA0871BA 02:06:56.304|c__DisplayClass11_0|Debug > TCP Write:10us 13 AB0060FDE79400757ADA0833BA 02:06:56.323|c__DisplayClass11_0|Debug > TCP Write:19367us 13 AB00609D829600757ADA0834BA 02:06:56.324|c__DisplayClass11_0|Debug > TCP Write:13us 13 AB0060C3F99600757ADA0811BA 02:06:56.331|c__DisplayClass11_0|Debug > TCP Write:6900us 13 AB006063479700757ADA080EBA 02:06:56.331|c__DisplayClass11_0|Debug > TCP Write:10us 13 AB006033959700757ADA088CBA 02:06:56.351|c__DisplayClass11_0|Debug > TCP Write:19534us 13 AB00600BE49700757ADA08C5BA 02:06:56.351|c__DisplayClass11_0|Debug > TCP Write:11us 13 AB0060AE309800757ADA08BBBA 02:06:56.357|c__DisplayClass11_0|Debug > TCP Write:5604us 13 AB0060587D9800757ADA0800BA 02:06:56.357|c__DisplayClass11_0|Debug > TCP Write:12us 13 AB00601BCD9800757ADA08F3BA 02:06:56.376|c__DisplayClass11_0|Debug > TCP Write:19273us 13 AB0060A4199900757ADA0899BA 02:06:56.377|c__DisplayClass11_0|Debug > TCP Write:11us 13 AB0060D66A9900757ADA0898BA 02:06:56.382|c__DisplayClass11_0|Debug > TCP Write:3146us 14 AB00600155029900757ADA089FBA 02:06:56.383|c__DisplayClass11_0|Debug > TCP Write:12us 13 AB0060F9789A00757ADA08A6BA 02:06:56.402|c__DisplayClass11_0|Debug > TCP Write:19495us 13 AB006012C79A00757ADA08F2BA 02:06:56.402|c__DisplayClass11_0|Debug > TCP Write:11us 13 AB006042179B00757ADA0873BA 02:06:56.408|c__DisplayClass11_0|Debug > TCP Write:5492us 13 AB00605E639B00757ADA081BBA 02:06:56.408|c__DisplayClass11_0|Debug > TCP Write:10us 13 AB00605EB49B00757ADA08CCBA
and this is same code I run in windows and the logs I got:
02:08:20.043|c__DisplayClass11_0|Debug > TCP Write:27us 13 AB006054545332757ADA08DCBA 02:08:20.045|c__DisplayClass11_0|Debug > TCP Write:22us 13 AB0060F0A35332757ADA088FBA 02:08:20.047|c__DisplayClass11_0|Debug > TCP Write:22us 13 AB0060C1F15332757ADA08ECBA 02:08:20.049|c__DisplayClass11_0|Debug > TCP Write:23us 13 AB0060903F5432757ADA0874BA 02:08:20.051|c__DisplayClass11_0|Debug > TCP Write:24us 13 AB00607A8D5432757ADA082CBA 02:08:20.053|c__DisplayClass11_0|Debug > TCP Write:26us 13 AB006063DC5432757ADA0864BA 02:08:20.055|c__DisplayClass11_0|Debug > TCP Write:38us 14 AB0060F128550032757ADA0803BA 02:08:20.057|c__DisplayClass11_0|Debug > TCP Write:22us 14 AB00608678550032757ADA0824BA 02:08:20.059|c__DisplayClass11_0|Debug > TCP Write:22us 15 AB00605502C7550032757ADA08A7BA 02:08:20.061|c__DisplayClass11_0|Debug > TCP Write:23us 13 AB00608E135632757ADA0844BA 02:08:20.063|c__DisplayClass11_0|Debug > TCP Write:21us 13 AB00605F625632757ADA08E4BA 02:08:20.065|c__DisplayClass11_0|Debug > TCP Write:43us 13 AB0060F6AF5632757ADA0880BA 02:08:20.067|c__DisplayClass11_0|Debug > TCP Write:29us 13 AB006035FF5632757ADA0813BA 02:08:20.069|c__DisplayClass11_0|Debug > TCP Write:33us 13 AB006090515732757ADA0819BA 02:08:20.071|c__DisplayClass11_0|Debug > TCP Write:36us 13 AB0060DE995732757ADA089FBA 02:08:20.073|c__DisplayClass11_0|Debug > TCP Write:24us 13 AB00608BEA5732757ADA08B9BA 02:08:20.075|c__DisplayClass11_0|Debug > TCP Write:22us 13 AB0060B6385832757ADA0859BA 02:08:20.077|c__DisplayClass11_0|Debug > TCP Write:22us 13 AB006014865832757ADA0845BA 02:08:20.079|c__DisplayClass11_0|Debug > TCP Write:23us 13 AB006061D45832757ADA0862BA 02:08:20.082|c__DisplayClass11_0|Debug > TCP Write:39us 13 AB006031215932757ADA08C6BA 02:08:20.086|c__DisplayClass11_0|Debug > TCP Write:146us 13 AB0060DFBF5932757ADA08B6BA 02:08:20.090|c__DisplayClass11_0|Debug > TCP Write:29us 13 AB006089815A32757ADA08DDBA 02:08:20.092|c__DisplayClass11_0|Debug > TCP Write:26us 13 AB00606DCE5A32757ADA0876BA 02:08:20.094|c__DisplayClass11_0|Debug > TCP Write:23us 13 AB0060BF1D5B32757ADA0876BA 02:08:20.096|c__DisplayClass11_0|Debug > TCP Write:22us 13 AB0060626C5B32757ADA08DABA 02:08:20.099|c__DisplayClass11_0|Debug > TCP Write:341us 14 AB0060D555025B32757ADA08BBBA 02:08:20.104|c__DisplayClass11_0|Debug > TCP Write:42us 13 AB00603F7C5C32757ADA0890BA 02:08:20.107|c__DisplayClass11_0|Debug > TCP Write:50us 13 AB0060291A5D32757ADA08E1BA 02:08:20.111|c__DisplayClass11_0|Debug > TCP Write:32us 13 AB0060C9B45D32757ADA08AFBA