Discussion:
.NET Remoting long function stops responding
(too old to reply)
Oliver
2008-06-12 15:06:12 UTC
Permalink
I'm at an impasse with my remoting code, and I am hoping that someone could
help me. I have a class for determining disk space usage on a remote
server, and in order to determine the disk space usage of a particular
folder, it has to do a loop and get the file length of all files. In some
cases, there are more than 80,000 files in all subfolders, and the process
takes more than 5 minutes to calculate on the server. It seems that there
is a threshold for the length of time this calculation takes that at a
specific point, it will no longer return the value to the client. Here is
the code I am using on the server side:

Server Side:
Public Class DiskSpaceUsage
Inherits MarshalByRefObject
Public Function Size(ByVal di As System.IO.DirectoryInfo) As Long
Dim total As Long = 0
For Each file As System.IO.FileInfo In di.GetFiles()
total += file.Length
Next

For Each dir As System.IO.DirectoryInfo In di.GetDirectories()
total += Size(dir)
Next
Return total
End Function
End Class

Client Side:
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Lifetime
Module Module1
Private mTcp As Tcp.TcpChannel
Sub Main()
Try
mTcp = New Tcp.TcpChannel(9000)
ChannelServices.RegisterChannel(mTcp, False)
RemotingConfiguration.RegisterWellKnownServiceType(GetType(servertools.DiskSpaceUsage),
"DiskSpaceUsage", WellKnownObjectMode.SingleCall)
...
...
...
Dim FolderSize As DiskSpaceUsage =
CType(Activator.GetObject(GetType(DiskSpaceUsage), url & "DiskSpaceUsage"),
DiskSpaceUsage)
dim lFoldersize as long = foldersize.size(diFolder)
Catch ex as exception
End Try
End Sub
End Module


I've tried setting the GetLifetimeService and iLease to 30 minutes, and a
few other variables on the lifetimeservices, but nothing seems to work. I
set the server function to write to the console when it's complete, so I
know that the function completes successfully, but it does not return the
value. I'm not sure if the client has closed the connection at this point,
but it just hangs at the remote function call, and it does not let me
continue code execution, or error out, so there is no way for me to run a
client-side test on the connection.

Any help is appreciated, as I have looked everywhere to describe this
problem without success.
Oliver
2008-06-12 17:36:13 UTC
Permalink
Just to add a little extra, I managed to create some test code in order to
determine the exact amount of time the remote procedure will run before it
no longer returns a value to the client, and it turns out to be 2 minutes.
I check the lease time on the lifetimeservices, and it's actually 17 seconds
by default, but it does not affect anything if I manually set it to 5
minutes. The object still exists remotely, so I don't think it's a garbage
collection issue remotely, but I think that there is something going on with
the client-side connection.

Oliver
Post by Oliver
I'm at an impasse with my remoting code, and I am hoping that someone
could help me. I have a class for determining disk space usage on a
remote server, and in order to determine the disk space usage of a
particular folder, it has to do a loop and get the file length of all
files. In some cases, there are more than 80,000 files in all subfolders,
and the process takes more than 5 minutes to calculate on the server. It
seems that there is a threshold for the length of time this calculation
takes that at a specific point, it will no longer return the value to the
Public Class DiskSpaceUsage
Inherits MarshalByRefObject
Public Function Size(ByVal di As System.IO.DirectoryInfo) As Long
Dim total As Long = 0
For Each file As System.IO.FileInfo In di.GetFiles()
total += file.Length
Next
For Each dir As System.IO.DirectoryInfo In di.GetDirectories()
total += Size(dir)
Next
Return total
End Function
End Class
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Lifetime
Module Module1
Private mTcp As Tcp.TcpChannel
Sub Main()
Try
mTcp = New Tcp.TcpChannel(9000)
ChannelServices.RegisterChannel(mTcp, False)
RemotingConfiguration.RegisterWellKnownServiceType(GetType(servertools.DiskSpaceUsage),
"DiskSpaceUsage", WellKnownObjectMode.SingleCall)
...
...
...
Dim FolderSize As DiskSpaceUsage =
CType(Activator.GetObject(GetType(DiskSpaceUsage), url &
"DiskSpaceUsage"), DiskSpaceUsage)
dim lFoldersize as long = foldersize.size(diFolder)
Catch ex as exception
End Try
End Sub
End Module
I've tried setting the GetLifetimeService and iLease to 30 minutes, and a
few other variables on the lifetimeservices, but nothing seems to work. I
set the server function to write to the console when it's complete, so I
know that the function completes successfully, but it does not return the
value. I'm not sure if the client has closed the connection at this
point, but it just hangs at the remote function call, and it does not let
me continue code execution, or error out, so there is no way for me to run
a client-side test on the connection.
Any help is appreciated, as I have looked everywhere to describe this
problem without success.
Oliver
2008-06-12 19:21:51 UTC
Permalink
So I hope this information will prove useful for anyone else that may be
having the same problem with remoting. I have found what looks like to be
the problem, but as of yet, I don't have a solution, just a workaround.
I tested out my code on the remote server and if I ran the client on the
same machine as the server app, the process completes. I then tried it on
another server on the same local network, and it worked. Both these servers
are located behind an external firewall, but no individual firewall exists
between their internal network. My only suspicion is that there is some
kind of process that is either closing the network connection between my
computer and the server, or it is related to how remoting works across
public networks. I know I've had issues with WMI across public networks.
Perhaps someone else has some insight on this problem.
Post by Oliver
I'm at an impasse with my remoting code, and I am hoping that someone
could help me. I have a class for determining disk space usage on a
remote server, and in order to determine the disk space usage of a
particular folder, it has to do a loop and get the file length of all
files. In some cases, there are more than 80,000 files in all subfolders,
and the process takes more than 5 minutes to calculate on the server. It
seems that there is a threshold for the length of time this calculation
takes that at a specific point, it will no longer return the value to the
Public Class DiskSpaceUsage
Inherits MarshalByRefObject
Public Function Size(ByVal di As System.IO.DirectoryInfo) As Long
Dim total As Long = 0
For Each file As System.IO.FileInfo In di.GetFiles()
total += file.Length
Next
For Each dir As System.IO.DirectoryInfo In di.GetDirectories()
total += Size(dir)
Next
Return total
End Function
End Class
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Lifetime
Module Module1
Private mTcp As Tcp.TcpChannel
Sub Main()
Try
mTcp = New Tcp.TcpChannel(9000)
ChannelServices.RegisterChannel(mTcp, False)
RemotingConfiguration.RegisterWellKnownServiceType(GetType(servertools.DiskSpaceUsage),
"DiskSpaceUsage", WellKnownObjectMode.SingleCall)
...
...
...
Dim FolderSize As DiskSpaceUsage =
CType(Activator.GetObject(GetType(DiskSpaceUsage), url &
"DiskSpaceUsage"), DiskSpaceUsage)
dim lFoldersize as long = foldersize.size(diFolder)
Catch ex as exception
End Try
End Sub
End Module
I've tried setting the GetLifetimeService and iLease to 30 minutes, and a
few other variables on the lifetimeservices, but nothing seems to work. I
set the server function to write to the console when it's complete, so I
know that the function completes successfully, but it does not return the
value. I'm not sure if the client has closed the connection at this
point, but it just hangs at the remote function call, and it does not let
me continue code execution, or error out, so there is no way for me to run
a client-side test on the connection.
Any help is appreciated, as I have looked everywhere to describe this
problem without success.
Adam
2008-07-22 20:07:15 UTC
Permalink
Hi,

