[Mono-list] Why is MONO network streaming much slower than .NET?
Hi, is MONO network streaming slow? First I built a very simple client/server program to get a data stream over network. In both programs I used a TcpClient, a NetworkStream and a byte array (8kB chunks) to stream 20 MB of data. Then I tested the transfer rate of the client/server program between different Linux/MONO (1.2.3.1) and different Windows/.NET (2.0) hosts in a 100 Mbit/s ethernet. The strange result: If MONO was involved the speed was dramatically reduced. Only a .NET/.NET transfer showed a realistic rate. .NET --> MONO : 31...42 Mbit/s LOW MONO --> MONO : 43...45 Mbit/s LOW MONO --> .NET : 51...76 Mbit/s LOW .NET --> .NET : 94 Mbit/sO.K. What's wrong here? Any suggestions or hints? Thanks in advance. Cheers Andreas === Sourcecodes: // ** // Client // ** using System; using System.IO; using System.Net.Sockets; namespace SimpleStreamClient { class SimpleStreamClient { public static void Main(string[] args) { TcpClient client; NetworkStream netStream; byte[] buf = new byte[8192]; int bytesToReceive = buf.Length; int receivedBytes = 0; int bytesReceived = 0; for(int index = 0; index < 10; index++) { client = new TcpClient(args[0], 14866); netStream = client.GetStream(); DateTime startTime = DateTime.Now; bytesReceived = 0; while(true) { bytesToReceive = buf.Length; while(bytesToReceive > 0) { receivedBytes = netStream.Read(buf, 0, bytesToReceive); if(receivedBytes == 0) { break; } bytesReceived += receivedBytes; bytesToReceive -= receivedBytes; } if(receivedBytes == 0) { break; } } double rate = bytesReceived / (((TimeSpan)(DateTime.Now - startTime)).TotalMilliseconds * 1000) * 8; Console.WriteLine(bytesReceived + " Bytes received (" + rate + "MBit/s)."); } Console.ReadKey(); } } } // ** // Server // ** using System; using System.IO; using System.Net; using System.Net.Sockets; namespace SimpleStreamServer { class SimpleStreamServer { public static void Main(string[] args) { TcpClient client; NetworkStream netStream; byte[] bigBuf = new byte[2000]; MemoryStream ms = new MemoryStream(bigBuf); byte[] buf = new byte[8192]; string host = Dns.GetHostEntry(args[0]).AddressList[0].ToString(); IPAddress ipAddr = IPAddress.Parse(host); TcpListener listener = new TcpListener(ipAddr, 14866); listener.Start(); while(true) { Console.WriteLine("Waiting for client ..."); client = listener.AcceptTcpClient(); Console.WriteLine("New client!"); netStream = client.GetStream(); ms.Seek(0, SeekOrigin.Begin); int readBytes = 0; while((readBytes = ms.Read(buf, 0, buf.Length)) != 0) { netStream.Write(buf, 0, readBytes); } netStream.Flush(); client.Close(); } } } } ___ Mono-list maillist - Mono-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-list
Re: [Mono-list] Why is MONO network streaming much slower than .NET?
Hi, I've ran your tests on my linux box... Between Gentoo Linux on a 3Ghz PIV and Gentoo Linux on a 3Ghz Xeon in a 100Mbit/s ethernet (with a router in the middle) Mono 1.2.4 -> Mono 1.2.4. : 2000 Bytes received (82,9530454655273MBit/s). 2000 Bytes received (84,3471687291307MBit/s). 2000 Bytes received (83,6054866100588MBit/s). 2000 Bytes received (85,4498641614191MBit/s). 2000 Bytes received (84,066551285325MBit/s). 2000 Bytes received (83,0987524799784MBit/s). 2000 Bytes received (82,9746839053487MBit/s). 2000 Bytes received (75,9913065945256MBit/s). 2000 Bytes received (84,3420555318636MBit/s). 2000 Bytes received (84,7406908378895MBit/s). ~83Mbit/s Thats acceptable no? Le lundi 18 juin 2007 à 09:38 +0200, Hund a écrit : > Hi, > is MONO network streaming slow? > > First I built a very simple client/server program > to get a data stream over network. > In both programs I used a TcpClient, > a NetworkStream and a byte array (8kB chunks) > to stream 20 MB of data. > > Then I tested the transfer rate of the client/server > program between different Linux/MONO (1.2.3.1) > and different Windows/.NET (2.0) hosts > in a 100 Mbit/s ethernet. > > The strange result: If MONO was involved > the speed was dramatically reduced. > Only a .NET/.NET transfer showed a realistic > rate. > > .NET --> MONO : 31...42 Mbit/s LOW > MONO --> MONO : 43...45 Mbit/s LOW > MONO --> .NET : 51...76 Mbit/s LOW > .NET --> .NET : 94 Mbit/sO.K. > > What's wrong here? > Any suggestions or hints? > Thanks in advance. > > Cheers > Andreas > > === > > > Sourcecodes: > > // ** > // Client > // ** > > using System; > using System.IO; > using System.Net.Sockets; > > namespace SimpleStreamClient > { > class SimpleStreamClient > { > public static void Main(string[] args) { > TcpClient client; > NetworkStream netStream; > byte[] buf = new byte[8192]; > int bytesToReceive = buf.Length; > int receivedBytes = 0; > int bytesReceived = 0; > > for(int index = 0; index < 10; index++) { > client = new TcpClient(args[0], 14866); > netStream = client.GetStream(); > DateTime startTime = DateTime.Now; > bytesReceived = 0; > > while(true) { > bytesToReceive = buf.Length; > > while(bytesToReceive > 0) { > receivedBytes = netStream.Read(buf, 0, bytesToReceive); > if(receivedBytes == 0) { > break; > } > bytesReceived += receivedBytes; > bytesToReceive -= receivedBytes; > } > if(receivedBytes == 0) { > break; > } > } > double rate = bytesReceived / (((TimeSpan)(DateTime.Now - > startTime)).TotalMilliseconds * 1000) * 8; > Console.WriteLine(bytesReceived + " Bytes received (" + rate + > "MBit/s)."); > } > Console.ReadKey(); > } > } > } > > > // ** > // Server > // ** > > using System; > using System.IO; > using System.Net; > using System.Net.Sockets; > > namespace SimpleStreamServer > { > class SimpleStreamServer > { > public static void Main(string[] args) { > TcpClient client; > NetworkStream netStream; > byte[] bigBuf = new byte[2000]; > MemoryStream ms = new MemoryStream(bigBuf); > byte[] buf = new byte[8192]; > string host = > Dns.GetHostEntry(args[0]).AddressList[0].ToString(); > IPAddress ipAddr = IPAddress.Parse(host); > TcpListener listener = new TcpListener(ipAddr, 14866); > listener.Start(); > > while(true) { > Console.WriteLine("Waiting for client ..."); > client = listener.AcceptTcpClient(); > Console.WriteLine("New client!"); > netStream = client.GetStream(); > ms.Seek(0, SeekOrigin.Begin); > int readBytes = 0; > while((readBytes = ms.Read(buf, 0, buf.Length)) != 0) { > netStream.Write(buf, 0, readBytes); > } > netStream.Flush(); > client.Close(); > } > } > } > } > > > ___ > Mono-list maillist - Mono-list@lists.ximian.com > http://lists.ximian.com/mailman/listinfo/mono-list ___ Ce message et les �ventuels documents joints peuvent contenir des informations confidentielles. Au cas o� il ne vous serait pas destin�, nous vous remercions de bien vouloir le supprimer et en aviser imm�diatement l'exp�diteur. Toute utilisation de ce message non conforme � sa destination, toute diffusion ou publication, totale ou partielle et quel qu'en soit le moyen est formellement interdite. Les communications sur internet n'�tant pas s�curis�es, l'int�grit� de ce message n'est pas assur�e et la soci�t� �mettrice ne peut �tre tenue pour re
Re: [Mono-list] Why is MONO network streaming much slower than .NET?
Hello, Do not allocate an array of 20 megabytes, it will slow down your performance as the GC does not cope well with it. > Hi, > is MONO network streaming slow? > > First I built a very simple client/server program > to get a data stream over network. > In both programs I used a TcpClient, > a NetworkStream and a byte array (8kB chunks) > to stream 20 MB of data. > > Then I tested the transfer rate of the client/server > program between different Linux/MONO (1.2.3.1) > and different Windows/.NET (2.0) hosts > in a 100 Mbit/s ethernet. > > The strange result: If MONO was involved > the speed was dramatically reduced. > Only a .NET/.NET transfer showed a realistic > rate. > > .NET --> MONO : 31...42 Mbit/s LOW > MONO --> MONO : 43...45 Mbit/s LOW > MONO --> .NET : 51...76 Mbit/s LOW > .NET --> .NET : 94 Mbit/sO.K. > > What's wrong here? > Any suggestions or hints? > Thanks in advance. > > Cheers > Andreas > > === > > > Sourcecodes: > > // ** > // Client > // ** > > using System; > using System.IO; > using System.Net.Sockets; > > namespace SimpleStreamClient > { > class SimpleStreamClient > { > public static void Main(string[] args) { > TcpClient client; > NetworkStream netStream; > byte[] buf = new byte[8192]; > int bytesToReceive = buf.Length; > int receivedBytes = 0; > int bytesReceived = 0; > > for(int index = 0; index < 10; index++) { > client = new TcpClient(args[0], 14866); > netStream = client.GetStream(); > DateTime startTime = DateTime.Now; > bytesReceived = 0; > > while(true) { > bytesToReceive = buf.Length; > > while(bytesToReceive > 0) { > receivedBytes = netStream.Read(buf, 0, bytesToReceive); > if(receivedBytes == 0) { > break; > } > bytesReceived += receivedBytes; > bytesToReceive -= receivedBytes; > } > if(receivedBytes == 0) { > break; > } > } > double rate = bytesReceived / (((TimeSpan)(DateTime.Now - > startTime)).TotalMilliseconds * 1000) * 8; > Console.WriteLine(bytesReceived + " Bytes received (" + rate + > "MBit/s)."); > } > Console.ReadKey(); > } > } > } > > > // ** > // Server > // ** > > using System; > using System.IO; > using System.Net; > using System.Net.Sockets; > > namespace SimpleStreamServer > { > class SimpleStreamServer > { > public static void Main(string[] args) { > TcpClient client; > NetworkStream netStream; > byte[] bigBuf = new byte[2000]; > MemoryStream ms = new MemoryStream(bigBuf); > byte[] buf = new byte[8192]; > string host = > Dns.GetHostEntry(args[0]).AddressList[0].ToString(); > IPAddress ipAddr = IPAddress.Parse(host); > TcpListener listener = new TcpListener(ipAddr, 14866); > listener.Start(); > > while(true) { > Console.WriteLine("Waiting for client ..."); > client = listener.AcceptTcpClient(); > Console.WriteLine("New client!"); > netStream = client.GetStream(); > ms.Seek(0, SeekOrigin.Begin); > int readBytes = 0; > while((readBytes = ms.Read(buf, 0, buf.Length)) != 0) { > netStream.Write(buf, 0, readBytes); > } > netStream.Flush(); > client.Close(); > } > } > } > } > > ___ > Mono-list maillist - Mono-list@lists.ximian.com > http://lists.ximian.com/mailman/listinfo/mono-list ___ Mono-list maillist - Mono-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-list