M
Martin Bischoff
In the MSDN article "Microsoft .NET Remoting: A Technical Overview" I
found the following statement (in the paragraph "Proxy Objects") about
method calls on remote objects:
"...the [method] call is examined to determine if it is a valid method
of the remote object and if an instance of the remote object resides in
the same application domain as the proxy. If this is true, a simple
method call is routed to the actual object."
I have created a simple remoting application which is server and client
at the same time (see below). In the sample, I instantiate the remote
object and then want to check whether it resides in the same AppDomain
as the client code.
To do so I call RemotingServices.IsObjectOutOfAppDomain(obj). I would
have expected this method to return false because client and "remote"
object are in the same AppDomain, but it returns true.
Another thing i found out is the following:
After running some rudimentary performance comparisions (using a
somewhat more complex sample), it seems to me that calling the remote
object's method takes roughly the same time no matter whether the remote
object exists in the same AppDomain or when it really is instantiated in
a different AppDomain/process (on the same machine). E.g.:
calling the remote object's method 20000 times takes:
- not measurable when called on a local instance
- 13 seconds when used as shown in the sample below
- 15 seconds when the object really is remote (different AppDomain, same
machine though)
So here are my questions:
1/ Is there a bug in RemotingServices.IsObjectOutOfAppDomain(obj)?
Shouldn't this method return false, when the "remote" object resides in
the same AppDomain as the client (as described above)?
2/ When the remote object resides in the same AppDomain as the client,
is there any optimization done by the framework (e.g. bypassing the
network stack)? My rudimentary tests made me think that there's no such
optimization, even though something like this is mentioned in the MSDN
articled cited above (at least that's how I understood the statement)
Thanks for any information.
Martin Bischoff
here's the example (example.cs):
----------------------------------
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace RemotingSamples
{
public class HelloServer : MarshalByRefObject
{
public HelloServer()
{
Console.WriteLine("HelloServer activated");
}
public String HelloMethod(String name)
{
return "Hi there " + name;
}
}
public class Server
{
public static int Main(string [] args)
{
// server code
ChannelServices.RegisterChannel(new TcpChannel(8085));
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(HelloServer), "SayHelloSingleton",
WellKnownObjectMode.Singleton);
// client code
HelloServer obj = HelloServer)Activator.GetObject(
typeof(HelloServer), "tcp://localhost:8085/SayHelloSingleton");
System.Console.WriteLine(
"IsTransparentProxy={0}, IsOutOfAppDomain={1}",
RemotingServices.IsTransparentProxy(obj),
RemotingServices.IsObjectOutOfAppDomain(obj));
Console.WriteLine(obj.HelloMethod("server"));
return 0;
}
}
}
----------------------------------
found the following statement (in the paragraph "Proxy Objects") about
method calls on remote objects:
"...the [method] call is examined to determine if it is a valid method
of the remote object and if an instance of the remote object resides in
the same application domain as the proxy. If this is true, a simple
method call is routed to the actual object."
I have created a simple remoting application which is server and client
at the same time (see below). In the sample, I instantiate the remote
object and then want to check whether it resides in the same AppDomain
as the client code.
To do so I call RemotingServices.IsObjectOutOfAppDomain(obj). I would
have expected this method to return false because client and "remote"
object are in the same AppDomain, but it returns true.
Another thing i found out is the following:
After running some rudimentary performance comparisions (using a
somewhat more complex sample), it seems to me that calling the remote
object's method takes roughly the same time no matter whether the remote
object exists in the same AppDomain or when it really is instantiated in
a different AppDomain/process (on the same machine). E.g.:
calling the remote object's method 20000 times takes:
- not measurable when called on a local instance
- 13 seconds when used as shown in the sample below
- 15 seconds when the object really is remote (different AppDomain, same
machine though)
So here are my questions:
1/ Is there a bug in RemotingServices.IsObjectOutOfAppDomain(obj)?
Shouldn't this method return false, when the "remote" object resides in
the same AppDomain as the client (as described above)?
2/ When the remote object resides in the same AppDomain as the client,
is there any optimization done by the framework (e.g. bypassing the
network stack)? My rudimentary tests made me think that there's no such
optimization, even though something like this is mentioned in the MSDN
articled cited above (at least that's how I understood the statement)
Thanks for any information.
Martin Bischoff
here's the example (example.cs):
----------------------------------
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace RemotingSamples
{
public class HelloServer : MarshalByRefObject
{
public HelloServer()
{
Console.WriteLine("HelloServer activated");
}
public String HelloMethod(String name)
{
return "Hi there " + name;
}
}
public class Server
{
public static int Main(string [] args)
{
// server code
ChannelServices.RegisterChannel(new TcpChannel(8085));
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(HelloServer), "SayHelloSingleton",
WellKnownObjectMode.Singleton);
// client code
HelloServer obj = HelloServer)Activator.GetObject(
typeof(HelloServer), "tcp://localhost:8085/SayHelloSingleton");
System.Console.WriteLine(
"IsTransparentProxy={0}, IsOutOfAppDomain={1}",
RemotingServices.IsTransparentProxy(obj),
RemotingServices.IsObjectOutOfAppDomain(obj));
Console.WriteLine(obj.HelloMethod("server"));
return 0;
}
}
}
----------------------------------