The default lease time on a SingleCall server activated object (SAO) is 300
seconds. SingleCall activated object leases are not configurable. You also
cannot control server leasing from the client side as it is a SAO (if this
is what you are trying to do, I'm not sure by your example).

Try making it a Singleton object (Singleton instead of SingleCall) and call
the method asynchronously (if it takes so long, don't wait for it - register
a callback). Singleton also allows you to specify lease times as they
participate in the leasing system - its also a gotcha because sometimes
clients will get different singletons if the gap between client calls is
long enough for the lease to expire - so state is lost.

Override "InitializeLifetimeService" of your remote class and return "null"
to specify no lease expiry (object will live forever until the remote class
server resets).

To give the client lease control, make it a Client Activated Object (CAO) -
this allows you to register a sponsor for the object to increase the
remaining lease time on the server.

Hope this is helpful, though it is a month late.

Cheers,

Adam
Post by Oliver
I'm at an impasse with my remoting code, and I am hoping that someone
could help me. I have a class for determining disk space usage on a
remote server, and in order to determine the disk space usage of a
particular folder, it has to do a loop and get the file length of all
files. In some cases, there are more than 80,000 files in all subfolders,
and the process takes more than 5 minutes to calculate on the server. It
seems that there is a threshold for the length of time this calculation
takes that at a specific point, it will no longer return the value to the
Public Class DiskSpaceUsage
Inherits MarshalByRefObject
Public Function Size(ByVal di As System.IO.DirectoryInfo) As Long
Dim total As Long = 0
For Each file As System.IO.FileInfo In di.GetFiles()
total += file.Length
Next
For Each dir As System.IO.DirectoryInfo In di.GetDirectories()
total += Size(dir)
Next
Return total
End Function
End Class
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Lifetime
Module Module1
Private mTcp As Tcp.TcpChannel
Sub Main()
Try
mTcp = New Tcp.TcpChannel(9000)
ChannelServices.RegisterChannel(mTcp, False)
RemotingConfiguration.RegisterWellKnownServiceType(GetType(servertools.DiskSpaceUsage),
"DiskSpaceUsage", WellKnownObjectMode.SingleCall)
...
...
...
Dim FolderSize As DiskSpaceUsage =
CType(Activator.GetObject(GetType(DiskSpaceUsage), url &
"DiskSpaceUsage"), DiskSpaceUsage)
dim lFoldersize as long = foldersize.size(diFolder)
Catch ex as exception
End Try
End Sub
End Module
I've tried setting the GetLifetimeService and iLease to 30 minutes, and a
few other variables on the lifetimeservices, but nothing seems to work. I
set the server function to write to the console when it's complete, so I
know that the function completes successfully, but it does not return the
value. I'm not sure if the client has closed the connection at this
point, but it just hangs at the remote function call, and it does not let
me continue code execution, or error out, so there is no way for me to run
a client-side test on the connection.
Any help is appreciated, as I have looked everywhere to describe this
problem without success.
Loading...