Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

Net Remoting and Performace

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
How to get a common name(CN) of SSL - 07 Jan 2008 11:35 GMT
Hello..
EveryOne..

i want to use the NET Remote between Server and Client.

But it was not good about the CPU Usage and sending time, whie i tested the
NET Remote.

so i write my code below..

[Server Side]

1. I made a Remote Server using TCPChannel.
           try
           {
               m_channel = new TcpChannel(nPortNumber);
               ChannelServices.RegisterChannel(m_channel, false);
               
RemotingConfiguration.RegisterWellKnownServiceType(typeof(CReceiverParameterFromThird), strCentralName,
                   WellKnownObjectMode.Singleton);
           }
           catch (Exception ex)
           {
               Console.WriteLine("CreateCentral :" + ex.Message);
               return false;
           }

2. And i made a some of funtions like below.
But All Of Functions are nothing to do, they just write some text through
Console.

   public class CReceiverParameterFromThird : MarshalByRefObject
   {

       public bool CreateParameter(string strId, string strName,     int
nLength)
       {
           Console.WriteLine("CreateParameter : {0}
{1}:{2}ms",nLength.ToString(), DateTime.Now, DateTime.Now.Millisecond);
           return true;
       }

[Client Side]

1.The Remote Object was created like below.
m_receiverParameter =
(CReceiverParameterFromThird)Activator.GetObject(typeof(CReceiverParameterFromThird), "tcp://" + strCentralIP +":" + strPortNumber + "/" + "Central");

2.The Client will call a Remote Functions.
m_receiverParameter.CreateParameter(strId, strName,  nLength);

[How to Test]

1.I called a Remote Functions like below.
       static void Main(string[] args)
       {
           CCentralClient CentralClient = new CCentralClient();

           CentralClient.CreateReceiver("10.1.2.220", "7000");

           for (int i = 0; i < 20000; i++)
           {
               CentralClient.CreateParameter("1", "PM",  i);
                      --- any of Remote Functions.----

               Thread.Sleep(TimeSpan.FromMilliseconds(100));
           }
       }
   }
After i call a Remote Function, The CPU Usage is increased both Server and
Client
about 2%~5%.

How can i solve this kind of problem, because i want to send a lot of data
and as soon as faster from Client To Server.

anyone help me how to solve this kind of problem.
Mr. Arnold - 07 Jan 2008 11:53 GMT
> How can i solve this kind of problem, because i want to send a lot of data
> and as soon as faster from Client To Server.
>
> anyone help me how to solve this kind of problem.

You use the Binary Formatters, serialize the data, and compress the data.
You deserialize and uncompress the data on the other side.
How to get a common name(CN) of SSL - 07 Jan 2008 13:04 GMT
> > How can i solve this kind of problem, because i want to send a lot of data
> > and as soon as faster from Client To Server.
[quoted text clipped - 3 lines]
> You use the Binary Formatters, serialize the data, and compress the data.
> You deserialize and uncompress the data on the other side.

Thank you for your reply,

Could you show me a sample program about binary formatter, Serialize and
Compress the data.

because i don't know how to do that very well.
Wolf Saenger - 07 Jan 2008 15:43 GMT
> Could you show me a sample program about binary formatter, Serialize
> and Compress the data.
>
> because i don't know how to do that very well.

www.micrsoft.com
www.gotdotnet.com
Mr. Arnold - 08 Jan 2008 00:44 GMT
>> > How can i solve this kind of problem, because i want to send a lot of
>> > data
[quoted text clipped - 11 lines]
>
> because i don't know how to do that very well.

There is a project for Contacts on how to use a Binary Formatter.

http://docs.msdnaa.net/ark_new3.0/cd3/content/Tech_Visual%20CSharp.htm

What you'll want to do is have a Class/object on the client side and server
the same object that represents the data. You're going to populate the
object with your data with object accessor properties that represent your
data int, string, double, etc. You'll use the [Serializable] attribute at
the top of the class. You'll serialize the object to XML using a Memory
Stream. You send the data to the server, and you'll deserialize it back into
the object. Again, the class must be on the client and server sides.

Here is some code for compressing data. You'll notice that it's doing it
with a Memory Stream, using sharpziplib.

http://www.google.com/search?hl=en&q=sharpziplib&btnG=Google+Search

As for the .Net Remoting and Binary Formatter on the TCP, you can use Google
and look it up.

HTH

public static string GetFileData( string filename, SAISDataFormat format )

{

//Make sure the file exists

if(!File.Exists(filename))

throw new Exception("FILE DOES NOT EXIST!");

//Get the file data

StreamReader reader = new StreamReader( filename );

string data = reader.ReadToEnd();

reader.Close();

//Check if we should compress the data

MemoryStream ms = null;

Stream output = null;

switch(format)

{

case SAISDataFormat.XML:

return data;

case SAISDataFormat.XML_BZ:

ms = new MemoryStream();

output = new BZip2OutputStream( ms );

break;

case SAISDataFormat.XML_GZ:

ms = new MemoryStream();

output = new GZipOutputStream( ms );

break;

}

//Compress the data by writing it to the output stream

byte[] buffer = System.Text.Encoding.Unicode.GetBytes ( data );

output.Write( buffer, 0, buffer.Length );

output.Close();

//Read out the compressed data and base64 encode it

buffer = ms.GetBuffer();

ms.Close();

string outputBase64 = Convert.ToBase64String( buffer );

//Return the Base64 encoding file data

return outputBase64;

}

/// <summary>
Willy Denoyette [MVP] - 07 Jan 2008 14:03 GMT
> Hello..
> EveryOne..
[quoted text clipped - 76 lines]
>
> anyone help me how to solve this kind of problem.

You don't actually describe a "problem", 2-5% CPU increase is not a problem.
You don't mention the measured transfer time, the expected response time and
how you measured, you also need to tell us in what context you have used
this test bed, are the clients running on the same box? If not what's the
distance between the two (LAN, WAN etc..).
And..... why do you sleep 100msec between calls?

Willy.
lightdoll - 07 Jan 2008 15:05 GMT
> > Hello..
> > EveryOne..
[quoted text clipped - 85 lines]
>
> Willy.

Thank you for your reply.

I have alredy mentioned something to send a lot of data to server from client.

I just send a little data for this test before making a program.

so The Cpu usage isn't good between server and client.

i want to solve this problem before making a program.

so if i call a function of Remote, then Both the Cpu Usage of Server and
Client are increased, so it isn't good for server and client,

i have tested this function in same pc or separated pc.

you can see there is a variable of i in for loop,

if The Client send a lot of data to server in same pc continually,

i found the time based of i's value from Server and Client,

Of course i also used LAN,

Actually, i want to use less than 100msec,
i think
it is difficult to control OS

Thank you...

do you have any idea to solve this problem.

if you need my code, i can give you my code..^^

bye
Willy Denoyette [MVP] - 07 Jan 2008 16:54 GMT
>> > Hello..
>> > EveryOne..
[quoted text clipped - 127 lines]
>
> bye

Hmmm... it looks like you want to call a remoted method 20000 times without
consuming CPU resources and it should not take longer than 100msec, please
correct me if I'm wrong. This is however not possible, calling methods
(whatever)  will always consume CPU cycles, what else did you expect?
To know exactly how long a single call takes, you can use the Stopwatch
class and measure how long it takes to execute, say 1000 calls.

Willy.
lightdoll - 08 Jan 2008 00:34 GMT
> >> > Hello..
> >> > EveryOne..
[quoted text clipped - 136 lines]
>
> Willy.

Thank you for your reply.

As soon as possible i want to call the faster remoted method , Not lose the
Cpu resource.

Can i...?ㅠㅠ
sloan - 07 Jan 2008 16:47 GMT
If you're just starting out, then you might want to go straight to WCF.

WCF is a 3.0 thing, but 3.0 is just an add on to 2.0.

See:
http://sholliday.spaces.live.com/blog/cns!A68482B9628A842A!158.entry

> Hello..
> EveryOne..
[quoted text clipped - 76 lines]
>
> anyone help me how to solve this kind of problem.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.