tags:

views:

29

answers:

1

When I execute the following code to delete and move a file my worker process hangs:

File.Delete(FullSourceFilePath);
File.Move(FullTempFilePath, FullSourceFilePath);
// update db
Data.AdminUpdateFileSizeandBitrate(FileId, SizeInbytes, Bitrate);
Response.Redirect("?m=File replaced!");

The folder FullSourceFilePath has more than 15000 files in it.

Above code causes site to hang (only this site) if the file that needs to be moved is larger than around 5 MB. When this problem arises my worker process starts consuming memory and gradually my server is brought to its knees.

The only recovery solution is then to issue the IISRESET /RESTART command.

My environment is:

IIS6 running on Windows 2003 x86 SP2
Web site written using ASP.NET 4.0 and C#

A: 

At a guess, the problem here is probably the large number of files in the folder you're moving the file to.

Does the worker process hang just on the File.Move()?

Try doing:

File.Delete(FullSourceFilePath);
File.Copy(FullTempFilePath, FullSourceFilePath);

Other things to try are performing the same actions from the command line and see if that causes the same problem to arise.

If it does then you're filesystem may be heavily fragmented and the disk is thrashing.

Windows also doesn't handle large numbers of files very well, if the files can be categorised in any way (for example by ID range or date range) then break this down into subfolders.

You could also run DebugDiag and capture a minidump to see where the bottleneck is happening.

Tess Ferrandez' blog has some great articles on how to use this tool to determine causes of worker process high memory use, crashes and hangs.

.NET Debugging Demos - Information and setup instructions

Kev
thanks, just add some more info. same operation works just fine with classic asp
nLL
@nLL - probably time to dig out the debugging tools to find out what's going on.
Kev