Remoting is different from just shooting the contents of a class over
the wire. With remoting, you have method calls that are taking place, sinks
that are manipulating the call before it gets to the call site (on both
ends, etc, etc). This definitely contributes to the overall time it takes
to make a call over remoting.
Also, with serialization, you get that out of the box, with little or no
modification to your class (with the exception of the Serializable
attribute). In C++, I've seen some pretty contrived ways of serializing
information to send over the wire. Serialization really shines in .NET when
you have large object graphs that need to be serialized.
Your example class is somewhat simplistic. Granted, it could be all you
ever send, but in more complex situations, I think that the C++ solution
will become difficult to implement (I could be very wrong here, granted).
In the end though, you have to measure what your needs are. If
processing 500K methods in 1459 seconds (an average of 342 calls a second)
is not sufficient, then don't use it. However, if you only need to process
say, 40 operations a second, then this would be more than sufficient, and I
would take the .NET solution because it would be much easier to implement.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mvp@spam.guard.caspershouse.com
<ajou_king@yahoo.com> wrote in message
news:1110898272.233605.189020@o13g2000cwo.googlegr oups.com...[color=blue]
>I was running some tests on my Win32 1GHZ processor to see how long it
> would take to transmit objects numerous times via TCP/IP using C#
> .NET Remoting vs the C++ trustworthy method of binary streams. I ran
> the test for 50K, 100K, 500K iterations, where each iteration consists
> of sending an object from a client process to a server process, and the
> server process sends back an ack.
> Here are the results:
>
> .NET Remoting C++ Binary TCP/IP
> -------------- ------------------
> 50,000 Iterations: 128 seconds 3 seconds
> 100,000 Iterations: 300 seconds 8 seconds
> 500,000 Iterations: 1459 seconds 43 seconds
>
> In the above tests the .NET remoting overhead was 42.6x, 37.5x, and
> 33.9x slower than the c++ version.
>
> Here is the object that was used:
> ---------------------------------------------------------------
> [Serializable]
> public class Msg
> {
> public int msgType_;
> public int seqNum_;
> public String symbol_;
> public int quoteId_;
> public int responseLevel_;
> public int eqiRole_;
> public float bidPrice_;
> public float offerPrice_;
> public int bidSize_;
> public int offerSize_;
> public float liquidityBidPrice_;
> public float liquidityOfferPrice_;
> public int liquidityBidSize_;
> public int liquidityOfferSize_;
> public int checkSum_;
> }
>
> The Server Process:
> ------------------------------------------------------
> using System;
> using Messages;
>
>
> namespace tcpServer
> {
>
> using System;
> using System.Net;
> using System.Net.Sockets;
> using System.Runtime.Serialization.Formatters.Binary;
> using System.IO;
>
>
> /// <summary>
> /// Summary description for Class1.
> /// </summary>
> class Class1
> {
> /// <summary>
> /// The main entry point for the application.
> /// </summary>
> [STAThread]
> static void Main(string[] args)
> {
> int port = 7627;
> int N = 50000;
> int i = 0;
>
> BinaryFormatter bF = new BinaryFormatter();
>
> TcpListener tcpListener = new TcpListener(port);
> tcpListener.Start();
> Socket soTcp = tcpListener.AcceptSocket();
> Console.WriteLine("SampleClient is connected through TCP.");
> NetworkStream stream = new NetworkStream(soTcp,
> FileAccess.ReadWrite, true);
> BinaryReader bReader = new BinaryReader(stream);
>
> DateTime beginTime = new DateTime();
>
> while (i < N)
> {
> if (i == 0)
> {
> beginTime = System.DateTime.Now;
> }
>
> ++i;
> Byte[] received = new Byte[1024];
> Messages.Msg msg = new Messages.Msg();
> msg = (Messages.Msg)bF.Deserialize(stream);
> String returningString = Convert.ToString(99);
> Byte[] returningByte =
> System.Text.Encoding.ASCII.GetBytes(returningStrin g.ToCharArray());
>
> //Returning a confirmation back to the client.
> soTcp.Send(returningByte, returningByte.Length, 0);
> }
> DateTime endTime = System.DateTime.Now;
> Console.WriteLine(endTime - beginTime);
> }
> }
> }
>
> The Client Process
> ---------------------------------------------------------------------
> using System;
> using System.Net;
> using System.Net.Sockets;
> using System.IO;
> using System.Runtime.Serialization.Formatters.Binary;
> using Messages;
>
> namespace tcpClient
> {
> /// <summary>
> /// Summary description for Class1.
> /// </summary>
> ///
>
>
>
> class Class1
> {
> /// <summary>
> /// The main entry point for the application.
> /// </summary>
> [STAThread]
> static void Main(string[] args)
> {
> int port = 7627;
> int N = 100000;
> int i = 0;
>
> TcpClient tcpClient = new TcpClient("machine1", port);
> NetworkStream tcpStream = tcpClient.GetStream();
> BinaryWriter bWriter = new BinaryWriter(tcpStream);
> BinaryFormatter bF = new BinaryFormatter();
>
> while (i < N)
> {
> ++i;
>
> Messages.Msg m = new Messages.Msg();
> m.msgType_ = 101;
> m.bidPrice_ = 123.32f;
> m.bidSize_ = 100;
> m.eqiRole_ = 1;
> m.liquidityBidPrice_ = 122.12f;
> m.liquidityOfferPrice_ = 192.32f;
> m.offerPrice_ = 154.25f;
> m.quoteId_ = i;
> m.responseLevel_ = 10;
> m.symbol_ = "IBM";
> bF.Serialize(tcpStream, m);
>
> // Read back the Ack
> Byte[] received = new Byte[1024];
> tcpStream.Read(received, 0, received.Length);
>
> }
> }
> }
> }
>
>
>
>
> The C++ binary streams method was to simply simulate the above but no
> serialization involved - just send the byte stream of the class via
> TCP/IP sockets.
>
> If .NET Remoting / Serialization is so slow, why would anyone ever use
> it over C++ for performance critical applications that transmit
> hundreds of thousands of messages per day ? Is the tradeoff really
> worth it ? What are people's thoughts ?
>[/color]